This tutorial shows how to efficiently explore the Linux kernel source code using CodeJumps – the interactive navigation labels shown by VisualKernel 3.1 or later. We will create a basic kernel module project with VisualKernel, show how to easily add the kernel sources into the solution and then will use CodeJumps to quickly search the Linux Kernel codebase for functions related to ones used in our module.
Before you begin, install VisualKernel 3.1 or later.
- Start Visual Studio and open the New Project window, then select the VisualKernel’s Linux Kernel Module Wizard. If you are using Visual Studio 2019, enter “VisualKernel” in the search box to help quickly locate the VisualKernel’s wizards:
- Specify the name and the location of the project you are creating:
- Press “Create” to open the Linux Kernel Module Project Wizard. On the first page of the wizard select “Create a new kernel module => Virtual /proc file:
- Select the Linux machine you would like to target and ensure you have checked the “Download and install kernel symbols” checkbox:
VisualKernel will automatically download the sources and debug symbols for the kernel that is currently running on the target machine and will make sure you can step into its sources when debugging the module.
- Proceed with the default source code access settings on the next page and click “Finish”:
- On the “Debug Settings” page pick a debug method that works the best for your setup. You can read more about the supported debug methods here:
- Press “Finish” to complete the wizard. VisualKernel will generate a project for a basic kernel module creating a file in the /proc file system:
- Now we will use CodeJumps to quickly explore the source code of the Linux kernel. Locate the line setting the .read field in the file_operations structure and select “Go to definition”. This will open the fs.h file where the field is declared:
- Click on the “Show references” label. Once VisualKernel asks whether you want to search the Linux Kernel sources, click “Yes”:
- VisualKernel will query the exact command lines used to build the kernel from the KBuild Makefiles, that will allow building a very precise database of all source files, functions, structures and relations between them:
- Once the command lines are collected, VisualKernel will begin building the IntelliSense database. As the Linux Kernel is huge, this may take a long time, however once the database is built, VisualKernel will use it for instant navigation inside the kernel sources from any project using the same version of the kernel:
- The default CodeJumps view will simply display the references to a specific field, function or type, similar to the “Find References” command:
- A more powerful way to explore the kernel would be using the semantic views. Click on “Function Pointer Implementations” and VisualKernel will display all functions in the entire Kernel codebase that are explicitly assigned to the file_operations::read field anywhere in the kernel:
- You can use the filter in the top right corner of the popup to quickly search for a specific function. Then simply click on a function to instantly open its definition:
- As long as the function is defined anywhere inside the Linux Kernel codebase (and is included in the kernel configuration you are using), VisualKernel will instantly show its definition:
- You can use other views of the CodeJumps popups to explore the call trees or find functions assigning specific global variables/fields by using the corresponding view modes in the CodeJumps popup:
- If you want to limit the search scope to the current project only, simply use the scope selector in the bottom right corner of the CodeJumps popup: