tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Confused about MKBUILD=yes



Thanks for replying, comments below.

Greg A. Woods wrote:
At Sun, 07 Mar 2010 01:33:43 -0500, Richard Hansen <rhansen%bbn.com@localhost> 
wrote:
Subject: Confused about MKBUILD=yes
While investigating a segfault in libpam on the netbsd-5 branch, I discovered that MKDEBUG=yes (see mk.conf(5)):

   * does not install debugging symbols for libraries
* does not install any debug symbols at all (because it does not cause -g to be passed to gcc)
   * does not strip debug symbols from installed binaries

You need all of the following:

    MKDEBUG=    yes

Unfortunately, this only affects programs, not libraries.

    MKDEBUGLIB= yes

This only adds -DDEBUG to the preprocessor flags (for libraries only, not programs). I don't want to change the behavior of the libraries; I just want debug symbols so that gdb gives me useful backtraces.

    DBG=        -g

Isn't the DBG variable an implementation detail? I don't see it documented anywhere. Also, DBG seems to only be used for optimization, not debug.

COPTS is documented and intended to be used in mk.conf, so my first instinct is to use it instead. But really I'd rather just set MKDEBUG=yes and have everything work as expected.

The "debug" symbols are stripped and saved to a hierarchy of files in /usr/libdata/debug.

I don't think the debug symbols are stripped -- they're just *copied* to /usr/libdata/debug. Here are the relevant lines from bsd.prog.mk:

.for _P in ${PROGS} ${PROGS_CXX}
PROGNAME.${_P}?=        ${_P}
.if ${MKDEBUG} != "no" && ${OBJECT_FMT} == "ELF" && !commands(${_P})
_PROGDEBUG.${_P}:=      ${PROGNAME.${_P}}.debug
.endif
.if defined(_PROGDEBUG.${_P})
${_PROGDEBUG.${_P}}: ${_P}
        ${_MKTARGET_CREATE}
        ${OBJCOPY} --only-keep-debug ${_P} ${_PROGDEBUG.${_P}}
${OBJCOPY} -R .gnu_debuglink --add-gnu-debuglink=${_PROGDEBUG.${_P}} ${_P} \
            || rm -f ${_PROGDEBUG.${_P}}
.endif
.endfor

The first objcopy line copies the debug symbols to /usr/libdata/debug. The second objcopy line adds a reference to the copied symbols, but it doesn't actually strip anything from the original binary.

To strip the original binaries, I think the following rule might work:

${_PROGDEBUG.${_P}}: ${_P}
        ${_MKTARGET_CREATE}
        ${OBJCOPY} --only-keep-debug ${_P} ${_PROGDEBUG.${_P}}
${OBJCOPY} --strip-debug -R .gnu_debuglink --add-gnu-debuglink=${_PROGDEBUG.${_P}} ${_P} \
            || rm -f ${_PROGDEBUG.${_P}}

You can load these *.debug symbol files in gdb with the "symbol-file" command.

I don't think the symbol-file command is needed; gdb will see the .gnu_debuglink section in the ELF binary and simply load the file listed there.

Thanks for the info,
Richard


Home | Main Index | Thread Index | Old Index