addr2line on kernel module

匿名 (未验证) 提交于 2019-12-03 01:49:02

问题:

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. And I got some warning from that:

[11839.429168] slab error in verify_redzone_free(): cache `size-64': memory outside object was overwritten [11839.438659] [] (unwind_backtrace+0x0/0x164) from [] (kfree+0x278/0x4d8) [11839.447357] [] (kfree+0x278/0x4d8) from [] (some_function+0x18/0x1c [my_module]) [11839.457214] [] (some_function+0x18/0x1c [my_module]) from [] (some_function+0x174/0x718 [my_module]) [11839.470184] [] (some_function+0x174/0x718 [my_module]) from [] (some_function+0x12c/0x16c [my_module]) [11839.483917] [] (some_function+0x12c/0x16c [my_module]) from [] (some_function+0x8/0x10 [my_module]) [11839.496368] [] (some_function+0x8/0x10 [my_module]) from [] (some_function+0x358/0x6d4 [my_module]) [11839.507476] [] (some_function+0x358/0x6d4 [my_module]) from [] (worker_thread+0x1e8/0x284) [11839.517211] [] (worker_thread+0x1e8/0x284) from [] (kthread+0x78/0x80) [11839.525543] [] (kthread+0x78/0x80) from [] (kernel_thread_exit+0x0/0x8) 

There is no problem to translate addresses which points to kernel:

$ addr2line -f -e vmlinux.kmeml c0116ca0 verify_redzone_free /[...]/kernel/mm/slab.c:2922 

But I can't do that if addresses are from my_module:

$ addr2line -f -e vmlinux.kmeml bf0a56b8 ?? ??:0 

I was also trying with module file:

$ addr2line -f -e my_module.ko bf0a56b8 ?? ??:0 

How can I translate this addresses to files and line numbers?

回答1:

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  -j 

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 .



回答2:

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



回答3:

Maybe you should use -g parameter to compile the module.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!