addr2line on kernel module

后端 未结 3 1534
梦毁少年i
梦毁少年i 2020-12-02 13:46

I\'m trying to debug kernel module. I suspect to have there some memory leaks. To check it I have prepared build with enabled Memory leak debugging for kernel and modules. A

相关标签:
3条回答
  • 2020-12-02 13:58

    I suppose the module is built with debug info included. If so, you can use gdb or objdump to find out which source file and line each address belongs to. Something like this:

    $ gdb "$(modinfo -n my_module)"
    (gdb) list *(some_function+0x12c)
    

    Gdb will now tell the name of the source file and the line in it.

    You can also do a similar thing with objdump but it is a bit more difficult. First, disassemble the module:

    objdump -dSlr my_module.ko > my_module.disasm
    

    When called with -S option, objdump will include the source lines in the resulting listing where appropriate.

    You can now scroll the listing down to the code of some_function, find the instruction at offset 0x12c from the beginning of the function. The source line will be indicated above it.

    EDIT:

    After many experiments, I found that although addr2line can indeed be used for kernel modules, eu-addr2line (a similar tool from elfutils) seems to be more reliable. That is, sometimes addr2line output incorrect source lines but eu-add2line did things right.

    To use eu-addr2line, one may need to install libdw and libebl libraries if they are not already installed along with elfutils.

    The usage is similar to that of addr2line:

    eu-addr2line -f -e <path_to_the_module> -j <section_name> <offset_in_section>
    

    If the debug information for a kernel module is stored in separate file (this is often the case for the kernels provided by the major Linux distros), the path to that file should be used as <path_to_the_module>.

    0 讨论(0)
  • 2020-12-02 13:59

    You indeed need to run addr2line on your kernel module and not kernel but there is a twist -

    the kernel module file uses relative addresses, the crash address you have is actually composed of:

    offset inside module + module load address is memory.

    So what you need to do is find the kernel moduel load address is memory first by doing cat /proc/modules, finding to what module that address belongs to, in case you don't know, subtract the module load address from the crash address and feed that to addr2line

    good luck

    0 讨论(0)
  • Maybe you should use -g parameter to compile the module.

    0 讨论(0)
提交回复
热议问题