首页 > 解决方案 > Makefile:没有规则可以使“/constants.py”需要目标“/constants.py.in”。停止

问题描述

我目前正在使用 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 目录以查找丢失的文件,仅找到 2 个相关文件:

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在调试期间完成工作的最后一部分

标签: linuxmakefilegdbgnu-makegdb-python

解决方案


make scripts_gdb在源代码树的顶层运行将运行几个其他 Makefile 并最终构建constants.py. 你会看到一些 make chatter 像下面这样:

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就可以使用了。


推荐阅读