# Linux Kernel Module Cheat

##### 17.6.1.1. Kernel module stack trace to source line

The log shows which module each symbol belongs to if any, e.g.:

    myinit+0x1d/0x20 [panic]

says that the function `myinit` is in the module `panic`.

To find the line that panicked, do:

    ./run-gdb

and then:

    info line *(myinit+0x1d)

which gives us the correct line:

    Line 7 of "/root/linux-kernel-module-cheat/out/kernel_modules/x86_64/kernel_modules/panic.c" starts at address 0xbf00001c <myinit+28> and ends at 0xbf00002c <myexit>.

as explained at: https://stackoverflow.com/questions/8545931/using-gdb-to-convert-addresses-to-lines/27576029#27576029

The exact same thing can be done post mortem with:

    ./run-toolchain gdb -- \
      -batch \
      -ex 'info line *(myinit+0x1d)' \
      "$(./getvar kernel_modules_build_subdir)/panic.ko" \
    ;

Related:

- https://stackoverflow.com/questions/6151538/addr2line-on-kernel-module

- https://stackoverflow.com/questions/13468286/how-to-read-understand-analyze-and-debug-a-linux-kernel-panic