简体   繁体   English

可加载内核模块的调试信息

[英]Debug-info for loadable kernel modules

如何为可加载的Linux内核模块(比如vmlinux- uname -r .debug中的内核模块)构建调试信息?是否在我们构建模块时生成它,如果是这样的话它将位于何处?

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. 假设您使用CONFIG_DEBUG_INFO构建了内核,则调试符号应该已经存在于相关模块的.ko文件中。 However as the module can be dynamically loaded at any address you need to give gdb a bit more information. 但是,由于模块可以在任何地址动态加载,因此需要为gdb提供更多信息。

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

You can then use this information when telling GDB about the modules: 然后,在告诉GDB有关模块时,您可以使用此信息:

(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. 有一个教程可以在Linux Foundation网站上引导您完成此操作。 Kernel and Module Debugging with GDB 使用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 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM