0

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.

7
  • Does vmlinux have debug-symbols? I.e. does file vmlinux say that the file is "stripped" or "not stripped"? Commented Sep 19, 2022 at 22:41
  • Yes, vmlinux should have the debug symbols. I enabled them when building the kernel. But I can't verify in gdb. Every time I do file vmlinux, I get the same traceback from Python as in my post. i.e. gdb.error: 'hrtimer_resolution' has unknown type; cast it to its declared type Commented Sep 20, 2022 at 12:05
  • I followed these 2 guides when building my kernel for debugging... 01.org/linuxgraphics/gfx-docs/drm/dev-tools/… and starlab.io/blog/using-gdb-to-debug-the-linux-kernel Commented Sep 20, 2022 at 12:08
  • Oh sorry, I should have been more precise: What is the output of file vmlinux when run from your shell, not from within GDB. Commented Sep 20, 2022 at 14:14
  • 1
    Ah, sorry about that. Here is the output of file vmlinux. It isn't stripped vmlinux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=b8ab6b15dc6d013b1c6b7f72d632a576c3645675, with debug_info, not stripped Commented Sep 20, 2022 at 14:17

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.