Tuesday 25 July 2017

Linux kernel module debugging using gdb

Choose appropriate function from stack which has failed. Suppose
function failed is "function_foo()" then you will have entry like

kernel: [<ffffffff814ec2ba>] ? function_foo+198

in stack trace. Pass corresponding debug .ko to gdb 
[root@pritam-pc]# gdb mymodule.ko.debug

(gdb) l* function_foo+198

This will give you .c file which caused failure with line number.
Suppose you got details like .c file is foo.c and line number is 122
then you can do more debugging with following command

(gdb) info line  foo.c:122