Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 Dec 2010 20:40:41 GMT
From:      Mark Johnston <markjdb@gmail.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   misc/153157: [patch] Add support for generating userland debug symbols during installworld
Message-ID:  <201012142040.oBEKefJ5085538@red.freebsd.org>
Resent-Message-ID: <201012142050.oBEKo7ZY092955@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         153157
>Category:       misc
>Synopsis:       [patch] Add support for generating userland debug symbols during installworld
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Dec 14 20:50:07 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Mark Johnston
>Release:        STABLE-8
>Organization:
>Environment:
FreeBSD mark-laptop-bsd.mark-home 8.2-PRERELEASE FreeBSD 8.2-PRERELEASE #7 r+46c51f0-dirty: Tue Dec  7 11:17:13 EST 2010     mark@mark-laptop-bsd.mark-home:/usr/obj/usr/home/mark/src/freebsd_git/src/sys/IPFW_GENERIC  i386
>Description:
I posted about this in a few threads on -hackers:

http://lists.freebsd.org/pipermail/freebsd-hackers/2010-November/033474.html

I just thought I'd open a PR in case someone is still interested.

The details are in my posts, but the basic idea behind this change is to allow users to have a 'make installworld' generate a directory (/usr/lib/debug) containing debug symbols for all of the base FreeBSD binaries. With my change, this can be done by adding an option to src.conf.

At the moment, my change adds a script to src/tools/ which is the script invoked by install(1) to strip and extract the debug symbols from each binary that gets installed. I'm not sure that this is the best place for it, but it seems ok to me.
>How-To-Repeat:

>Fix:
I have a patch which applies against HEAD (as of a few days ago).

Patch attached with submission follows:

diff --git a/gnu/usr.bin/gdb/arch/amd64/config.h b/gnu/usr.bin/gdb/arch/amd64/config.h
index 29f2d95..026117e 100644
--- a/gnu/usr.bin/gdb/arch/amd64/config.h
+++ b/gnu/usr.bin/gdb/arch/amd64/config.h
@@ -440,7 +440,7 @@
 #define PACKAGE "gdb"
 
 /* Global directory for separate debug files.  */
-#define DEBUGDIR "/usr/local/lib/debug"
+#define DEBUGDIR "/usr/lib/debug"
 
 /* Define to BFD's default architecture.  */
 #define DEFAULT_BFD_ARCH bfd_i386_arch
diff --git a/gnu/usr.bin/gdb/arch/arm/config.h b/gnu/usr.bin/gdb/arch/arm/config.h
index 535bd6f..fc5f895 100644
--- a/gnu/usr.bin/gdb/arch/arm/config.h
+++ b/gnu/usr.bin/gdb/arch/arm/config.h
@@ -452,7 +452,7 @@
 #define PACKAGE "gdb"
 
 /* Global directory for separate debug files.  */
-#define DEBUGDIR "/usr/local/lib/debug"
+#define DEBUGDIR "/usr/lib/debug"
 
 /* Define to BFD's default architecture.  */
 #define DEFAULT_BFD_ARCH bfd_arm_arch
diff --git a/gnu/usr.bin/gdb/arch/i386/config.h b/gnu/usr.bin/gdb/arch/i386/config.h
index 683f683..1d4b243 100644
--- a/gnu/usr.bin/gdb/arch/i386/config.h
+++ b/gnu/usr.bin/gdb/arch/i386/config.h
@@ -440,7 +440,7 @@
 #define PACKAGE "gdb"
 
 /* Global directory for separate debug files.  */
-#define DEBUGDIR "/usr/local/lib/debug"
+#define DEBUGDIR "/usr/lib/debug"
 
 /* Define to BFD's default architecture.  */
 #define DEFAULT_BFD_ARCH bfd_i386_arch
diff --git a/gnu/usr.bin/gdb/arch/ia64/config.h b/gnu/usr.bin/gdb/arch/ia64/config.h
index 0e284d5..72878ae 100644
--- a/gnu/usr.bin/gdb/arch/ia64/config.h
+++ b/gnu/usr.bin/gdb/arch/ia64/config.h
@@ -440,7 +440,7 @@
 #define PACKAGE "gdb"
 
 /* Global directory for separate debug files.  */
-#define DEBUGDIR "/usr/local/lib/debug"
+#define DEBUGDIR "/usr/lib/debug"
 
 /* Define to BFD's default architecture.  */
 #define DEFAULT_BFD_ARCH bfd_ia64_arch
diff --git a/gnu/usr.bin/gdb/arch/mips/config.h b/gnu/usr.bin/gdb/arch/mips/config.h
index 114a0f9..39dcc31 100644
--- a/gnu/usr.bin/gdb/arch/mips/config.h
+++ b/gnu/usr.bin/gdb/arch/mips/config.h
@@ -440,7 +440,7 @@
 #define PACKAGE "gdb"
 
 /* Global directory for separate debug files.  */
-#define DEBUGDIR "/usr/local/lib/debug"
+#define DEBUGDIR "/usr/lib/debug"
 
 /* Define to BFD's default architecture.  */
 #define DEFAULT_BFD_ARCH bfd_mips_arch
diff --git a/gnu/usr.bin/gdb/arch/powerpc/config.h b/gnu/usr.bin/gdb/arch/powerpc/config.h
index 7bc963d..c916419 100644
--- a/gnu/usr.bin/gdb/arch/powerpc/config.h
+++ b/gnu/usr.bin/gdb/arch/powerpc/config.h
@@ -440,7 +440,7 @@
 #define PACKAGE "gdb"
 
 /* Global directory for separate debug files.  */
-#define DEBUGDIR "/usr/local/lib/debug"
+#define DEBUGDIR "/usr/lib/debug"
 
 /* Define to BFD's default architecture.  */
 #define DEFAULT_BFD_ARCH bfd_rs6000_arch
diff --git a/gnu/usr.bin/gdb/arch/sparc64/config.h b/gnu/usr.bin/gdb/arch/sparc64/config.h
index 66fcb1f..a407d06 100644
--- a/gnu/usr.bin/gdb/arch/sparc64/config.h
+++ b/gnu/usr.bin/gdb/arch/sparc64/config.h
@@ -440,7 +440,7 @@
 #define PACKAGE "gdb"
 
 /* Global directory for separate debug files.  */
-#define DEBUGDIR "/usr/local/lib/debug"
+#define DEBUGDIR "/usr/lib/debug"
 
 /* Define to BFD's default architecture.  */
 #define DEFAULT_BFD_ARCH bfd_sparc_arch
diff --git a/share/man/man5/src.conf.5 b/share/man/man5/src.conf.5
index 180d333..7335fe0 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.
diff --git a/share/mk/bsd.own.mk b/share/mk/bsd.own.mk
index 3361295..74d52b1 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
+STRIPBIN=	/usr/src/tools/stripbin.sh
+SYMBOLS_DIR?=	${DESTDIR}${LIBDIR}/debug
+.endif
+
 .endif # !_WITHOUT_SRCCONF
 
 .endif	# !target(__<bsd.own.mk>__)
diff --git a/share/mk/bsd.prog.mk b/share/mk/bsd.prog.mk
index bc3f15c..0be07be 100644
--- a/share/mk/bsd.prog.mk
+++ b/share/mk/bsd.prog.mk
@@ -29,6 +29,11 @@ CFLAGS+=${CRUNCH_CFLAGS}
 
 .if !defined(DEBUG_FLAGS)
 STRIP?=	-s
+.else
+.if defined(STRIPBIN)
+STRIP?= -s
+INSTALL:= /usr/bin/env SYMBOLS_DIR=${SYMBOLS_DIR} STRIPBIN=${STRIPBIN} ${INSTALL}
+.endif
 .endif
 
 .if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO")
diff --git a/tools/stripbin.sh b/tools/stripbin.sh
new file mode 100755
index 0000000..7efe6b1
--- /dev/null
+++ b/tools/stripbin.sh
@@ -0,0 +1,26 @@
+#!/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.
+
+PATH=${PATH}:/usr/bin
+
+SYMBOLS_FULLPATH="${SYMBOLS_DIR}$(dirname ${1})"
+
+case $1 in
+/*INS@*)
+        exit 0
+	;;
+esac
+
+# Make sure that some debug info is actually present.
+[ -z "$(readelf -wi $1)" ] && exit 0
+
+mkdir -p $SYMBOLS_FULLPATH
+
+strip --only-keep-debug -o ${SYMBOLS_DIR}${1}.symbols $1
+strip --strip-debug $1
+objcopy --add-gnu-debuglink=${SYMBOLS_DIR}${1}.symbols $1


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201012142040.oBEKefJ5085538>