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 locate the Linux Kernel Module Wizard:
  2. Enter the name and location for your project:
  3. On the first wizard page select “Hello, World” module and press “Next”:
  4. On the next page select “Setup a new target for running Linux kernels”. If you would like to debug an existing VMWare machine, select “Use an existing virtual machine”: You can also select “Download a ready-to-debug VM image” to download an existing VM together with matching pre-indexed kernel symbols.
  5. Proceed with the default VM configuration:
  6. 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.
  7. On the next wizard page you can change the location where VisualKernel will build your kernel module. Press “Next” to accept the default location:
  8. 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:
  9. Press “Finish” to create the project. Press Ctrl-Shift-B to build it:
  10. 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 and will proceed to loading your kernel module. The breakpoint you set in the init function will trigger:
  11. You can use the Debug->Windows->Live Watch window to view the values of various variables live, without having to stop the debug session: When done debugging, press Shift-F5 to end the debug session.

You can read more about other debugging methods on this page.