I am trying to debug a Linux kernel v5.15 running on a QEMU/KVM virtual machine. My intention is to debug an external kernel module, specifically character device driver that I have written, which is generating a kernel panic. For this purpose, I am running Ubuntu on my virtual machine, so that I can install build tools, compile and install my driver.
However, I am running into an issue when debugging my kernel module. I have built the kernel with the flags indicated in the documentation, run the virtual machine with the -s flag, and used this kernel to boot Ubuntu. I have inserted my module and followed the instructions in this article: 1) checked where it was loaded with cat /sys/module/<my-module>/sections/.text, then 2) I called add-symbol-file <my-module-file> <my-address> to load the module symbols in my gdb session. However, when I add a breakpoint on the last function before the kernel panic and hit continue, the VM freezes and if I run lx-dmesg in gdb I can see that the kernel panic occurred, meaning that the breakpoint was not hit.
I am not entirely sure what information to pass to the add-symbol-file <my-module-file> <my-address> command. The GDB documentation says the following about the argument:
address should be the memory address at which the file has been loaded; GDB cannot figure this out for itself.
I have tried passing the path to the .ko file in my host machine (as the <my-module-file> argument), and the address where the module is loaded in my guest VM (as the <my-address>). Also I tried inserting the module on my host as well and passing its loaded address (on my host machine) as the <my-address> parameter. Both of these attempts resulted on the aforementioned behavior. I am not sure whether it is a problem with the address that I am passing to the command, or a problem with the file path.
I think its important to clarify that I am able to work with breakpoints on regular kernel functions, I am just having issues with breakpoints in my custom external kernel module. Is this the correct way of debugging externally loaded, out-of-tree modules? Should I try a different approach? I haven't been able to find much documentation on these cases. I would greatly appreciate any help or pointers to the right documentation for this.