Module Name:    src
Committed By:   christos
Date:           Wed Dec 29 22:22:13 UTC 2021

Modified Files:
        src: build.sh
        src/distrib/sets: sets.subr
        src/distrib/sets/lists/debug: mi
        src/etc: Makefile
        src/sys/conf: Makefile.kern.inc

Log Message:
Enable split-debug files for kernels. Enabled by default with MKDEBUG=yes.


To generate a diff of this commit:
cvs rdiff -u -r1.359 -r1.360 src/build.sh
cvs rdiff -u -r1.197 -r1.198 src/distrib/sets/sets.subr
cvs rdiff -u -r1.369 -r1.370 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.455 -r1.456 src/etc/Makefile
cvs rdiff -u -r1.285 -r1.286 src/sys/conf/Makefile.kern.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/build.sh
diff -u src/build.sh:1.359 src/build.sh:1.360
--- src/build.sh:1.359	Mon Oct  4 17:02:40 2021
+++ src/build.sh	Wed Dec 29 17:22:12 2021
@@ -1,5 +1,5 @@
 #! /usr/bin/env sh
-#	$NetBSD: build.sh,v 1.359 2021/10/04 21:02:40 andvar Exp $
+#	$NetBSD: build.sh,v 1.360 2021/12/29 22:22:12 christos Exp $
 #
 # Copyright (c) 2001-2011 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -1974,7 +1974,7 @@ createmakewrapper()
 	eval cat <<EOF ${makewrapout}
 #! ${HOST_SH}
 # Set proper variables to allow easy "make" building of a NetBSD subtree.
-# Generated from:  \$NetBSD: build.sh,v 1.359 2021/10/04 21:02:40 andvar Exp $
+# Generated from:  \$NetBSD: build.sh,v 1.360 2021/12/29 22:22:12 christos Exp $
 # with these arguments: ${_args}
 #
 
@@ -2111,6 +2111,7 @@ buildkernel()
 	    bomb "${toolprefix}config failed for ${kernelconf}"
 	make_in_dir "${kernelbuildpath}" depend
 	make_in_dir "${kernelbuildpath}" all
+	make_in_dir "${kernelbuildpath}" debuginstall
 
 	if [ "${runcmd}" != "echo" ]; then
 		statusmsg "Kernels built from ${kernelconf}:"

Index: src/distrib/sets/sets.subr
diff -u src/distrib/sets/sets.subr:1.197 src/distrib/sets/sets.subr:1.198
--- src/distrib/sets/sets.subr:1.197	Sat Sep 25 17:26:03 2021
+++ src/distrib/sets/sets.subr	Wed Dec 29 17:22:13 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: sets.subr,v 1.197 2021/09/25 21:26:03 maya Exp $
+#	$NetBSD: sets.subr,v 1.198 2021/12/29 22:22:13 christos Exp $
 #
 
 #
@@ -192,7 +192,7 @@ SUBST="${SUBST};s#@MACHINE@#${MACHINE}#g
 # In each file, a record consists of a path and a System Package name,
 # separated by whitespace. E.g.,
 #
-# 	# $NetBSD: sets.subr,v 1.197 2021/09/25 21:26:03 maya Exp $
+# 	# $NetBSD: sets.subr,v 1.198 2021/12/29 22:22:13 christos Exp $
 # 	.			base-sys-root	[keyword[,...]]
 # 	./altroot		base-sys-root
 # 	./bin			base-sys-root
@@ -263,19 +263,34 @@ list_set_files()
 	else
 		verbose=true
 	fi
+	local CONFIGS="$( list_kernel_configs )"
 	print_set_lists "$@" | \
 	${AWK} -v obsolete=${obsolete} '
 		function addkmod(line, fname, prefix, pat, patlen) {
 			if (substr(line, 1, patlen) != pat) {
-				return;
+				return
 			}
 			for (d in kmodarchdirs) {
 				xd = prefix kmodarchdirs[d]
-				xfile = xd substr(line, patlen + 1)
-				tmp = xd substr(fname, patlen + 1)
-				list[xfile] = tmp;
+				xline = xd substr(line, patlen + 1)
+				xfname = xd substr(fname, patlen + 1)
+				list[xline] = xfname
 			}
 		}
+		function adddebugkernel(line, fname, pat, patlen) {
+			if (substr(line, 1, patlen) != pat) {
+				return 0
+			}
+			split("'"${CONFIGS}"'", configs)
+			for (d in configs) {
+				xfname = fname
+				sub("CONFIG", configs[d], xfname)
+				xline = line;
+				sub("CONFIG", configs[d], xline)
+				list[xline] = xfname
+			}
+			return 1
+		}
 		BEGIN {
 			if (obsolete)
 				wanted["obsolete"] = 1
@@ -327,6 +342,10 @@ list_set_files()
 				kmoddbpat = kmoddbprefix ENVIRON["MACHINE"]
 				l_kmoddbpat = length(kmoddbpat)
 			}
