Installing Development builds of VirtualBox with GDB Support
The recent versions of VirtualBox support debugging the target directly (i.e. without the use of kgdboe or kgdboe) with a built-in GDB stub.
However, this functionality is only available in the development snapshots of VirtualBox and requires disabling the Hyper-V platform on the host.
In order to debug a Linux kernel running inside a VirtualBox VM, follow the steps below:
- Download and install the latest development snapshot of VirtualBox (not a test build). You can also get the latest version successfully tested with VisualKernel here.
- When the VM is stopped, run the following commands:
123vboxmanage [.vbox file path] setextradata VBoxInternal/DBGC/gdb/Provider TCPvboxmanage [.vbox file path] setextradata VBoxInternal/DBGC/gdb/StubType Gdbvboxmanage [.vbox file path] setextradata VBoxInternal/DBGC/gdb/Port 1234
Replace 1234 with the port number on the host that you would like to use for debugging.
- Start the VM. Once it loads, start a gdb executable on the host and run the following command:
1target remote :1234
You will now be able to debug the target kernel using VirtualBox.
The VirtualBox GDB stub has the following known limitations:
- It is only supported in the development snapshots of VirtualBox. Stable releases do not include it.
- It does not work when the host has Hyper-V virtualization enabled. If you encounter strange debugging behavior, make sure Hyper-V is disabled:
- The VirtualBox GDB stub has higher latency than the VMWare or QEMU gdb stubs. Expect a ~1 second delay after hitting each breakpoint. If the overall debugging performance is too slow, try disabling the printk() hook in VisualKernel settings, as it involves setting a breakpoint.
Integration with Visual Studio
See this tutorial for detailed steps on debugging a VirtualBox guest kernel with Visual Studio.