From owner-freebsd-hackers@FreeBSD.ORG Fri Nov 5 19:15:03 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 920B81065679 for ; Fri, 5 Nov 2010 19:15:03 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-yx0-f182.google.com (mail-yx0-f182.google.com [209.85.213.182]) by mx1.freebsd.org (Postfix) with ESMTP id 44DB58FC14 for ; Fri, 5 Nov 2010 19:15:02 +0000 (UTC) Received: by yxl31 with SMTP id 31so2504549yxl.13 for ; Fri, 05 Nov 2010 12:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:subject :message-id:mime-version:content-type:content-disposition:user-agent; bh=W/8gJP2KFebQpJ9CKkumzoMLHypuiI+6EWW8ZTm7nv0=; b=I6THbEaC9sqTA74hF3H3le72Uk7UKsOHNai1sHyy8BssjSU4P0WRdFbiQmdAU5u50J KcHBzj/fI7yL51Kxq7whtMXHy9LQNEdfWDnCHC/5y2Kf3BMZAfk6zNpjI3OYzu8BfleU 6FVmD+m0tNnSfBfq9PNF7wZlW4JKDiHI3YyWw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; b=g1fjNJpsy2lEnvrR/uEcFOJxo5oSsAgT78CG44JLzccJyhkaVYyA3rPwNxlRNRd79Q S0Dq7oKUMIBnn928sD8U/bAyZGwFPiHX9hMnVlXq3yLcPLF4eJmcoibbSR/F6PGN5o+f +EmMtnhCVZr2UObp4NkVH3FWErDcQ2sg/BN8w= Received: by 10.100.229.16 with SMTP id b16mr63114anh.109.1288984502024; Fri, 05 Nov 2010 12:15:02 -0700 (PDT) Received: from mark-laptop-bsd.mark-home (Mail1.sandvine.com [64.7.137.162]) by mx.google.com with ESMTPS id 6sm1787700anx.32.2010.11.05.12.15.00 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 05 Nov 2010 12:15:01 -0700 (PDT) Date: Fri, 5 Nov 2010 15:14:43 -0400 From: Mark Johnston To: freebsd-hackers@freebsd.org Message-ID: <20101105191443.GD1437@mark-laptop-bsd.mark-home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Subject: Userland debug symbols directory X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Nov 2010 19:15:03 -0000 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 +/*INS@*) + 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(____) 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.