{"id":96,"date":"2018-02-05T15:11:11","date_gmt":"2018-02-05T23:11:11","guid":{"rendered":"https:\/\/sysprogs.com\/tutorials\/?p=96"},"modified":"2022-09-15T18:37:11","modified_gmt":"2022-09-16T01:37:11","slug":"debugging-linux-kernel-with-visual-studio-and-vmware","status":"publish","type":"post","link":"https:\/\/sysprogs.com\/VisualKernel\/tutorials\/vmware\/","title":{"rendered":"Debugging Linux Kernel with Visual Studio and VMWare"},"content":{"rendered":"<p>This tutorial shows how to debug a Linux kernel module using Visual Studio and the VMWare GDB stub. This method is preferred over KGDB due to higher speed and reliability. Before you begin please install the following tools:<\/p>\n<ul>\n<li>Visual Studio<\/li>\n<li>VMWare<\/li>\n<li><a href=\"http:\/\/visualkernel.com\/download\/\">VisualKernel<\/a><\/li>\n<li>A recent version of Linux inside the VM (we recommend Ubuntu, CentOS or Fedora)<\/li>\n<li>Ensure that you can access your Linux machine over SSH<\/li>\n<\/ul>\n<ol>\n<li>Start Visual Studio. Open the New Project dialog and locate the Linux Kernel Module Wizard:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/01-wizard.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-580\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/01-wizard.png\" alt=\"\" width=\"1014\" height=\"675\" \/><\/a><\/li>\n<li>Enter the name and location for your project:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/02-name.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-582\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/02-name.png\" alt=\"\" width=\"1014\" height=\"675\" \/><\/a><\/li>\n<li>On the first wizard page select &#8220;Hello, World&#8221; module and press &#8220;Next&#8221;:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/03-hello.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-583\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/03-hello.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>On the next page select &#8220;Setup a new target for running Linux kernels&#8221;. If you would like to debug an existing VMWare machine, select &#8220;Use an existing virtual machine&#8221;: <a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/04-vm.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-584\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/04-vm.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a>You can also select &#8220;Download a ready-to-debug VM image&#8221; to download an existing VM together with matching pre-indexed kernel symbols.<\/li>\n<li>Proceed with the default VM configuration:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/06-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-585\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/06-build.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>Once you press &#8216;Next&#8217; VisualKernel will configure the machine for building and debugging your kernel module. This will involve automatically installing the necessary packages and downloading the sources\/symbols to your Windows machine:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/07-progress.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-586\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/07-progress.png\" alt=\"\" width=\"736\" height=\"553\" \/><\/a>Once the machine is ready to build and debug your kernel module, VisualKernel will test it by building a basic module and verifying that the build succeeds.<\/li>\n<li>On the next wizard page you can change the location where VisualKernel will build your kernel module. Press &#8220;Next&#8221; to accept the default location:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/08-access.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-587\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/08-access.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>On the last wizard page select &#8220;Debug a Virtual Machine&#8221;, then select &#8220;VMWare&#8221; and specify the path to the .vmx file of the machine you are going to debug. You can use the button to the right from the text box to browse through a list of VMWare virtual machines registered for the current user:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/09-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-588\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/09-debug.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221; to create the project. Press Ctrl-Shift-B to build it:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/10-built-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-589\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/10-built-2.png\" alt=\"\" width=\"1278\" height=\"718\" \/><\/a><\/li>\n<li>Set a breakpoint in the init function and press F5 to start debugging. VisualKernel will automatically edit the .vmx file to enable the undocumented VMWare GDB stub and will proceed to loading your kernel module. The breakpoint you set in the init function will trigger:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/11-debug-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-590\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/11-debug-1.png\" alt=\"\" width=\"1278\" height=\"718\" \/><\/a><\/li>\n<li>You can use the <strong>Debug-&gt;Windows-&gt;Live Watch<\/strong> window to view the values of various variables live, without having to stop the debug session: <a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/12-jiffies.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-591\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/12-jiffies.png\" alt=\"\" width=\"1340\" height=\"824\" \/><\/a>When done debugging, press Shift-F5 to end the debug session.<\/li>\n<\/ol>\n<p>You can read more about other debugging methods on <a href=\"https:\/\/sysprogs.com\/VisualKernel\/documentation\/overview\/\">this page<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to debug a Linux kernel module using Visual Studio and the VMWare GDB stub. This method<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42],"tags":[26,27],"_links":{"self":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/96"}],"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=96"}],"version-history":[{"count":4,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/96\/revisions"}],"predecessor-version":[{"id":593,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/96\/revisions\/593"}],"wp:attachment":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/media?parent=96"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/categories?post=96"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/tags?post=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}