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
  • VMWare
  • VisualKernel
  • A recent version of Linux inside the VM (we recommend Ubuntu, CentOS or Fedora)
  • Ensure that you can access your Linux machine over SSH
  1. Start Visual Studio. Open the New Project dialog and select VisualKernel->Linux Kernel Module Wizard:
  2. On the first wizard page select "Hello, World" module and press "Next":
  3. On the next page select your VM with Linux so that VisualKernel can connect to it over SSH:
  4. 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:
  5. 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:
  6. On the next wizard page you can change the location where VisualKernel will build your kernel module. Press "Next" to accept the default location:
  7. 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:
  8. Press "Finish" to create the project. Press Ctrl-Shift-B to build it:
  9. 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:
  10. 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.