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?
Add a comment
|
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
-
Can I set breakpoints and watchpoints? in that tutorial they have mentioned that we can't do more advanced such as setting breakpoints etc..?? and all these can be done in single system right? or else I need to PCs? – BHANUMATHI H M Dec 18 '17 at 11:45
-
You are not going to be able to set breakpoints on your host kernel while on the host. Either debug a kernel in a VM or setup the serial debug to another machine so you can stop/start the kernel as you debug. – stsquad Dec 20 '17 at 8:21
#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
-
As per this link we need not to add the -g flags in my module's make file right ...?? linux.com/learn/… – BHANUMATHI H M Dec 26 '17 at 6:49