Debugging Linux Kernel over network

This tutorial shows how to create and debug a basic Linux kernel module using Visual Studio and VisualKernel over a network connection. Before you begin please do the following:

  • Install Visual Studio
  • Install VisualKernel
  • Get a recent version of Linux (we recommend Ubuntu, CentOS or Fedora)
  • Ensure that your Linux and Windows machine are on the same subnet
  1. Start Visual Studio. Select the Linux Kernel Module wizard in the "New Project" window:
  2. Select the default kernel module template:
  3. On the next page select the computer you are targeting. If it is not listed, :
  4. When you press "next", VisualKernel will automatically detect the kernel version used on the target machine and will download the sources and symbols for it so that you can debug it easily:
  5. Select default source settings on the next page. VisualKernel will keep the source files on the Windows machine and transfer them to the Linux side to do the build:
  6. On the last wizard page select the debugger connection type. In this tutorial we will use KGDB-over-Ethernet to debug our kernel. Proceed with the default settings:
  7. When you press "Finish", VisualKernel will generate a basic kernel module project in Visual Studio. Build it by pressing Ctrl-Shift-B:
  8. Set a breakpoint in the init() function and press F5 to start debugging. As the Linux kernel does not include built-in support for debugging over network, VisualKernel will build and install a module that enables it:
  9. Once the module has been installed, the debugging will begin and your breakpoint will be hit:
  10. You can debug your module as usual: step, set breakpoints, inspect variables. As VisualKernel has downloaded the symbols and sources for your kernel, you will be able to debug the kernel itself as well. E.g. use the call stack to see the Linux code involved in loading your module:
  11. When done debugging, press Shift-F5. You can always change various settings via the VisualKernel Project Properties window:Note that by default network debugging disables all CPU cores except #0. This reduces the complexity of the network synchronization code needed to support kernel debugging and makes your debugging session more stable. You can enable the multi-core support, however if your network card driver uses some additional resources that are not managed by KGDBoE, your session may hang if one core is holding those resources while another core is handling a KGDB exception.