Solved How to compile kernel modules with debug symbols

I just started to make a kernel module.

With a Makefile like this
Code:
KMOD=   hello
SRCS=   hello.c

.include <bsd.kmod.mk>
Type `make` and successfully compile. But no debug symbols.

I followed `bsd.kmod.mk` and found `sys/conf/kmod.mk` in which dozens of variables help to control the compiling process.
But did not find one that help to add debug symbols. Like CFLAGS?

Thanks.
 
Thanks. I tried it, but not work. No `-g` shown in the output of `make`.
Code:
USES=   kmod:debug
KMOD=   hello
SRCS=   hello.c

.include <bsd.kmod.mk>

Code:
root@freebsd:~/trymodules # touch hello.c; make
Warning: Object directory not changed from original /root/trymodules
cc  -O2 -pipe  -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc   -include /root/trymodules/opt_global.h -I. -I/usr/freebsd-src-stable-14/sys -I/usr/freebsd-src-stable-14/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/freebsd-src-stable-14/sys/amd64/include -fdebug-prefix-map=./x86=/usr/freebsd-src-stable-14/sys/x86/include -fdebug-prefix-map=./i386=/usr/freebsd-src-stable-14/sys/i386/include     -MD  -MF.depend.hello.o -MThello.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error=tautological-compare -Wno-error=empty-body -Wno-error=parentheses-equality -Wno-error=unused-function -Wno-error=pointer-sign -Wno-error=shift-negative-value -Wno-address-of-packed-member -Wno-format-zero-length   -mno-aes -mno-avx  -std=gnu99 -c hello.c -o hello.o
ld -m elf_x86_64_fbsd -warn-common --build-id=sha1 -T /usr/freebsd-src-stable-14/sys/conf/ldscript.kmod.amd64 -r  -o hello.ko hello.o
:> export_syms
awk -f /usr/freebsd-src-stable-14/sys/conf/kmod_syms.awk hello.ko  export_syms | xargs -J% objcopy % hello.ko
objcopy --strip-debug hello.ko
 
Isn't debug-ness inherited from the kernel config file?
No, the compiling flags from the output did not include `-g`. And `readelf -S hello.o` reveals no debug section.
Code:
root@freebsd:~/trymodules # readelf -S hello.o | grep debug
root@freebsd:~/trymodules #

I use `freebsd-src-stable-14`
 
Back
Top