Debugging Linux Kernel with Visual Studio and VMWare
This tutorial shows how to debug a Linux kernel module using Visual Studio and the VMWare GDB stub. This method is preferred over KGDB due to higher speed and reliability. Before you begin please install the following tools:
- Visual Studio
- A recent version of Linux inside the VM (we recommend Ubuntu, CentOS or Fedora)
- Ensure that you can access your Linux machine over SSH
- Start Visual Studio. Open the New Project dialog and select VisualKernel->Linux Kernel Module Wizard:
- On the first wizard page select "Hello, World" module and press "Next":
- On the next page select your VM with Linux so that VisualKernel can connect to it over SSH:
- Once you press 'Next' VisualKernel will configure the machine for building and debugging your kernel module. This will involve automatically installing the necessary packages and downloading the sources/symbols to your Windows machine:
- Once the machine is ready to build and debug your kernel module, VisualKernel will test it by building a basic module and verifying that the build succeeds:
- On the next wizard page you can change the location where VisualKernel will build your kernel module. Press "Next" to accept the default location:
- On the last wizard page select "Debug a Virtual Machine", then select "VMWare" and specify the path to the .vmx file of the machine you are going to debug. You can use the button to the right from the text box to browse through a list of VMWare virtual machines registered for the current user:
- Press "Finish" to create the project. Press Ctrl-Shift-B to build it:
- Set a breakpoint in the init function and press F5 to start debugging. VisualKernel will automatically edit the .vmx file to enable the undocumented VMWare GDB stub:
- VisualKernel will then automatically load your driver, load the symbols for it and stop when your breakpoint is hit:When done debugging, press Shift-F5 to end the debug session.
You can read more about various debugging techniques in our KGDB debugging tutorial.