Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug-info for loadable kernel modules

Tags:

linux-kernel

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?

like image 599
user1698287 Avatar asked Sep 25 '12 19:09

user1698287


People also ask

How do I enable debug logs in kernel?

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.

What command is used to check information of kernel module?

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.

How do loadable kernel modules work?

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.


2 Answers

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

like image 111
stsquad Avatar answered Oct 03 '22 15:10

stsquad


#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 
like image 31
Rahul Ravi Avatar answered Oct 03 '22 15:10

Rahul Ravi