From owner-freebsd-bugs@FreeBSD.ORG Tue Dec 14 20:50:08 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2FB771065670 for ; Tue, 14 Dec 2010 20:50:08 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id E47B28FC13 for ; Tue, 14 Dec 2010 20:50:07 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id oBEKo73X092956 for ; Tue, 14 Dec 2010 20:50:07 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id oBEKo7ZY092955; Tue, 14 Dec 2010 20:50:07 GMT (envelope-from gnats) Resent-Date: Tue, 14 Dec 2010 20:50:07 GMT Resent-Message-Id: <201012142050.oBEKo7ZY092955@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Mark Johnston Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 98D45106564A for ; Tue, 14 Dec 2010 20:40:41 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (unknown [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 85C9F8FC1B for ; Tue, 14 Dec 2010 20:40:41 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id oBEKef24085539 for ; Tue, 14 Dec 2010 20:40:41 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id oBEKefJ5085538; Tue, 14 Dec 2010 20:40:41 GMT (envelope-from nobody) Message-Id: <201012142040.oBEKefJ5085538@red.freebsd.org> Date: Tue, 14 Dec 2010 20:40:41 GMT From: Mark Johnston To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: misc/153157: [patch] Add support for generating userland debug symbols during installworld X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Dec 2010 20:50:08 -0000 >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(____) 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: