Use -fdebug-prefix-map to map auto-generated kernel build paths.

The kernel build uses symlinks to make MD #includes like <machine/pcpu.h>
work.  Debug info ends up referencing these symlinks in a relative path,
so debuggers generally don't know how to find the corresponding headers.
Address this by using -fdebug-prefix-map to map relative paths through
the symlinks to their absolute paths in the source tree.  This is
consistent with how regular source file paths are defined in the
kernel's debug info.

Also map the current directory to an absolute path to the object
directory.  This gives debuggers a chance to find auto-generated files
like vnode_if.c if the object directory is available.

Reviewed by:	emaste, jhb (previous version)
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D19633
This commit is contained in:
Mark Johnston 2019-03-20 20:42:44 +00:00
parent fb7e42b9fd
commit 7114b1763c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=345348
2 changed files with 36 additions and 0 deletions

View File

@ -328,6 +328,11 @@ ${__obj}: ${OBJS_DEPEND_GUESS.${__obj}}
.depend: .PRECIOUS ${SRCS}
.if ${COMPILER_TYPE} == "clang" || \
(${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 60000)
_MAP_DEBUG_PREFIX= yes
.endif
_ILINKS= machine
.if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64"
_ILINKS+= ${MACHINE_CPUARCH}
@ -337,12 +342,25 @@ _ILINKS+= x86
.endif
# Ensure that the link exists without depending on it when it exists.
# Ensure that debug info references the path in the source tree.
.for _link in ${_ILINKS}
.if !exists(${.OBJDIR}/${_link})
${SRCS} ${CLEAN:M*.o}: ${_link}
.endif
.if defined(_MAP_DEBUG_PREFIX)
.if ${_link} == "machine"
CFLAGS+= -fdebug-prefix-map=./machine=${SYSDIR}/${MACHINE}/include
.else
CFLAGS+= -fdebug-prefix-map=./${_link}=${SYSDIR}/${_link}/include
.endif
.endif
.endfor
.if defined(_MAP_DEBUG_PREFIX)
# Ensure that DWARF info contains a full path for auto-generated headers.
CFLAGS+= -fdebug-prefix-map=.=${.OBJDIR}
.endif
${_ILINKS}:
@case ${.TARGET} in \
machine) \

View File

@ -267,6 +267,11 @@ ${FULLPROG}: ${OBJS}
${OBJCOPY} --strip-debug ${.TARGET}
.endif
.if ${COMPILER_TYPE} == "clang" || \
(${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 60000)
_MAP_DEBUG_PREFIX= yes
.endif
_ILINKS=machine
.if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64"
_ILINKS+=${MACHINE_CPUARCH}
@ -283,12 +288,25 @@ beforebuild: ${_ILINKS}
# Ensure that the links exist without depending on it when it exists which
# causes all the modules to be rebuilt when the directory pointed to changes.
# Ensure that debug info references the path in the source tree.
.for _link in ${_ILINKS}
.if !exists(${.OBJDIR}/${_link})
OBJS_DEPEND_GUESS+= ${_link}
.endif
.if defined(_MAP_DEBUG_PREFIX)
.if ${_link} == "machine"
CFLAGS+= -fdebug-prefix-map=./machine=${SYSDIR}/${MACHINE}/include
.else
CFLAGS+= -fdebug-prefix-map=./${_link}=${SYSDIR}/${_link}/include
.endif
.endif
.endfor
.if defined(_MAP_DEBUG_PREFIX)
# Ensure that DWARF info contains a full path for auto-generated headers.
CFLAGS+= -fdebug-prefix-map=.=${.OBJDIR}
.endif
.NOPATH: ${_ILINKS}
${_ILINKS}: