Debugging linux kernel with QEMU and GDB gdb.error

Viewed 53

I'm trying to debug Linux Kernel 5.15.47 and a kernel module that I am building. I'm using gdb and unfortunately, everytime I load up the vmlinux file in gdb in preparation for remote debugging using qemu, I am presented with the following error. Note, I tried using GDB on the qemu VM as well (so no remote debugging) and the error still happens there too.

I don't see much discussion around something similar so I figured I would ask if anyone has a work around for this?

(gdb) file vmlinux
Reading symbols from vmlinux...
Traceback (most recent call last):
  File "/home/administrator/Kernels/built/linux-5.15.47/vmlinux-gdb.py", line 34, in <module>
    import linux.proc
  File "/home/administrator/Kernels/built/linux-5.15.47/scripts/gdb/linux/proc.py", line 15, in <module>
    from linux import constants
  File "/home/administrator/Kernels/built/linux-5.15.47/scripts/gdb/linux/constants.py", line 10, in <module>
    LX_hrtimer_resolution = gdb.parse_and_eval("hrtimer_resolution")
gdb.error: 'hrtimer_resolution' has unknown type; cast it to its declared type
(gdb) lx-symbols /home/administrator/<module>/src
loading vmlinux
Traceback (most recent call last):
  File "/home/administrator/Kernels/built/linux-5.15.47/vmlinux-gdb.py", line 34, in <module>
    import linux.proc
  File "/home/administrator/Kernels/built/linux-5.15.47/scripts/gdb/linux/proc.py", line 15, in <module>
    from linux import constants
  File "/home/administrator/Kernels/built/linux-5.15.47/scripts/gdb/linux/constants.py", line 10, in <module>
    LX_hrtimer_resolution = gdb.parse_and_eval("hrtimer_resolution")
gdb.error: 'hrtimer_resolution' has unknown type; cast it to its declared type
No source file named kernel/module.c.

The kernel/module.c file does exist that it is complaining about.

1 Answers

Solved.

Found my problem. Normally gdb should be able to use the 2 separate dwo files that get generated when you use the following flag. However, in my case, it seems like it just was not working with the version of gdb I had or perhaps there was a command I needed to execute inside gdb. I had the correct version of gdb (any version >=7.2) gcc version 11.2.0 (Ubuntu 11.2.0-19ubuntu1).

CONFIG_DEBUG_INFO_SPLIT Split out the debug info for the kernel and kernel modules into separate .dwo files. This significantly reduces the size of the kernel image and kernel modules installed on the device or VM we will be debugging. Note that this option requires a gcc version greater than or equal to version 4.7, as it adds the option -gsplit-dwarfto the compiler flags.

Setting this value to n in your .config file and then rebuilding the kernel fixes the issue I was running into.

Related