{"id":112,"date":"2018-02-05T15:30:03","date_gmt":"2018-02-05T23:30:03","guid":{"rendered":"https:\/\/sysprogs.com\/tutorials\/?p=112"},"modified":"2018-02-05T15:30:03","modified_gmt":"2018-02-05T23:30:03","slug":"debugging-a-basic-module-with-a-custom-linux-kernel","status":"publish","type":"post","link":"https:\/\/sysprogs.com\/VisualKernel\/tutorials\/kernel\/module\/","title":{"rendered":"Debugging a Basic Module with a Custom Linux Kernel"},"content":{"rendered":"<p>This tutorial demonstrates how to build and debug a basic Linux kernel module under a custom Linux kernel built with VisualKernel. Before proceeding with the steps below, follow\u00a0<a href=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/kernel\/\">this tutorial\u00a0<\/a>to build your custom kernel.<\/p>\n<ol>\n<li>Open your custom kernel project. Right-click on the solution in Solution Explorer and select &#8220;Add -&gt; New Project&#8221;:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/kernel\/module\/img\/01-addprj.png\" width=\"700\" height=\"600\" \/><\/li>\n<li>Select VisualKernel-&gt;Linux Kernel Module wizard:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/kernel\/module\/img\/02-newmodule.png\" width=\"700\" height=\"394\" \/><\/li>\n<li>Proceed with the default settings on the first page:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/kernel\/module\/img\/03-hellomodule.png\" width=\"696\" height=\"628\" \/><\/li>\n<li>On the next page select your target computer and uncheck the automatic installation checkbox:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/kernel\/module\/img\/04-noautokernel.png\" width=\"696\" height=\"628\" \/><\/li>\n<li>On the next page enable the &#8220;Debug a kernel built with VisualKernel project&#8221; checkbox and specify the path to the<strong>.vkrnlsettings<\/strong>\u00a0file in the directory with your custom kernel project:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/kernel\/module\/img\/05-kernelfile.png\" width=\"696\" height=\"628\" \/><\/li>\n<li>On the next page specify the location where you want to store the source code or proceed with the default settings:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/kernel\/module\/img\/06-source.png\" width=\"696\" height=\"628\" \/><\/li>\n<li>On the last page select the method of connecting a kernel debugger to your machine:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/kernel\/module\/img\/07-kgdb.png\" width=\"696\" height=\"628\" \/><\/li>\n<li>Press Finish to create the project. Go to Configuration Manager and uncheck the &#8216;build&#8217; option for the kernel project. This will ensure the kernel itself won&#8217;t be built each time you build your solution:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/kernel\/module\/img\/08-nobuild.png\" width=\"700\" height=\"439\" \/><\/li>\n<li>Build the solution by pressing Ctrl-Shift-B. The kernel module will now be built:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/kernel\/module\/img\/09-buildmodule.png\" width=\"698\" height=\"562\" \/><\/li>\n<li>Set a breakpoint in the init() function, select the module project as the startup project and press F5 to begin debugging. The module will be loaded and the breakpoint will be triggered:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/kernel\/module\/img\/10-debug.png\" width=\"698\" height=\"562\" \/><\/li>\n<li>You can use the Call Stack window to navigate to the frames from the kernel itself. Note that VisualKernel will automatically show the files from your custom kernel project:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/kernel\/module\/img\/11-callstack.png\" width=\"700\" height=\"600\" \/><\/li>\n<li>If you want to modify the kernel further, simply edit the related files, stop debugging, right-click on the kernel in Solution Explorer and select &#8220;Build&#8221;:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/kernel\/module\/img\/12-buildkernel.png\" width=\"700\" height=\"600\" \/>Don&#8217;t forget to reboot your Linux machine after the new kernel is built and installed.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial demonstrates how to build and debug a basic Linux kernel module under a custom Linux kernel built with<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[34],"_links":{"self":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/112"}],"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=112"}],"version-history":[{"count":1,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/112\/revisions"}],"predecessor-version":[{"id":113,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/112\/revisions\/113"}],"wp:attachment":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/media?parent=112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/categories?post=112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/tags?post=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}