+			if ("debug" in wanted) {
+				debugkernelname = "./usr/libdata/debug/netbsd-CONFIG.debug"
+				l_debugkernelname = length(debugkernelname);
+			}
 
 			if ("'"${TOOLCHAIN_MISSING}"'" != "yes") {
 				if ("binutils" in wanted)
@@ -424,6 +443,8 @@ list_set_files()
 				next
 			if (!show)
 				next
+			if (adddebugkernel($0, $1, debugkernelname, l_debugkernelname))
+				next
 
 			list[$1] = $0
 			if (havekmod > 0) {
@@ -647,6 +668,14 @@ print_set_lists()
 	done | ${XARGS} ${SED} ${SUBST}
 }
 
+
+list_kernel_configs()
+{
+	(cd ${NETBSDSRCDIR}/etc
+	MAKEFLAGS= \
+	${MAKE} -m ${NETBSDSRCDIR}/share/mk -V '${ALL_KERNELS}')
+}
+
 # arch_to_cpu mach
 #
 # Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,

Index: src/distrib/sets/lists/debug/mi
diff -u src/distrib/sets/lists/debug/mi:1.369 src/distrib/sets/lists/debug/mi:1.370
--- src/distrib/sets/lists/debug/mi:1.369	Tue Dec  7 12:39:53 2021
+++ src/distrib/sets/lists/debug/mi	Wed Dec 29 17:22:13 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.369 2021/12/07 17:39:53 brad Exp $
+# $NetBSD: mi,v 1.370 2021/12/29 22:22:13 christos Exp $
 ./etc/mtree/set.debug                           comp-sys-root
 ./usr/lib					comp-sys-usr		compatdir
 ./usr/lib/i18n/libBIG5_g.a			comp-c-debuglib		debuglib,compatfile
@@ -325,6 +325,7 @@
 ./usr/libdata/debug/bin/test.debug		comp-util-debug		debug
 ./usr/libdata/debug/libexec/lfs_cleanerd.debug	comp-sysutil-debug	debug
 ./usr/libdata/debug/netbsd			comp-sysutil-debug	debug,kernel_dir
+./usr/libdata/debug/netbsd-CONFIG.debug		comp-sysutil-debug	debug
 ./usr/libdata/debug/sbin/amrctl.debug		comp-sysutil-debug	debug
 ./usr/libdata/debug/sbin/apmlabel.debug		comp-sysutil-debug	debug
 ./usr/libdata/debug/sbin/atactl.debug		comp-sysutil-debug	debug

Index: src/etc/Makefile
diff -u src/etc/Makefile:1.455 src/etc/Makefile:1.456
--- src/etc/Makefile:1.455	Thu Dec 23 09:50:59 2021
+++ src/etc/Makefile	Wed Dec 29 17:22:13 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.455 2021/12/23 14:50:59 christos Exp $
+#	$NetBSD: Makefile,v 1.456 2021/12/29 22:22:13 christos Exp $
 #	from: @(#)Makefile	8.7 (Berkeley) 5/25/95
 
 # Environment variables without default values:
@@ -158,6 +158,7 @@ distribution: .PHONY .MAKE check_DESTDIR
 	${MAKEDIRTARGET} ${NETBSDSRCDIR} include _DISTRIB=
 	${MAKEDIRTARGET} ${NETBSDSRCDIR} install _DISTRIB=
 .endif	# !INSTALL_DONE
+	${MAKEDIRTARGET} . install-debugkernels
 	${MAKEDIRTARGET} . install-etc-files
 . if ${MKX11} != "no"
 	${MAKEDIRTARGET} ${NETBSDSRCDIR}/external/mit/xorg distribution
@@ -596,7 +597,8 @@ kern-${configfile}: .PHONY .MAKE
 	${MAKE} -C ${KERNOBJDIR}/${configfile:C/.*\///} distclean
 .endif
 	${MAKE} -C ${KERNOBJDIR}/${configfile:C/.*\///} depend && \
-	${MAKE} -C ${KERNOBJDIR}/${configfile:C/.*\///} 
+	${MAKE} -C ${KERNOBJDIR}/${configfile:C/.*\///} && \
+	${MAKE} -C ${KERNOBJDIR}/${configfile:C/.*\///} debuginstall
 .endfor	# ALL_KERNELS							# }
 .endif	# KERNELS_DONE							# }
 
@@ -693,6 +695,22 @@ releasekern-${configfile}: .PHONY build_
 .endfor
 .endfor	# KERNEL_SETS EXTRA_KERNELS					# }
 
+# install-debugkernels:
+#	Create fake kernel debug files to satisfy the sets requirements
+#	They will be later replaced with the real ones if we are building
+#	kernels. This mess is needed because checkflist runs before the
+#	kernels are built. It should really run before the sets are build.
+install-debugkernels:
+.if ${MKDEBUG:Uno} == "yes"
+.	for k in ${ALL_KERNELS}
+install-debugkernels: ${DESTDIR}${DEBUGDIR}/netbsd-${k}.debug
+		
+${DESTDIR}${DEBUGDIR}/netbsd-${k}.debug:
+	${_MKTARGET_INSTALL}
+	touch ${.TARGET}
+.	endfor
+.endif
+
 # snap_md_post --
 #	Machine dependent distribution media operations.
 #	Overridden by etc.$MACHINE/Makefile.inc

Index: src/sys/conf/Makefile.kern.inc
diff -u src/sys/conf/Makefile.kern.inc:1.285 src/sys/conf/Makefile.kern.inc:1.286
--- src/sys/conf/Makefile.kern.inc:1.285	Mon Dec 20 15:33:20 2021
+++ src/sys/conf/Makefile.kern.inc	Wed Dec 29 17:22:13 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.kern.inc,v 1.285 2021/12/20 20:33:20 christos Exp $
+#	$NetBSD: Makefile.kern.inc,v 1.286 2021/12/29 22:22:13 christos Exp $
 #
 # This file contains common `MI' targets and definitions and it is included
 # at the bottom of each `MD' ${MACHINE}/conf/Makefile.${MACHINE}.
@@ -18,7 +18,7 @@
 # all ports are expected to include bsd.own.mk for toolchain settings
 
 # Default DEBUG to -g if kernel debug info is requested by MKDEBUGKERNEL=yes
-.if defined(MKDEBUGKERNEL) && ${MKDEBUGKERNEL} == "yes"
+.if ${MKDEBUGKERNEL:Uno} == "yes" || ${MKDEBUG:Uno} == "yes"
 DEBUG?=-g
 .endif
 
@@ -243,16 +243,29 @@ LINKFLAGS_DEBUG?=	-X
 
 SYSTEM_LD_TAIL?=@${TOOL_SED} '/const char sccs/!d;s/.*@(.)//;s/" "//;s/\\.*//' vers.c && \
 		${SIZE} $@ && ${SYSTEM_CTFMERGE} && chmod 755 $@
-SYSTEM_LD_TAIL_DEBUG?=&& \
-		echo mv -f $@ $@.gdb && mv -f $@ $@.gdb && \
-		echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb && \
-		${STRIP} ${STRIPFLAGS} -o $@ $@.gdb && \
-		chmod 755 $@ $@.gdb
+
+SYSTEM_LD_TAIL_DEBUG?=&& set -x &&\
+	mv -f $@ $@.gdb && \
+	${OBJCOPY} --only-keep-debug $@.gdb $@-${KERNEL_BUILD}.debug && \
+	${OBJCOPY} --strip-debug -p -R .gnu_debuglink \
+	    --add-gnu-debuglink=$@-${KERNEL_BUILD}.debug $@.gdb $@ && \
+	chmod 755 $@ $@.gdb $@-${KERNEL_BUILD}.debug
+
 LINKFLAGS_NORMAL?=	-S
 STRIPFLAGS?=	-g
 
 DEBUG?=
 .if !empty(DEBUG:M-g*)
+
+# XXX: KERNEL_DIR?
+debuginstall: install-kernel-debug
+.for k in ${KERNELS}
+install-kernel-debug: ${DESTDIR}${DEBUGDIR}/${k}-${KERNEL_BUILD}.debug
+
+${DESTDIR}${DEBUGDIR}/${k}-${KERNEL_BUILD}.debug: ${k}-${KERNEL_BUILD}.debug
+	install -c -o root -g bin -m 444 ${.ALLSRC} ${.TARGET}
+.endfor
+
 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_DEBUG}
 LINKFLAGS+=	${LINKFLAGS_DEBUG}
 EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.gdb@}
@@ -262,6 +275,10 @@ TARGETSFX=	.gdb
 LINKFLAGS+=	${LINKFLAGS_NORMAL}
 .endif
 
+.if !target(debuginstall)
+debuginstall:
+.endif
+
 SYSTEM_LD_HEAD+=	${SYSTEM_LD_HEAD_EXTRA}
 SYSTEM_LD_TAIL_STAGE1=	${SYSTEM_LD_TAIL}
 SYSTEM_LD_TAIL_STAGE2=	${SYSTEM_LD_TAIL}

Reply via email to