0

i'm currently working on an ubuntu 18.0.4.5 machine and i've been trying to figure out the whole kernel debugging process. I've stumbled upon the need to auto run GDB scripts along with the vmlinux file, particulary the script residing under /usr/src/linux../scripts/gdb/vmlinux-gdb.py. I made sure the script ran on initialization with the vmlinux file and had the following error

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'

After this error occured I checked the /usr/share/gdb/auto-load/gdb/linux directory to look for the missing file and only found 2 related files:

constants.py.in
Makefile

Inside the constants.py.in file was C code mixed with python and was commented that the build will take care of that. The exact Makefile and constants.py.in files can be found here for reference: 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

Trying to build for the first time resulted in this:

make: *** No rule to make target '/constants.py.in', needed by '/constants.py'.  Stop.

After some trial and error (i'm not experienced in Makefile language) I copied constants.py.in to the / directory and tried to build again and recieved the following error:

make: *** No rule to make target 'FORCE', needed by '/constants.py'.  Stop.

I don't understand what does that FORCE is, looks like some kind of makefile configuration but i can't find a reasonable explantion or patch, the same errors occur when trying to build anything under /usr/src/linux-.../

trying to understand how to fix the build process and eventually create the correct constants.py that is hopefully the last piece to making the vmlinux-gdb.py work during debugging

  • What directions are you following? Is there a configure script or README file in that directory? – stark Jun 14 '21 at 13:21
  • There is none, the content of the directory is used as a python package used to import the *.py files needed but within the directory is the Makefile file and the constants.py.in, currently working on figuring out what FORCE means and if its written correctly – sharlit mals Jun 14 '21 at 13:27
  • I've been following the `vmlinux-gdb.py` errors and understood that the constants.py.in needs to be built into a `*.py` file in order for the gdb script to work – sharlit mals Jun 14 '21 at 13:30
  • The reason for the error is that the variable `obj` in the path `$(obj)/constants.py` is not set (expands to the empty string). That's why it seems to be looking at `/constants.py`. This makefile is not intended to be run directly, by itself. It's intended to be run as a component of the Linux kernel build system. That build system will set the variables `obj` and `src` and other important things, then include this makefile. I don't know enough about this project to help more than that. – MadScientist Jun 14 '21 at 13:46
  • I see, thank you very much! now i'm just wondering now how do i get my kernel to build the script for me – sharlit mals Jun 14 '21 at 14:02

1 Answers1

1

Running make scripts_gdb at the top level of the source tree will run through a few other Makefiles and eventually build constants.py. You'll see some make chatter like the following:

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

After this completes,vmlinux-gdb.py will be usable.

Mark Plotnick
  • 9,598
  • 1
  • 24
  • 40