{"id":86,"date":"2018-02-05T15:08:16","date_gmt":"2018-02-05T23:08:16","guid":{"rendered":"https:\/\/sysprogs.com\/tutorials\/?p=86"},"modified":"2018-02-05T15:08:16","modified_gmt":"2018-02-05T23:08:16","slug":"debugging-kernel-modules-on-ubuntu-15-with-visual-studio","status":"publish","type":"post","link":"https:\/\/sysprogs.com\/VisualKernel\/tutorials\/ubuntu\/","title":{"rendered":"Debugging kernel modules on Ubuntu 15 with Visual Studio"},"content":{"rendered":"<p>This tutorial shows how to develop and debug a basic kernel module for Ubuntu 15 using Visual Studio and VisualKernel. Before you begin, install VisualKernel 2.0.<\/p>\n<ol>\n<li>Start Visual Studio. Select File-&gt;New-&gt;Project and pick the VisualKernel kernel module wizard:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/ubuntu\/img\/01-prjwiz.png\" width=\"800\" \/><\/li>\n<li>The first page of the wizard allows selecting the project template. In this tutorial we will use the default &#8220;Hello, World&#8221; template:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/ubuntu\/img\/02-helloworld.png\" width=\"696\" \/><\/li>\n<li>The next page allows selecting the remote machine. Choose your Ubuntu machine and click &#8220;Next&#8221; to automatically install and cache the kernel symbols and sources:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/ubuntu\/img\/03-machine.png\" width=\"696\" \/><\/li>\n<li>The next page allows specifying the directory where the sources will be stored. The default settings should work for most of the projects:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/ubuntu\/img\/04-sources.png\" width=\"696\" \/><\/li>\n<li>Finally the last page allows choosing the debug method. If you are using a VMWare VM, we recommend debugging it directly using the VM debugger. Otherwise you can choose KGDB-over-Ethernet for higher speed or KGDB-over-COM port for higher reliability:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/ubuntu\/img\/05-debug.png\" width=\"696\" \/><\/li>\n<li>Press Finish to create the project. You can build it by pressing Ctrl-Shift-B:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/ubuntu\/img\/06-build.png\" width=\"700\" \/><\/li>\n<li>If you are debugging over Ethernet, the debugging may hang randomly on some kernels with Ubuntu patches due to incomptaibilities between kgdboe and the softirq mechanism. In most cases this can be fixed by unchecking the &#8220;Disable all CPU cores except #0&#8221; checkbox. This will turn on more intrusive KGDBoE mode that involves detecting and delaying network-related interrupts to prevent deadlocking:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/ubuntu\/img\/07-settings.png\" width=\"789\" \/><\/li>\n<li>Set a breakpoint in the init() function and hit F5 to start debugging. The breakpoint will be triggered:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/ubuntu\/img\/08-bkpt.png\" width=\"700\" \/><\/li>\n<li>You can right-click on your project in Solution Explorer and choose VisualKernel Project Properties to edit various project-related settings. E.g. if debugging over Ethernet is unreliable, you can switch to a more reliable VM debugger or a COM port-based connection:<img decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/ubuntu\/img\/09-vm.png\" width=\"745\" \/><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to develop and debug a basic kernel module for Ubuntu 15 using Visual Studio and VisualKernel.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[20,22],"_links":{"self":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/86"}],"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=86"}],"version-history":[{"count":1,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/86\/revisions"}],"predecessor-version":[{"id":87,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/86\/revisions\/87"}],"wp:attachment":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/media?parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/categories?post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/tags?post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}