Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Dec 2012 16:46:02 +0000
From:      Ed Maste <emaste@freebsd.org>
To:        freebsd-hackers@freebsd.org
Subject:   [PATCH] Add WITH_DEBUG_FILES knob to enable separate debug files
Message-ID:  <20121222164602.GB32022@sandvine.com>

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

--XsQoSWH+UP9D9v3l
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

When this knob is set standalone debug files for shared objects are
built and installed in /usr/lib/debug/<so pathname>.debug.  GDB
searches this path for debug data.

The -g flag is automatically added to CFLAGS if debug files are enabled
(but the shared objects are still installed stripped, if DEBUG_FLAGS is
not set).
---
This is a refinement of my earlier change for shared object standalone
debug.  This patch also includes the following changes:

- Change GDB's standalone debug file path to the default /usr/lib/debug.

- Change debug file extension from 'symbols' to 'debug', in line with
  GDB's documentation.  I initially followed the kernel build example
  in choosing .symbols, but .debug more accurately represents the use
  of these files.

--XsQoSWH+UP9D9v3l
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="usr_lib_debug.diff"

diff --git a/etc/mtree/BSD.usr.dist b/etc/mtree/BSD.usr.dist
index 336d055..7b428d5 100644
--- a/etc/mtree/BSD.usr.dist
+++ b/etc/mtree/BSD.usr.dist
@@ -18,6 +18,22 @@
             aout
             ..
         ..
+        debug
+            boot
+            ..
+            lib
+                geom
+                ..
+            ..
+            usr
+                lib
+                    engines
+                    ..
+                ..
+                lib32
+                ..
+            ..
+        ..
         dtrace
         ..
         engines
diff --git a/gnu/usr.bin/gdb/arch/amd64/config.h b/gnu/usr.bin/gdb/arch/amd64/config.h
index ac81c54..ae3e104 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 e1b128c..26b1891 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 f21da4c..30e75c3 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 5faa96b..f8c84ab 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 41a6731..01a7869 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 f169fad..49472e7 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/powerpc64/config.h b/gnu/usr.bin/gdb/arch/powerpc64/config.h
index d8b9b6d..c904d1d 100644
--- a/gnu/usr.bin/gdb/arch/powerpc64/config.h
+++ b/gnu/usr.bin/gdb/arch/powerpc64/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 5527a79..ff87c28 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/mk/bsd.lib.mk b/share/mk/bsd.lib.mk
index aa3567b..a3fa175 100644
--- a/share/mk/bsd.lib.mk
+++ b/share/mk/bsd.lib.mk
@@ -43,6 +43,10 @@ CTFFLAGS+= -g
 STRIP?=	-s
 .endif
 
+.if defined(MK_DEBUG_FILES) && empty(${DEBUG_FLAGS:M-g})
+CFLAGS+= -g
+.endif
+
 .include <bsd.libnames.mk>
 
 # prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
@@ -173,8 +177,8 @@ SOLINKOPTS+=	-Wl,--fatal-warnings -Wl,--warn-shared-textrel
 .if target(beforelinking)
 ${SHLIB_NAME}: beforelinking
 .endif
-.if defined(DEBUG_FLAGS)
-${SHLIB_NAME}.debug: ${SOBJS}
+.if defined(MK_DEBUG_FILES)
+${SHLIB_NAME}.full: ${SOBJS}
 .else
 ${SHLIB_NAME}: ${SOBJS}
 .endif
@@ -196,13 +200,13 @@ ${SHLIB_NAME}: ${SOBJS}
 	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SOBJS}
 .endif
 
-.if defined(DEBUG_FLAGS)
-${SHLIB_NAME}: ${SHLIB_NAME}.debug ${SHLIB_NAME}.symbols
-	${OBJCOPY} --strip-debug --add-gnu-debuglink=${SHLIB_NAME}.symbols \
-	    ${SHLIB_NAME}.debug ${.TARGET}
+.if defined(MK_DEBUG_FILES)
+${SHLIB_NAME}: ${SHLIB_NAME}.full ${SHLIB_NAME}.debug
+	${OBJCOPY} --strip-debug --add-gnu-debuglink=${SHLIB_NAME}.debug \
+	    ${SHLIB_NAME}.full ${.TARGET}
 
-${SHLIB_NAME}.symbols: ${SHLIB_NAME}.debug
-	${OBJCOPY} --only-keep-debug ${SHLIB_NAME}.debug ${.TARGET}
+${SHLIB_NAME}.debug: ${SHLIB_NAME}.full
+	${OBJCOPY} --only-keep-debug ${SHLIB_NAME}.full ${.TARGET}
 .endif
 .endif
 
@@ -280,10 +284,10 @@ _libinstall:
 	${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
 	    ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
 	    ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR}
-.if defined(DEBUG_FLAGS)
+.if defined(MK_DEBUG_FILES)
 	${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
 	    ${_INSTALLFLAGS} \
-	    ${SHLIB_NAME}.symbols ${DESTDIR}${SHLIBDIR}
+	    ${SHLIB_NAME}.debug ${DESTDIR}${DEBUGDIR}${SHLIBDIR}
 .endif
 .if defined(SHLIB_LINK)
 # ${_SHLIBDIRPREFIX} and ${_LDSCRIPTROOT} are both needed when cross-building
diff --git a/share/mk/bsd.own.mk b/share/mk/bsd.own.mk
index 78af8fb..cf83264 100644
--- a/share/mk/bsd.own.mk
+++ b/share/mk/bsd.own.mk
@@ -43,6 +43,9 @@
 # LIBMODE	Library mode. [${NOBINMODE}]
 #
 #
+# DEBUGDIR	Base path for standalone debug files. [/usr/lib/debug]
+#
+#
 # KMODDIR	Base path for loadable kernel modules
 #		(see kld(4)). [/boot/kernel]
 #
@@ -147,6 +150,8 @@ LIBOWN?=	${BINOWN}
 LIBGRP?=	${BINGRP}
 LIBMODE?=	${NOBINMODE}
 
+DEBUGDIR?=	/usr/lib/debug
+
 
 # Share files
 SHAREDIR?=	/usr/share
@@ -427,6 +432,7 @@ __DEFAULT_NO_OPTIONS = \
     BSD_GREP \
     CLANG_EXTRAS \
     CTF \
+    DEBUG_FILES \
     HESIOD \
     ICONV \
     IDEA \

--XsQoSWH+UP9D9v3l--



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