{"id":404,"date":"2015-02-15T01:14:59","date_gmt":"2015-02-15T06:14:59","guid":{"rendered":"http:\/\/www.rajatswarup.com\/blog\/?p=404"},"modified":"2015-02-15T01:14:59","modified_gmt":"2015-02-15T06:14:59","slug":"setting-up-a-windows-7-kernel-development-environment","status":"publish","type":"post","link":"https:\/\/www.rajatswarup.com\/blog\/2015\/02\/15\/setting-up-a-windows-7-kernel-development-environment\/","title":{"rendered":"Setting up a Windows 7 Kernel Development Environment"},"content":{"rendered":"<p>If you are writing some Ring0 (or privileged mode code), say something like device drivers in Windows you&#8217;d probably be better served with a separate development machine and a deployment machine. This helps you to write poor code and still not lose hair because your development machine blue screens! \ud83d\ude42<\/p>\n<p>My setup was using a Windows 8.1 development machine and a Hyper-V based Windows 7 machine for debugging. You will need to execute different tasks on the &#8220;guest&#8221; (Hyper-V based Windows 7 virtual machine) and some other tasks on the development machine. \u00a0I followed many of the things from the MSDN blog post <a href=\"http:\/\/blogs.technet.com\/b\/askcore\/archive\/2013\/07\/02\/how-to-live-debug-a-vm-in-hyper-v.aspx\">here<\/a><\/p>\n<p>On your guest machine you would want to setup a named pipe and setup debug settings. To do that this is what you need to do:<\/p>\n<p>Setup a virtual com port in the Hyper-V Settings (File -&gt; Settings) , this port will be used to communicate from the host machine to the guest to communicate the Kernel debugging commands.<br \/>\n<a href=\"http:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-405\" src=\"http:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled-300x166.png\" alt=\"Untitled\" width=\"300\" height=\"166\" srcset=\"https:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled-300x166.png 300w, https:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled-1024x568.png 1024w, https:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled.png 1050w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Now make sure that your target guest machine is configured to &#8220;listen&#8221; those commands. \u00a0Inside the guest VM, start a command shell (cmd.exe -&gt; Run as Administrator).<\/p>\n<p><a href=\"http:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-406\" src=\"http:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled2-245x300.png\" alt=\"Untitled2\" width=\"245\" height=\"300\" srcset=\"https:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled2-245x300.png 245w, https:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled2-140x170.png 140w, https:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled2.png 488w\" sizes=\"auto, (max-width: 245px) 100vw, 245px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Configure the bcdedit commands so that the machine can now be debugged. \u00a0Right after the 2nd command, reboot your Virtual Machine.<\/p>\n<p><a href=\"http:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-407\" src=\"http:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled3-300x76.png\" alt=\"Untitled3\" width=\"300\" height=\"76\" srcset=\"https:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled3-300x76.png 300w, https:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled3.png 621w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>With the VM now configured to listen the debug commands via the COM1 port, and the debug mode on in the bootup settings, now start the WinDbg x64 on the host (using &#8220;Run as administrator&#8221;; you need administrative privileges for communication via Serial port). \u00a0In your kernel debugger on the host or the development machine (I&#8217;m assuming that these are both on the same physical hardware here). \u00a0Click on File -&gt; Kernel Debug and you should see the following screen in the WinDbg window:<\/p>\n<p><a href=\"http:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-408\" src=\"http:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled4-300x115.png\" alt=\"Untitled4\" width=\"300\" height=\"115\" srcset=\"https:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled4-300x115.png 300w, https:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled4.png 491w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Hit Ctrl+Break or Debug -&gt; Break and you will see something like this:<\/p>\n<p><a href=\"http:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-409\" src=\"http:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled5-300x212.png\" alt=\"Untitled5\" width=\"300\" height=\"212\" srcset=\"https:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled5-300x212.png 300w, https:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled5-1024x724.png 1024w, https:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled5.png 1030w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Just remember that when you break in the debugger, your guest in Hyper-V should become &#8220;unresponsive&#8221;. \u00a0The only thing is that it is not\u00a0<em>really<\/em> unresponsive, its just being debugged. \u00a0Just to make sure, that you have the symbols package that is quite useful for debugging run the following command:<\/p>\n<blockquote><p>!process 0 0<\/p><\/blockquote>\n<p>If you see something like the following screen show up:<\/p>\n<p><a href=\"http:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-410\" src=\"http:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled6-300x186.png\" alt=\"Untitled6\" width=\"300\" height=\"186\" srcset=\"https:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled6-300x186.png 300w, https:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled6.png 816w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>The following error means that the symbols are not defined. \u00a0Symbols help the debugger give more information about the commands that you are going to execute in the debugger.<\/p>\n<blockquote><p>**** NT ACTIVE PROCESS DUMP ****<br \/>\nNT symbols are incorrect, please fix symbols<\/p><\/blockquote>\n<p>To fix this, use the following commands:<\/p>\n<blockquote><p>kd&gt; .sympath SRV*c:\\symcache*http:\/\/msdl.microsoft.com\/download\/symbols<br \/>\nkd&gt; .symfix<br \/>\nkd&gt; .symfix c:\\symcache<br \/>\nkd&gt; !sym noisy<br \/>\nkd&gt; .reload \/o<\/p><\/blockquote>\n<p>Then again try the command: !process 0 0 and see if you get a good response. \u00a0A good response looks like the following:<\/p>\n<p><a href=\"http:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-411\" src=\"http:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled7-300x297.png\" alt=\"Untitled7\" width=\"300\" height=\"297\" srcset=\"https:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled7-300x297.png 300w, https:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled7-150x150.png 150w, https:\/\/www.rajatswarup.com\/blog\/wp-content\/uploads\/2015\/02\/Untitled7.png 593w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>With this you should be good to go! Happy debugging and writing cool Ring0 code.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are writing some Ring0 (or privileged mode code), say something like device drivers in Windows you&#8217;d probably be better served with a separate development machine and a deployment machine. This helps you to write poor code and still not lose hair because your development machine blue screens! \ud83d\ude42 My setup was using a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[230,196,197],"tags":[261,462,461,254],"class_list":["post-404","post","type-post","status-publish","format-standard","hentry","category-howto","category-programming","category-tools","tag-drivers","tag-ring0","tag-windbg","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/posts\/404","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/comments?post=404"}],"version-history":[{"count":1,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/posts\/404\/revisions"}],"predecessor-version":[{"id":412,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/posts\/404\/revisions\/412"}],"wp:attachment":[{"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/media?parent=404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/categories?post=404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/tags?post=404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}