简体   繁体   English

Linux内核调试:“ Python异常 <class 'gdb.error'> 尝试在gdb中使用帮助程序脚本时,没有名为module_core的成员。

[英]Linux Kernel Debugging: “Python Exception <class 'gdb.error'> There is no member named module_core.” when trying to use helper scripts in gdb

I've been following this guide to set up a Linux kernel debugging environment with gdb and VMWare. 我一直遵循本指南来使用gdb和VMWare设置Linux内核调试环境。 Everything went on smoothly until that part: 一切进展顺利,直到那一部分:

Connect GDB to the debuggee 将GDB连接到调试对象
We won't be able to see symbols from loaded kernel modules yet. 我们还无法看到来自已加载内核模块的符号。 We'll load the helper script and then run lx-symbols, which will probe the loaded modules and configure GDB appropriately: 我们将加载帮助程序脚本,然后运行lx-symbols,它将探测已加载的模块并适当地配置GDB:
(gdb) source home/alambert/kernel/source/linux-4.13.0/debian/build/build-generic/vmlinux-gdb.py
(gdb) lx-symbols

When running this on my system I get the following python error: 在系统上运行此命令时,出现以下python错误:
pwndbg> source /home/user/kernel/source/linux-4.4.0/debian/build/build-generic/vmlinux-gdb.py pwndbg> lx-symbols loading vmlinux Python Exception <class 'gdb.error'> There is no member named module_core.: Error occurred in Python command: There is no member named module_core.


My setup 我的设定

Both the debugger and debugee machines are VMs, the debugee is a Ubuntu 16.04 and the debugger is a Ubuntu 18.04. 无论是调试器被调试机器的虚拟机,被调试是Ubuntu的16.04和调试器是一个Ubuntu的18.04。

Debugee: 被调试者:
$ cat /proc/version Linux version 4.4.0-134-generic (buildd@lgw01-amd64-033) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10) ) #160-Ubuntu SMP Wed Aug 15 14:58:00 UTC 2018

Debugger: 调试器:
$ cat /proc/version Linux version 4.15.0-34-generic (buildd@lgw01-amd64-047) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #37-Ubuntu SMP Mon Aug 27 15:21:48 UTC 2018 $ gdb --version GNU gdb (GDB) 8.2 Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. $ python -V Python 2.7.15rc1


I first thought it was a python3/2 compatibility issue so I recompiled gdb with python 2.7, but got the exact same error. 我首先认为这是python3 / 2兼容性问题,所以我用python 2.7重新编译了gdb,但得到了完全相同的错误。

I have also verified it is not a pwndbg problem - I tried this with vanilla gdb to the exact same effect. 我还验证了这不是pwndbg问题-我尝试使用香草gdb达到完全相同的效果。

I have verified that the python helper scripts had been created in the process of compiling the debugee kernel. 我已经验证了python帮助程序脚本是在编译被调试程序内核的过程中创建的。 I actually let the whole build process complete rather than stopping it once the scripts were created like the guide suggests - just to make sure all of them are in place. 实际上,我让整个构建过程完成了,而不是像指南所建议的那样立即停止了脚本-只是确保所有这些都就位。

I have tried looking for the error online but there does not seem to be any mention of it. 我尝试过在线查找错误,但似乎没有任何提及。

Did anybody ever encounter that problem? 有人遇到过这个问题吗?

After some digging in the sources of the scripts and the linux kernel, I have managed to fix the issue. 在深入研究了脚本和linux内核的源代码之后,我设法解决了这个问题。

The problem lies in this commit which replaced the module_core pointer with a module_layout struct in the include/linux/module.h header. 问题就出在此提交它取代了module_core指针与module_layout在struct include/linux/module.h报头。 The change had been apparently pulled into kernel 4.4.0 but was not accounted for in the helper scripts until a later version. 显然,此更改已引入内核4.4.0,但直到更高版本才在帮助程序脚本中进行说明。

This had been dealt with a while later (specifically - in this commit ), so all kernel versions between 4.4.0 and 4.6-rc1 will have this bug. 稍后(特别是在此commit中对此进行了处理 ,因此所有4.4.0到4.6-rc1之间的内核版本都将出现此错误。

The solution is to download the scripts from the aforementioned commit and place them in the relevant directories. 解决方案是从上述提交中下载脚本并将它们放置在相关目录中。

This is certainly a rare edge-case but I hope this answer will be helpful to somebody someday. 这当然是一种罕见的极端情况,但是我希望这个答案有一天能对某人有所帮助。

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

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