简体   繁体   English

如何在Linux内核模块`init()`中调试问题?

[英]How to debug problems in Linux kernel module `init()`?

I am using remote (k)gdb to debug a problem in a module that causes a panic when loaded eg when init() is called. 我正在使用远程(k)gdb来调试模块中的问题,该问题在加载时会引起混乱,例如在调用init()时。

The stack trace just shows that do_one_initcall(mod->init) causes the crash. 堆栈跟踪只显示do_one_initcall(mod->init)导致崩溃。 In order to get the symbol file loaded in the gdb, I need to get the address of the module text section, and to get that I need to get the module loaded. 为了获得在gdb中加载的符号文件,我需要获取模块文本部分的地址,并获得我需要加载模块。

Because the insmod in busybox (1.16.1) doesn't support -m so I'm stuck to grep modulename /proc/modules + adding the offset from nm to figure out the address. 因为busybox(1.16.1)中的insmod不支持-m所以我坚持使用grep modulename /proc/modules +从nm添加偏移来计算地址。

So I'm facing a sort a of a chicken and an egg problem here - to be able to debug the module loading, I need to get the module loaded - but in order to get the module loaded, I need to debug the problem... 所以我在这里面临一个鸡和蛋的问题 - 为了能够调试模块加载,我需要加载模块 - 但是为了加载模块,我需要调试问题。 ..

So I am currently thinking about two options - is there a way to get the address information either: 所以我目前正在考虑两种选择 - 是否有办法获取地址信息:

  1. by printk() in the module init code 通过模块初始化代码中的printk()
  2. by printk() somewhere in the kernel code 通过printk()在内核代码中的某个地方

all this prior to calling the mod->init() - so I could place a breakpoint there, load the symbol file, hit c and see it crash and burn... 所有这一切都在调用mod->init() - 所以我可以在那里放置一个断点,加载符号文件,点击c然后看到它崩溃并烧掉......

Can you build your code into the kernel rather than as a module? 您可以将代码构建到内核而不是模块中吗? That might simplify debugging the init() call. 这可能会简化调试init()调用。

You could also set a breakpoint at do_one_initcall() and look at the address of mod->init to get the load address. 您还可以在do_one_initcall()设置断点,并查看do_one_initcall() mod->init的地址以获取加载地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM