Debug-info for loadable kernel modules

How to create debug-info for loadable Linux kernel modules (for example, the kernel in vmlinux- uname -r .debug?) Is it created when we create the module, if so, where will it be?

+6
source share
2 answers

Assuming that you built the kernel with CONFIG_DEBUG_INFO, the debug symbols should already be in the .ko file for the module in question. However, since the module can be dynamically loaded at any address, you need to provide gdb with a bit more information.

 cd /sys/module/${MODNAME}/sections cat .text .data .bss 

You can then use this information when reporting GDB modules:

 (gdb) add-symbol-file ${MODPATH} ${TEXT} -s .data ${DATA} -s .bss ${BSS} 

There is a tutorial in which you will learn about this on the Linux Foundation website. Debugging the kernel and module using GDB

+5
source
 #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 
+4
source

Source: https://habr.com/ru/post/926236/


All Articles