-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
on osx, dsymutil needs to be called on the resulting executable when user requests debug builds (eg -g or --debugger:native) otherwise DWARF debug info is gone; see rationale here [1]
Note that the DWARF debug info is needed for:
- improved debugging experience (symbolication) under a debugger
- stacktrace without
--stackTraceruntime overhead #12702 (stacktraces without runtime overhead) - symbolication of stacktraces pointing to c++ code (which could be emitted, from a loaded library etc)
tools like llvm-symbolizer -obj=/pathto/prog can do proper symbolication (address => file/line) if /pathto/prog.dSYM is alongside the binary, as would be the case if dsymutil /pathto/prog is called:
On OSX, when using non-separate compilation, -g generates a foo.dSYM dir containing DWARF debug info, as can be seen using -v:
# main.c is any c program, eg a hello world
clang -v -g -o /tmp/z12 main.c
# the last step shows:
dsymutil -o /tmp/z12.dSYM /tmp/z12
However, when using separate compilation (as is the case for nim), the last step dsymutil needs to be called explicitly by the build logic.
We can detect whether user requested debug build by optCDebug in conf.globalOptions. If so, we should call dsymutil on executable
proposal
void afterBuild(conf: ConfigRef):
when defined(osx):
# remove directory exe / ".dSYM" if exists
if optCDebug in conf.globalOptions and (isDefined(c) or isDefined(cpp) or isDefined(objc)):
# user requested a debug build, and it's not js or weird target
let exe = conf.outDir / conf.outFile
let cmd = "dsymutil " & quoteShell(exe)
if execShellCmd(cmd) != 0:
echo "dsymutil cmd failed: " & cmd # send a warning or error?note
the separation of debug info from the binary allows several use cases, eg shipping to customers a build stripped from debug info, while still allowing symbolication of stacktraces / core dumps given a (say, non-shipped) .dSYM directory that corresponds to the released binary