python - Linux 内核调试 : "Python Exception <class ' gdb. 错误'> 没有名为 module_core 的成员。"在 gdb 中尝试使用帮助脚本时

标签 python linux-kernel gdb kernel

我一直在关注 this guide使用 gdb 和 VMWare 设置 Linux 内核调试环境。 一切都进行得很顺利,直到那部分:

Connect GDB to the debuggee
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:
(gdb) source home/alambert/kernel/source/linux-4.13.0/debian/build/build-generic/vmlinux-gdb.py
(gdb) lx-symbols

在我的系统上运行它时,出现以下 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.


我的设置

调试器被调试器机器都是VM,被调试器是Ubuntu 16.04,调试器是Ubuntu 18.04。

调试对象:
$ 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

调试器:
$ 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


我一开始以为是 python3/2 兼容性问题,所以我用 python 2.7 重新编译了 gdb,但得到了完全相同的错误。

我还验证了它不是 pwndbg问题 - 我用 vanilla gdb 尝试了这个完全相同的效果。

我已验证 python 帮助程序脚本已在编译调试内核的过程中创建。实际上,我让整个构建过程完成,而不是像指南建议的那样在创建脚本后停止它 - 只是为了确保所有脚本都到位。

我尝试在网上查找错误,但似乎没有任何提及。

有人遇到过这个问题吗?

最佳答案

在深入研究脚本和 Linux 内核的源代码后,我设法解决了这个问题。

问题出在this commit它用 include/linux/module.h header 中的 module_layout 结构替换了 module_core 指针。该更改显然已被引入内核 4.4.0,但直到更高版本才在帮助程序脚本中说明。

这已在稍后处理(特别是 - 在 this commit 中),因此 4.4.0 和 4.6-rc1 之间的所有内核版本都会有此错误。

解决方案是从上述commit 下载脚本。并将它们放在相关目录中。

这当然是一个罕见的边缘案例,但我希望有一天这个答案会对某人有所帮助。

关于python - Linux 内核调试 : "Python Exception <class ' gdb. 错误'> 没有名为 module_core 的成员。"在 gdb 中尝试使用帮助脚本时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52346447/

相关文章:

python - Django 注释

linux - 内核启动错误 - 我可以获取日志吗?

python - 如何获取内部值以用作 gdb pretty-print 的数组?

linux - 如何将一长串参数读入 GDB/DDD

crash - 仅在 GDB 中调用的纯虚方法

python 请求 'certificate verify failed' 获取特定的 SNI 证书

python - 如何在其 if 条件下解决列表理解的当前状态?

python - Python类成员查找的底层机制

linux - 使用自定义 header 编译 Linux 内核模块

linux - rq->cfs.load 值在 Linux 内核中到底代表什么?