diff --git a/etc/mtree/BSD.usr.dist b/etc/mtree/BSD.usr.dist index 336d055..90e7269 100644 --- a/etc/mtree/BSD.usr.dist +++ b/etc/mtree/BSD.usr.dist @@ -18,6 +18,46 @@ aout .. .. + debug + bin + .. + boot + .. + lib + geom + .. + .. + libexec + .. + sbin + .. + usr + bin + .. + games + .. + lib + engines + .. + .. + lib32 + .. + libexec + .. + bsdinstall + .. + lpr + ru + .. + .. + sendmail + .. + sm.bin + .. + sbin + .. + .. + .. dtrace .. engines diff --git a/gnu/usr.bin/gdb/Makefile.inc b/gnu/usr.bin/gdb/Makefile.inc index c40e9b8..5b11bb4 100644 --- a/gnu/usr.bin/gdb/Makefile.inc +++ b/gnu/usr.bin/gdb/Makefile.inc @@ -36,7 +36,7 @@ GDB_CROSS_DEBUGGER= .PATH: ${CNTRB_GDB}/gdb ${CNTRB_GDB}/gdb/cli ${CNTRB_GDB}/gdb/mi \ ${CNTRB_GDB}/gdb/signals ${CNTRB_GDB}/gdb/tui ${TARGET_SUBDIR} -CFLAGS+= -DHAVE_CONFIG_H -DRL_NO_COMPAT -DMI_OUT=1 -DTUI=1 +CFLAGS+= -DHAVE_CONFIG_H -DRL_NO_COMPAT -DMI_OUT=1 -DTUI=1 -DDEBUGDIR=\"/usr/lib/debug\" CFLAGS+= -I. CFLAGS+= -I${TARGET_SUBDIR} CFLAGS+= -I${BMAKE_BU}/libbfd -I${BMAKE_BU}/libbfd/${TARGET_CPUARCH} diff --git a/gnu/usr.bin/gdb/arch/amd64/config.h b/gnu/usr.bin/gdb/arch/amd64/config.h index ac81c54..674f818 100644 --- a/gnu/usr.bin/gdb/arch/amd64/config.h +++ b/gnu/usr.bin/gdb/arch/amd64/config.h @@ -439,9 +439,6 @@ /* Name of this package. */ #define PACKAGE "gdb" -/* Global directory for separate debug files. */ -#define DEBUGDIR "/usr/local/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..b2481f8 100644 --- a/gnu/usr.bin/gdb/arch/arm/config.h +++ b/gnu/usr.bin/gdb/arch/arm/config.h @@ -451,9 +451,6 @@ /* Name of this package. */ #define PACKAGE "gdb" -/* Global directory for separate debug files. */ -#define DEBUGDIR "/usr/local/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..e849e0a 100644 --- a/gnu/usr.bin/gdb/arch/i386/config.h +++ b/gnu/usr.bin/gdb/arch/i386/config.h @@ -439,9 +439,6 @@ /* Name of this package. */ #define PACKAGE "gdb" -/* Global directory for separate debug files. */ -#define DEBUGDIR "/usr/local/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..4cc29f9 100644 --- a/gnu/usr.bin/gdb/arch/ia64/config.h +++ b/gnu/usr.bin/gdb/arch/ia64/config.h @@ -439,9 +439,6 @@ /* Name of this package. */ #define PACKAGE "gdb" -/* Global directory for separate debug files. */ -#define DEBUGDIR "/usr/local/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..2b375a6 100644 --- a/gnu/usr.bin/gdb/arch/mips/config.h +++ b/gnu/usr.bin/gdb/arch/mips/config.h @@ -439,9 +439,6 @@ /* Name of this package. */ #define PACKAGE "gdb" -/* Global directory for separate debug files. */ -#define DEBUGDIR "/usr/local/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..37416a7 100644 --- a/gnu/usr.bin/gdb/arch/powerpc/config.h +++ b/gnu/usr.bin/gdb/arch/powerpc/config.h @@ -439,9 +439,6 @@ /* Name of this package. */ #define PACKAGE "gdb" -/* Global directory for separate debug files. */ -#define DEBUGDIR "/usr/local/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..58843fb 100644 --- a/gnu/usr.bin/gdb/arch/powerpc64/config.h +++ b/gnu/usr.bin/gdb/arch/powerpc64/config.h @@ -439,9 +439,6 @@ /* Name of this package. */ #define PACKAGE "gdb" -/* Global directory for separate debug files. */ -#define DEBUGDIR "/usr/local/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..974e426 100644 --- a/gnu/usr.bin/gdb/arch/sparc64/config.h +++ b/gnu/usr.bin/gdb/arch/sparc64/config.h @@ -439,9 +439,6 @@ /* Name of this package. */ #define PACKAGE "gdb" -/* Global directory for separate debug files. */ -#define DEBUGDIR "/usr/local/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 faa117f..93f4295 100644 --- a/share/man/man5/src.conf.5 +++ b/share/man/man5/src.conf.5 @@ -383,6 +383,12 @@ When set, it also enforces the following options: .It .Va WITHOUT_GROFF .El +.It Va WITH_DEBUG_FILES +Set to strip debug info into a separate file for each executable binary +and shared library. The debug files will be placed in a subdirectory of +.Pa /usr/lib/debug +and are located automatically by +.Xr gdb 1 . .It Va WITHOUT_DICT .\" from FreeBSD: head/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.crunchgen.mk b/share/mk/bsd.crunchgen.mk index 95f1aa3..65c33174 100644 --- a/share/mk/bsd.crunchgen.mk +++ b/share/mk/bsd.crunchgen.mk @@ -47,6 +47,9 @@ CRUNCH_GENERATE_LINKS?= yes CLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h +# Don't try to extract debug info from ${PROG}. +MK_DEBUG_FILES= no + # Program names and their aliases contribute hardlinks to 'rescue' executable, # except for those that get suppressed. .for D in $(CRUNCH_SRCDIRS) diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk index aa3567b..d880766 100644 --- a/share/mk/bsd.lib.mk +++ b/share/mk/bsd.lib.mk @@ -43,6 +43,10 @@ CTFFLAGS+= -g STRIP?= -s .endif +.if ${MK_DEBUG_FILES} != "no" +CFLAGS+= -g +.endif + .include # prefer .s to a .c, add .po, remove stuff not used in the BSD libraries @@ -170,14 +174,17 @@ SOLINKOPTS= -shared -Wl,-x SOLINKOPTS+= -Wl,--fatal-warnings -Wl,--warn-shared-textrel .endif -.if target(beforelinking) -${SHLIB_NAME}: beforelinking -.endif -.if defined(DEBUG_FLAGS) -${SHLIB_NAME}.debug: ${SOBJS} +.if ${MK_DEBUG_FILES} != "no" +SHLIB_NAME_FULL=${SHLIB_NAME}.full .else -${SHLIB_NAME}: ${SOBJS} +SHLIB_NAME_FULL=${SHLIB_NAME} .endif + +.if target(beforelinking) +beforelinking: ${SOBJS} +${SHLIB_NAME_FULL}: beforelinking +.endif +${SHLIB_NAME_FULL}: ${SOBJS} @${ECHO} building shared library ${SHLIB_NAME} @rm -f ${SHLIB_NAME} ${SHLIB_LINK} .if defined(SHLIB_LINK) @@ -196,13 +203,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 ${MK_DEBUG_FILES} != "no" +${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 +287,16 @@ _libinstall: ${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \ ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR} -.if defined(DEBUG_FLAGS) - ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ - ${_INSTALLFLAGS} \ - ${SHLIB_NAME}.symbols ${DESTDIR}${SHLIBDIR} +.if ${MK_DEBUG_FILES} != "no" +.if defined(SHLIBDIR) && ${SHLIBDIR:M/usr/local/*} == "" + -${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${NOBINMODE} \ + ${_INSTALLFLAGS} ${SHLIB_NAME}.debug \ + ${DESTDIR}${DEBUGDIR}${SHLIBDIR}/${SHLIB_NAME}.debug +.else + -${INSTALL} -d -o ${LIBOWN} -g ${LIBGRP} -m ${NOBINMODE} \ + ${_INSTALLFLAGS} ${SHLIB_NAME}.debug \ + ${DESTDIR}${SHLIBDIR} +.endif .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 \ diff --git a/share/mk/bsd.prog.mk b/share/mk/bsd.prog.mk index 950d381..5677563 100644 --- a/share/mk/bsd.prog.mk +++ b/share/mk/bsd.prog.mk @@ -22,14 +22,16 @@ CXXFLAGS+=${DEBUG_FLAGS} .if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != "" CTFFLAGS+= -g .endif +.else +STRIP?= -s .endif -.if defined(CRUNCH_CFLAGS) -CFLAGS+=${CRUNCH_CFLAGS} +.if defined(MK_DEBUG_FLAGS) +CFLAGS+= -g .endif -.if !defined(DEBUG_FLAGS) -STRIP?= -s +.if defined(CRUNCH_CFLAGS) +CFLAGS+=${CRUNCH_CFLAGS} .endif .if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO") @@ -41,14 +43,22 @@ PROG= ${PROG_CXX} .endif .if defined(PROG) + +.if ${MK_DEBUG_FILES} != "no" +PROG_FULL=${PROG}.full +.else +PROG_FULL=${PROG} +.endif + .if defined(SRCS) OBJS+= ${SRCS:N*.h:R:S/$/.o/g} .if target(beforelinking) -${PROG}: beforelinking +beforelinking: ${OBJS} +${PROG_FULL}: beforelinking .endif -${PROG}: ${OBJS} +${PROG_FULL}: ${OBJS} .if defined(PROG_CXX) ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} .else @@ -75,9 +85,10 @@ SRCS= ${PROG}.c OBJS= ${PROG}.o .if target(beforelinking) -${PROG}: beforelinking +beforelinking: ${OBJS} +${PROG_FULL}: beforelinking .endif -${PROG}: ${OBJS} +${PROG_FULL}: ${OBJS} .if defined(PROG_CXX) ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} .else @@ -98,6 +109,18 @@ ${PROG}: ${OBJS} MAN= ${PROG}.1 MAN1= ${MAN} .endif + +PROGNAME?= ${PROG} + +.if ${MK_DEBUG_FILES} != "no" +${PROG}: ${PROG_FULL} ${PROGNAME}.debug + ${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROGNAME}.debug \ + ${PROG_FULL} ${.TARGET} || cp -f ${PROG_FULL} ${.TARGET} + +${PROGNAME}.debug: ${PROG_FULL} + ${OBJCOPY} --only-keep-debug ${PROG_FULL} ${.TARGET} || \ + touch ${.TARGET} +.endif .endif # defined(PROG) all: objwarn ${PROG} ${SCRIPTS} @@ -106,7 +129,10 @@ all: _manpages .endif .if defined(PROG) -CLEANFILES+= ${PROG} +CLEANFILES+= ${PROG} +.if ${MK_DEBUG_FILES} != "no" +CLEANFILES+= ${PROG_FULL} ${PROGNAME}.debug +.endif .endif .if defined(OBJS) @@ -152,12 +178,16 @@ realinstall: _proginstall .ORDER: beforeinstall _proginstall _proginstall: .if defined(PROG) -.if defined(PROGNAME) ${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME} +.if ${MK_DEBUG_FILES} != "no" +.if defined(BINDIR) && ${BINDIR:M/usr/local/*} == "" + -${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${NOBINMODE} \ + ${PROGNAME}.debug ${DESTDIR}${DEBUGDIR}${BINDIR}/${PROGNAME}.debug .else - ${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ - ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR} + -${INSTALL} -d -o ${BINOWN} -g ${BINGRP} -m ${NOBINMODE} \ + ${PROGNAME}.debug ${DESTDIR}${BINDIR} +.endif .endif .endif .endif # !target(realinstall) diff --git a/tools/build/options/WITH_DEBUG_FILES b/tools/build/options/WITH_DEBUG_FILES new file mode 100644 index 0000000..be9b50e --- /dev/null +++ b/tools/build/options/WITH_DEBUG_FILES @@ -0,0 +1,6 @@ +.\" $FreeBSD$ +Set to strip debug info into a separate file for each executable binary +and shared library. The debug files will be placed in a subdirectory of +.Pa /usr/lib/debug +and are located automatically by +.Xr gdb 1 .