Linux 内核调试:"Python Exception <class 'gdb.error'> There is no member named module_core." 尝试在 gdb 中使用帮助程序脚本时

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

我一直在关注 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下载脚本,并将它们放在相关目录中。

这当然是一个罕见的 edge-case 但我希望有一天这个答案会对某人有所帮助。