Bug #6348
opensource-level debugging not quite working
0%
Description
The fixes for #3844 made it easier to build with -g but source-level debugging is still not quite working correctly. The reason is that #3844 added -g without removing optimization options.
With most tool chains, if you turn on both debug support and optimization, examination of local variables etc. usually doesn't work.
The most common approach for adjusting a Makefile to build for debugging is to modify whatever make variable holds the "optimization" options (i.e. typically "-O" or similar), so that when building for debug the optimization flags are replaced with a "-g" flag. That both turns on full source-level debugging support, and turns off optimization. That's what we should be doing as well.
In most ilumos makefiles, the variable we're interested in for this is COPTFLAG, but sometimes COPTFLAG64, CCOPTFLAG, CCOPTFLAG64
Files
Updated by Gordon Ross about 1 year ago
- File 0001-6348-source-level-debugging-not-quite-working.patch 0001-6348-source-level-debugging-not-quite-working.patch added
Just setting COPTFLAG (and related) empty lets debugging work OK.
According to the gcc documentation, -O0 (Oh zero) is better,
and -Og better still, though cw didn't like that last.
I've attached the change I normally apply when I need to use gdb.
Updated by Gordon Ross about 1 year ago
Unfortunately, if you use this and set SOURCEDEBUG during a full build,
the build fails in usr/src/lib/libc with unresolved symbols:
_curthread, __curthread, stkptr, set_lock_byte
apparently because of how the inline functions are defined.
There's no regular (not-inline) instantiation of those.
I normally use this with one of the "quick build" scripts in
usr/src/tools/quick and unset SOURCEDEBUG for libc.