我目前在一台ubuntu 18.0.4.5机器上工作,我一直在尝试弄清楚整个内核调试过程。我偶然发现需要自动运行GDB脚本和vmlinux文件,特别是/usr/src/linux../ scripts /gdb/vmlinux-gdb.py下的脚本。我确保该脚本使用vmlinux文件在初始化时运行,并出现以下错误
gdb vmlinux
File "/usr/src/linux-hwe-5.4-headers-5.4.0-42/scripts/gdb/vmlinux-gdb.py", line 34, in <module>
import linux.proc
File "/usr/share/gdb/auto-load/gdb/linux/proc.py", line 15, in <module>
from linux import constants
ImportError: cannot import name 'constants'出现此错误后,我检查了/usr/share/gdb/auto-load/gdb/linux目录以查找丢失的文件,但只找到了两个相关文件:
constants.py.in
Makefile在constants.py.in文件中是混合了python的C代码,并被注释为构建将负责这一点。可以在以下位置找到确切的Makefile和constants.py.in文件以供参考:https://elixir.bootlin.com/linux/v5.4/source/scripts/gdb/linux/Makefile https://elixir.bootlin.com/linux/v5.4/source/scripts/gdb/linux/constants.py.in
第一次尝试构建的结果是:
make: *** No rule to make target '/constants.py.in', needed by '/constants.py'. Stop.经过反复试验(我没有使用Makefile语言的经验),我将constants.py.in复制到/目录,并再次尝试构建,收到以下错误:
make: *** No rule to make target 'FORCE', needed by '/constants.py'. Stop.我不明白那个FORCE是做什么的,看起来像是一种makefile配置,但我找不到合理的解释或补丁,当我试图在/usr/src/linux-.../下构建任何东西时,同样的错误也会发生
尝试了解如何修复构建过程并最终创建正确的constants.py,希望这是在调试期间使vmlinux-gdb.py正常工作的最后一步
发布于 2021-06-16 00:07:28
在源代码树的顶层运行make scripts_gdb将遍历其他一些Makefiles,并最终构建constants.py。你会看到一些类似下面这样的对话:
builder@localhost:/tmp/linux/linux-5.4.125$ make V=1 scripts_gdb
make -f ./scripts/Makefile.build obj=scripts/basic
...
make -f ./scripts/Makefile.build obj=scripts/gdb
make -f ./scripts/Makefile.build obj=scripts/gdb/linux
gcc -E -E -x c -P -Wp,-MD,scripts/gdb/linux/.constants.py.d ... \
scripts/gdb/linux/constants.py.in > scripts/gdb/linux/constants.py ;\
sed -i '1,/<!-- end-c-headers -->/d;' scripts/gdb/linux/constants.py
ln -fsn /tmp/linux/linux-5.4.125/scripts/gdb/vmlinux-gdb.py完成此操作后,vmlinux-gdb.py将可用。
https://stackoverflow.com/questions/67969592
复制相似问题