{"id":375,"date":"2019-04-09T10:41:43","date_gmt":"2019-04-09T17:41:43","guid":{"rendered":"https:\/\/sysprogs.com\/tutorials\/?p=375"},"modified":"2019-07-16T18:16:13","modified_gmt":"2019-07-17T01:16:13","slug":"exploring-the-linux-kernel-with-codejumps","status":"publish","type":"post","link":"https:\/\/sysprogs.com\/VisualKernel\/tutorials\/codejumps\/","title":{"rendered":"Exploring the Linux Kernel with CodeJumps"},"content":{"rendered":"<p>This tutorial shows how to efficiently explore the Linux kernel source code using CodeJumps &#8211; 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.<\/p>\n<p>Before you begin, install VisualKernel 3.1 or later.<\/p>\n<ol>\n<li>Start Visual Studio and open the New Project window, then select the VisualKernel&#8217;s Linux Kernel Module Wizard. If you are using Visual Studio 2019, enter &#8220;VisualKernel&#8221; in the search box to help quickly locate the VisualKernel&#8217;s wizards:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/01-newprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-376\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/01-newprj.png\" alt=\"\" width=\"1024\" height=\"710\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/01-newprj.png 1024w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/01-newprj-300x208.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/01-newprj-768x533.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/01-newprj-392x272.png 392w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/01-newprj-130x90.png 130w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/li>\n<li>Specify the name and the location of the project you are creating: <a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/02-prjname.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-377\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/02-prjname.png\" alt=\"\" width=\"1024\" height=\"710\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/02-prjname.png 1024w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/02-prjname-300x208.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/02-prjname-768x533.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/02-prjname-392x272.png 392w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/02-prjname-130x90.png 130w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/li>\n<li>Press &#8220;Create&#8221; to open the Linux Kernel Module Project Wizard. On the first page of the wizard select &#8220;Create a new kernel module =&gt; Virtual \/proc file:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/03-procfile.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-378\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/03-procfile.png\" alt=\"\" width=\"886\" height=\"693\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/03-procfile.png 886w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/03-procfile-300x235.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/03-procfile-768x601.png 768w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>Select the Linux machine you would like to target and ensure you have checked the &#8220;Download and install kernel symbols&#8221; checkbox:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/04-target.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-379\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/04-target.png\" alt=\"\" width=\"886\" height=\"693\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/04-target.png 886w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/04-target-300x235.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/04-target-768x601.png 768w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><br \/>\nVisualKernel 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.<\/li>\n<li>Proceed with the default source code access settings on the next page and click &#8220;Finish&#8221;:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/05-files.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-380\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/05-files.png\" alt=\"\" width=\"886\" height=\"693\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/05-files.png 886w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/05-files-300x235.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/05-files-768x601.png 768w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>On the &#8220;Debug Settings&#8221; page pick a debug method that works the best for your setup. You can read more about the supported debug methods <a href=\"https:\/\/sysprogs.com\/VisualKernel\/debugmethods\/\">here<\/a>:<br \/>\n<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/06-debugmethod.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-381\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/06-debugmethod.png\" alt=\"\" width=\"886\" height=\"693\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/06-debugmethod.png 886w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/06-debugmethod-300x235.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/06-debugmethod-768x601.png 768w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221; to complete the wizard. VisualKernel will generate a project for a basic kernel module creating a file in the \/proc file system:<br \/>\n<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/07-source.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-382\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/07-source.png\" alt=\"\" width=\"1215\" height=\"783\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/07-source.png 1215w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/07-source-300x193.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/07-source-768x495.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/07-source-1024x660.png 1024w\" sizes=\"(max-width: 1215px) 100vw, 1215px\" \/><\/a><\/li>\n<li>Now we will use CodeJumps to quickly explore the source code of the Linux kernel. Locate the line setting the <strong>.read<\/strong> field in the <strong>file_operations<\/strong> structure and select &#8220;Go to definition&#8221;. This will open the <strong>fs.h<\/strong> file where the field is declared:<br \/>\n<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/08-def.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-383\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/08-def.png\" alt=\"\" width=\"1215\" height=\"784\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/08-def.png 1215w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/08-def-300x194.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/08-def-768x496.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/08-def-1024x661.png 1024w\" sizes=\"(max-width: 1215px) 100vw, 1215px\" \/><\/a><\/li>\n<li>Click on the &#8220;Show references&#8221; label. Once VisualKernel asks whether you want to search the Linux Kernel sources, click &#8220;Yes&#8221;:<br \/>\n<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/09-index.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-384\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/09-index.png\" alt=\"\" width=\"1215\" height=\"784\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/09-index.png 1215w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/09-index-300x194.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/09-index-768x496.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/09-index-1024x661.png 1024w\" sizes=\"(max-width: 1215px) 100vw, 1215px\" \/><\/a><\/li>\n<li>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:<br \/>\n<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/10-index2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-385\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/10-index2.png\" alt=\"\" width=\"1215\" height=\"783\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/10-index2.png 1215w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/10-index2-300x193.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/10-index2-768x495.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/10-index2-1024x660.png 1024w\" sizes=\"(max-width: 1215px) 100vw, 1215px\" \/><\/a><\/li>\n<li>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:<br \/>\n<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/11-scanning-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-393\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/11-scanning-1.png\" alt=\"\" width=\"1215\" height=\"783\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/11-scanning-1.png 1215w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/11-scanning-1-300x193.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/11-scanning-1-768x495.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/11-scanning-1-1024x660.png 1024w\" sizes=\"(max-width: 1215px) 100vw, 1215px\" \/><\/a><\/li>\n<li>The default CodeJumps view will simply display the references to a specific field, function or type, similar to the &#8220;Find References&#8221; command:<br \/>\n<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/12-refs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-387\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/12-refs.png\" alt=\"\" width=\"1215\" height=\"782\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/12-refs.png 1215w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/12-refs-300x193.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/12-refs-768x494.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/12-refs-1024x659.png 1024w\" sizes=\"(max-width: 1215px) 100vw, 1215px\" \/><\/a><\/li>\n<li>A more powerful way to explore the kernel would be using the semantic views. Click on &#8220;Function Pointer Implementations&#8221; and VisualKernel will display all functions in the entire Kernel codebase that are explicitly assigned to the <strong>file_operations::read<\/strong> field anywhere in the kernel:<br \/>\n<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/13-assign.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-388\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/13-assign.png\" alt=\"\" width=\"1215\" height=\"782\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/13-assign.png 1215w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/13-assign-300x193.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/13-assign-768x494.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/13-assign-1024x659.png 1024w\" sizes=\"(max-width: 1215px) 100vw, 1215px\" \/><\/a><\/li>\n<li>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:<br \/>\n<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/14-module.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-389\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/14-module.png\" alt=\"\" width=\"1215\" height=\"783\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/14-module.png 1215w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/14-module-300x193.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/14-module-768x495.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/14-module-1024x660.png 1024w\" sizes=\"(max-width: 1215px) 100vw, 1215px\" \/><\/a><\/li>\n<li>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:<br \/>\n<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/15-impl.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-390\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/15-impl.png\" alt=\"\" width=\"1215\" height=\"782\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/15-impl.png 1215w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/15-impl-300x193.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/15-impl-768x494.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/15-impl-1024x659.png 1024w\" sizes=\"(max-width: 1215px) 100vw, 1215px\" \/><\/a><\/li>\n<li>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:<br \/>\n<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/16-calls.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-391\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/16-calls.png\" alt=\"\" width=\"1215\" height=\"782\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/16-calls.png 1215w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/16-calls-300x193.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/16-calls-768x494.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/16-calls-1024x659.png 1024w\" sizes=\"(max-width: 1215px) 100vw, 1215px\" \/><\/a><\/li>\n<li>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:<br \/>\n<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/17-project.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-392\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/17-project.png\" alt=\"\" width=\"1215\" height=\"783\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/17-project.png 1215w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/17-project-300x193.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/17-project-768x495.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2019\/04\/17-project-1024x660.png 1024w\" sizes=\"(max-width: 1215px) 100vw, 1215px\" \/><\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to efficiently explore the Linux kernel source code using CodeJumps &#8211; the interactive navigation labels shown<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"_links":{"self":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/375"}],"collection":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/comments?post=375"}],"version-history":[{"count":1,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/375\/revisions"}],"predecessor-version":[{"id":394,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/375\/revisions\/394"}],"wp:attachment":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/media?parent=375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/categories?post=375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/tags?post=375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}