Description
Go's debug information for optimized binaries needs a lot of improvement (we're working on it). In the mean time, it would be valuable for debuggers to know whether a binary optimized or unoptimized. For example, this could be used (in combination with the toolchain version already recorded in the binary) to warn users that local variable information may be incorrect and that they should consider recompiling with optimizations disabled.
One complication is that it's currently possible (and fairly common) to compile different packages with different optimization levels. If the cmd/go
changes go as planned, this will no longer be possible in 1.10, but may again become possible in the future.
Some reasonable ways to record this information are:
-
Create a per-package symbol to indicate the optimization level. We could create this symbol only if the package is unoptimized, so we don't bloat optimized binaries with lots of extra symbols. This would be easy to get at from any symbolic debugger.
-
Record this as a custom attribute in each DWARF function (there is no DIE corresponding to a package). This is arguably the "right" place to record this, but it requires help from the debugger's DWARF decoder to access.
I think both are pretty easy to implement. I would lean toward solution 1.
/cc @rsc @dr2chase @zombiezen