user1698287
user1698287

Reputation: 101

Debug-info for loadable kernel modules

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?

Upvotes: 10

Views: 14403

Answers (2)

Rahul Ravi
Rahul Ravi

Reputation: 957

#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 

Upvotes: 9

stsquad
stsquad

Reputation: 6032

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

Upvotes: 8

Related Questions