Index: build.sh =================================================================== RCS file: /cvsroot/src/build.sh,v retrieving revision 1.359 diff -u -p -u -r1.359 build.sh --- build.sh 4 Oct 2021 21:02:40 -0000 1.359 +++ build.sh 29 Dec 2021 22:16:32 -0000 @@ -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: distrib/sets/sets.subr =================================================================== RCS file: /cvsroot/src/distrib/sets/sets.subr,v retrieving revision 1.197 diff -u -p -u -r1.197 sets.subr --- distrib/sets/sets.subr 25 Sep 2021 21:26:03 -0000 1.197 +++ distrib/sets/sets.subr 29 Dec 2021 22:16:32 -0000 @@ -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: distrib/sets/lists/debug/mi =================================================================== RCS file: /cvsroot/src/distrib/sets/lists/debug/mi,v retrieving revision 1.369 diff -u -p -u -r1.369 mi --- distrib/sets/lists/debug/mi 7 Dec 2021 17:39:53 -0000 1.369 +++ distrib/sets/lists/debug/mi 29 Dec 2021 22:16:32 -0000 @@ -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: etc/Makefile =================================================================== RCS file: /cvsroot/src/etc/Makefile,v retrieving revision 1.455 diff -u -p -u -r1.455 Makefile --- etc/Makefile 23 Dec 2021 14:50:59 -0000 1.455 +++ etc/Makefile 29 Dec 2021 22:16:32 -0000 @@ -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: sys/conf/Makefile.kern.inc =================================================================== RCS file: /cvsroot/src/sys/conf/Makefile.kern.inc,v retrieving revision 1.285 diff -u -p -u -r1.285 Makefile.kern.inc --- sys/conf/Makefile.kern.inc 20 Dec 2021 20:33:20 -0000 1.285 +++ sys/conf/Makefile.kern.inc 29 Dec 2021 22:16:32 -0000 @@ -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}