Skip to content

osx: dsymutil needs to be called for debug builds to keep debug info #12735

@timotheecour

Description

@timotheecour

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:

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

[1] Apple's "Lazy" DWARF Scheme - Dwarf Wiki

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions