简体   繁体   English

调试正在加载的内核模块

[英]Debug a kernel module being loaded

I am wondering if it is possible to debug a kernel module being loaded.我想知道是否可以调试正在加载的内核模块。

Note I am currently trying this on Linux 2.0.18.注意我目前正在 Linux 2.0.18 上尝试这个。 I've followed this great tutorial .我遵循了这个很棒的教程 Since the kernel config options CONFIG_PROC_KCORE and CONFIG_DEBUG_INFO don't seem to be available in this kernel version, I've added -g -gdwarf to CFLAGS in the Makefile, recompiled the kernel and modules and rebooted.由于内核配置选项CONFIG_PROC_KCORECONFIG_DEBUG_INFO在此内核版本中似乎不可用,因此我在 Makefile -g -gdwarf添加到CFLAGS ,重新编译内核和模块并重新启动。

Then I can run gdb vmlinux /proc/kcore and then p jiffies which gives me $1 = 1470917 .然后我可以运行gdb vmlinux /proc/kcore然后p jiffies这给了我$1 = 1470917

That's where I am starting to get lost, also because there seems to be no /sys/module/gdb1/sections on that kernel version, as it seems required to debug a loaded module.这就是我开始迷失的地方,也是因为该内核版本上似乎没有/sys/module/gdb1/sections ,因为它似乎需要调试加载的模块。

So I just tried to load the symbols of the module "ne":所以我只是尝试加载模块“ne”的符号:

(gdb) symbol-file modules/ne.o

which loads the symbols after confirming with "y".用“y”确认后加载符号。 Then I set a breakpoint:然后我设置了一个断点:

(gdb) break ne.c:148
Breakpoint 1 at 0xa: file ne.c, line 148.

Now I'd like to do modprobe ne and reach the breakpoint, but I think I am completely on the wrong path.现在我想做modprobe ne并到达断点,但我认为我完全走错了路。

Is it possible at all?有可能吗? Even if it is not on such an old kernel, I'd be happy to know how to debug a module being loaded on a current kernel as well.即使它不在这么旧的内核上,我也很高兴知道如何调试当前内核上加载的模块。

The very document you are linking states you can't use breakpoints when debugging.您正在链接的文档说明您在调试时不能使用断点。 Otherwise you could deadlock the kernel by accident (eg what if the thread blocking on a breakpoint has a spinlock the debugger needs to take to inspect the thread?), also there is no stable state as the kernel needs to keep running.否则你可能会意外死锁内核(例如,如果在断点上阻塞的线程有一个自旋锁,调试器需要用来检查线程呢?),也没有稳定状态,因为内核需要继续运行。

I can only speculate why this method was described.我只能推测为什么描述这种方法。 My guess is years ago there was not much choice when few people had hardware supporting virtualisation or multiple machines to debug remotely.我的猜测是几年前,当很少有人拥有支持虚拟化的硬件或多台机器进行远程调试时,没有太多选择。

The way to go about is to use something like qemu and attach to the vm from the host.解决的方法是使用 qemu 之类的东西并从主机附加到 vm。 http://wiki.osdev.org/Kernel_Debugging http://wiki.osdev.org/Kernel_Debugging

Also, for post mortem debugging you can use https://people.redhat.com/anderson/crash_whitepaper/此外,对于事后调试,您可以使用https://people.redhat.com/anderson/crash_whitepaper/

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

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