Hi all,

I have some tentative patches which add support for creating a separate
directory containing all of the userland debugging symbols.

I posted about this a week or so ago:
http://lists.freebsd.org/pipermail/freebsd-hackers/2010-October/033437.html

Some future work will involve finding out if any changes are necessary to
support Clang/LLVM, and seeing whether there's any interest in adding
support to the FreeBSD installer to install the debug symbols to a
user-defined directory.

Note that DEBUG_FLAGS must be set somewhere when building world -
adding WITH_DEBUG_SYMBOLS_DIR=yes to src.conf beforehand is sufficient,
as it causes DEBUG_FLAGS+=-g to be set; building world with DEBUG_FLAGS=-g
alone is also sufficient. If the binaries are built without debug symbols
and one tries to use my new option, nothing happens, i.e., no new
files/directories are created, unless specific programs explicitly
build with -g somehow (see below).

My changes are below. There's a new file (stripbin.sh) which invokes
objcopy(1) and strip(1). At the moment it's in usr/src, but it should
probably go elsewhere... perhaps usr/src/tools? The other changes are to
bsd.prog.mk, bsd.own.mk and the src.conf man page.

I've also noticed a few Makefiles that explicitly set DEBUG_FLAGS=-g
or CFLAGS+=-g for some reason. They are in

usr.bin/tar/
cddl/usr.bin/ctfconvert/
cddl/usr.sbin/usr.sbin/lockstat/
usr.sbin/wpa/wpa_supplicant/
usr.sbin/wpa/hostapd/
usr.sbin/bluetooth/bthidd/

I'm not sure if this is intentional.

Feedback and suggestions are extremely welcome. =)

Thanks,
-Mark

diff --git a/stripbin.sh b/stripbin.sh
new file mode 100755
index 0000000..be2e9ad
--- /dev/null
+++ b/stripbin.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+# This script is invoked by install(1) on all binaries when installing world.
+# It determines whether any debug info is present in the binary; if so, it
+# will extract the debug symbols to $SYMBOLS_FULLPATH, strip the binary and
+# add a link to the binary which points to the file containing the debugging 
+# symbols.
+
+: ${READELFEXEC:=/usr/obj/usr/src/gnu/usr.bin/binutils/readelf/readelf}
+: ${STRIPEXEC:=/usr/obj/usr/src/gnu/usr.bin/binutils/strip/strip}
+: ${OBJCEXEC:=/usr/obj/usr/src/gnu/usr.bin/binutils/objcopy/objcopy}
+: ${DIRNAMEEXEC:=/usr/obj/usr/src/usr.bin/dirname/dirname}
+
+SYMBOLS_FULLPATH="${SYMBOLS_DIR}`${DIRNAMEEXEC} ${1}`"
+
+case $1 in
+/*...@*)
+       exit 0
+       ;;
+esac
+
+# Make sure that some debug info is actually present.
+[ -z `$READELFEXEC -wi $1` ] && exit 0
+
+mkdir -p $SYMBOLS_FULLPATH
+
+$STRIPEXEC --only-keep-debug -o ${SYMBOLS_DIR}${1}.symbols $1
+$STRIPEXEC --strip-debug $1
+$OBJCEXEC --add-gnu-debuglink=${SYMBOLS_DIR}${1}.symbols $1
diff --git a/share/mk/bsd.prog.mk b/share/mk/bsd.prog.mk
index 47b43ab..9809db0 100644
--- a/share/mk/bsd.prog.mk
+++ b/share/mk/bsd.prog.mk
@@ -29,6 +29,12 @@ CFLAGS+=${CRUNCH_CFLAGS}
 
 .if !defined(DEBUG_FLAGS)
 STRIP?=        -s
+.else
+
+.if defined(STRIPSCRIPT)
+STRIP?= -s
+INSTALL:= /usr/bin/env SYMBOLS_DIR=${SYMBOLS_DIR} STRIPBIN=${STRIPSCRIPT} 
${INSTALL}
+.endif
 .endif
 
 .if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO")
diff --git a/share/mk/bsd.own.mk b/share/mk/bsd.own.mk
index 3aa832c..80b42ad 100644
--- a/share/mk/bsd.own.mk
+++ b/share/mk/bsd.own.mk
@@ -541,6 +541,12 @@ MK_${vv:H}:=       ${MK_${vv:T}}
 .endif
 .endfor
 
+.if defined(WITH_DEBUG_SYMBOLS_DIR)
+DEBUG_FLAGS+=  -g
+STRIPSCRIPT=   /usr/src/stripbin.sh
+SYMBOLS_DIR?=  /usr/local/lib/debug
+.endif
+
 .endif # !_WITHOUT_SRCCONF
 
 .endif # !target(__<bsd.own.mk>__)
diff --git a/share/man/man5/src.conf.5 b/share/man/man5/src.conf.5
index 4f8f9a1..d787746 100644
--- a/share/man/man5/src.conf.5
+++ b/share/man/man5/src.conf.5
@@ -283,6 +283,15 @@ Set to not build CVS.
 Set to not build
 .Xr g++ 1
 and related libraries.
+.It Va WITH_DEBUG_SYMBOLS_DIR
+Set this to have userland debugging symbols placed in a separate directory.
+By default, they will be placed in
+.Pa /usr/local/lib/debug/ .
+A different location can be specified by defining
+.Va SYMBOLS_DIR
+when running make installworld.
+Define this variable before running make buildworld to ensure that
+the userland binaries will be built with debug symbols in the first place.
 .It Va WITHOUT_DICT
 .\" from FreeBSD: stable/8/tools/build/options/WITHOUT_DICT 156932 2006-03-21 
07:50:50Z ru
 Set to not build the Webster dictionary files.
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"

Reply via email to