How to build debug-info for loadable linux kernel modules (like that of kernel in vmlinux-uname -r
.debug?)Does it is generated while we build a module, if so where it will be located?
upon the kernel booted and the prompt appear to enable debug level messages by executing either dmesg -n 8 or echo 8 > /proc/sys/kernel/printk.
modinfo command in Linux system is used to display the information about a Linux Kernel module. This command extracts the information from the Linux kernel modules given on the command line.
In computing, a loadable kernel module (LKM) is an object file that contains code to extend the running kernel, or so-called base kernel, of an operating system. LKMs are typically used to add support for new hardware (as device drivers) and/or filesystems, or for adding system calls.
Assuming you have built the kernel with CONFIG_DEBUG_INFO the debug symbols should already be in the .ko file for the module in question. However as the module can be dynamically loaded at any address you need to give gdb a bit more information.
cd /sys/module/${MODNAME}/sections
cat .text .data .bss
You can then use this information when telling GDB about the modules:
(gdb) add-symbol-file ${MODPATH} ${TEXT} -s .data ${DATA} -s .bss ${BSS}
There is a tutorial that walks you through this on the Linux Foundation website. Kernel and Module Debugging with GDB
#Modify your Makefile like this then build it
#cat /sys/module/mydriver/sections/.text -> find the address
#Then run like add-symbol-file drivers/mydrivers/mydriver.o address from above #line
obj-m += module_name.o
MY_CFLAGS += -g -DDEBUG
ccflags-y += ${MY_CFLAGS}
CC += ${MY_CFLAGS}
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
debug:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
EXTRA_CFLAGS="$(MY_CFLAGS)"
clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With