Developing a kernel module for the CentOS 7 system

This tutorial shows how to create, build and debug a simple kernel module on a CentOS 7 system using Visual Studio. Before you begin, install VisualKernel 2.0 or later.

  1. Start Visual Studio. Select File->New->Project and pick the VisualKernel kernel module wizard:
  2. Proceed with the default “Hello, World” sample:
  3. On the next page select the CentOS machine you want to debug:
  4. When you click “Next”, VisualKernel will begin installing and caching the kernel symbols and sources. If you are using an older kernel that does not have a matching symbol image, VisualKernel will suggest updating the kernel automatically:
  5. The next page of the wizard allows choosing the locations of the source files on the Windows and Linux machines. In this tutorial we will proceed with the default settings:
  6. Finally select the debug method. If you are using VMWare, select “Debug a Virtual Machine” as it is the fastest and the most reliable method. Otherwise, you can choose between ethernet, COM port, or a manual gdb stub (e.g. JTAG with OpenOCD):If you are using KGDBoE to debug a CentOS system, you will need to specify the network interface name manually. You can find out the interface name by running the “ifconfig” command.
  7. Press “Finish” to create your project. Then select Build->Build Solution to build it:
  8. Now you can set a breakpoint in the init() function and hit F5 to begin debugging:
  9. Once the breakpoint is hit, you can step into the printk() function by pressing F11. VisualKernel will automatically find and open the corresponding source file:Press F5 co continue debugging.
  10. Now we will debug the module unloading. Set a breakpoint in the exit() function and select “Unload module” in the GDB Session window:
  11. The breakpoint will be triggered and you will be able to step through the unload function:Press Shift-F5 to end debugging.
  12. You can change various settings related to building and debugging of your module by right-clicking on your project in Solution Explorer and selecting VisualKernel Project Properties: