Debugging kernel modules with KGDB
To debug a kernel module under KGDB, pretty much everything remains the same as with debugging in-tree kernel code with GDB. The main difference is this: GDB can't automatically see where the target kernel module's ELF code and data sections are in (virtual) memory, as modules can be loaded and unloaded on demand – we need to tell it. Let's get to how exactly we do so.
Informing the GDB client about the target module's locations in memory
The kernel makes the ELF section information of every kernel module available under sysfs here: /sys/module/<module-name>/sections/.*
. Do an ls -a
on this directory to see the so-called hidden files as well. For example, and assuming that the usbhid
kernel module is loaded up (you can run lsmod
to check, of course), we can see its sections (output truncated) with the following:
ls -a /sys/module/usbhid/sections/ ./ [.....