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.
- Start Visual Studio. Select File->New->Project and pick the VisualKernel kernel module wizard:
- Proceed with the default “Hello, World” sample:
- On the next page select the CentOS machine you want to debug:
- 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:
- 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:
- 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.
- Press “Finish” to create your project. Then select Build->Build Solution to build it:
- Now you can set a breakpoint in the init() function and hit F5 to begin debugging:
- 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.
- Now we will debug the module unloading. Set a breakpoint in the exit() function and select “Unload module” in the GDB Session window:
- The breakpoint will be triggered and you will be able to step through the unload function:Press Shift-F5 to end debugging.
- 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: