Archive for April 29th, 2010

I found a few different pages with information on debugging a Linux kernel with kgdb. There wasn't a single source with all the information I needed to get set up and working though. So here is how I set things up on my Linux host machine to debug a target Linux kernel running in a VirtualBox VM.

Set up the virtual machine

When setting up the VM, add a serial port and set it to use Host Pipe. You can check the box to have VirtualBox create the pipe too. Give a path to the file on the host where you want the pipe. This will become the virtual serial console that gdb connects to on the host machine.

Install VirtualBox with a VM containing the kernel you want to debug. Build the kernel with debug symbols, kgdb support, sysrq keys

Kernel hacking->

[*] Magic SysRq Key

[*] Kernel debugging

[*] Compile the kernel with debug info

[*] KGDB: kernel debugging with remote gdb ->

[*] KGDB: use kgdb over the serial console

Build your kernel and install the modules like you would any other kernel.

Add kgdboc=ttyS0,115200 to the kernel paremeters (ttyS[0-3] depending on which COM port you choose in the VM setup.)

Copy the vmlinux (uncompressed version to the host machine).
Also copy the .ko for the module you want to debug.

Start VM.

Get the target VM ready for debugging

After your module is inserted, you need its .text address so that you can see the source lines in gdb.