| 1 | = Windows Kernel Debugging Tips = |
| 2 | |
| 3 | == Kernel Debugging Setup == |
| 4 | Windows kernel debugging requires two computers - the "target computer" - is where the code being debugged is run, and the "host computer" - is where the debugger is run. |
| 5 | Host & Target computers are connected either either by a Null-modem (Com-to-Com) cable or a Firewire (1394) cable. |
| 6 | The 1394 is preferable since it is much faster. |
| 7 | |
| 8 | === Target Computer configuration for 1394 debugging === |
| 9 | For Vista+ systems, run the following commands from the elevated console: |
| 10 | 1. bcdedit /copy {current} /d "Windows with 1394 debugger enabled (ch 10)" |
| 11 | - the command should create a new boot entry and print: "The entry was successfully copied to {guid-string}" |
| 12 | 1. bcdedit /set {the-above-guid-string} debug on |
| 13 | 1. bcdedit /set {the-above-guid-string} debugtype 1394 |
| 14 | 1. bcdedit /set {the-above-guid-string} channel 10 |
| 15 | - NOTE: any channel number could be used, but the channel used by the host and the target should batch ofcourse. We use 10 here throughout this article for simplicity. |
| 16 | - NOTE: once you don't need kernel debugging anymore, you can remove the above entry by the following command run from an elevated console: |
| 17 | {{{ |
| 18 | bcdedit /delete {the-above-guid-string} |
| 19 | }}} |
| 20 | |
| 21 | === Host Computer configuration === |
| 22 | 1. Install Debugging Tools For Windows. You can install it as a stand-alone component from the Windows SDK in a way described [http://msdn.microsoft.com/en-us/windows/hardware/gg463009 here]. |
| 23 | - Both 32bit and 64bit versions of Debugging Tools could be used for debugging both 32bit and 64bit Targets. |
| 24 | 1. Run the WinDbg debugger: "Start"->"All Programs"->"Debugging Tools For Windows"->"WinDbg". |
| 25 | 1. Setup WinDbg symbol paths: "File"->"Symbol File Path" -> in the "Symbol File Path" dialog enter "srv*c:\symbols*http://msdl.microsoft.com/download/symbols" (w/o quotes) in the edit box->"OK" |
| 26 | - NOTE: the C:\symbols here is the path of your downstream store, i.e. the path where the downloaded symbols would be stored/cached. You can use any path for that. |
| 27 | |
| 28 | == Starting Kernel Debugging == |
| 29 | |
| 30 | Once both Host & Target computers are configured with the above steps, you can start kernel debugging by the following steps: |
| 31 | |
| 32 | 1. Connect Host and Target computer with a 1394 cable (for 1394 debugging) or with a null-modem cable (for null-modem debugging). |
| 33 | 1. Follow the steps below on the host and then on target machine respectively: |
| 34 | |
| 35 | === Host Computer === |
| 36 | 1. Run the WinDbg debugger: "Start"->"All Programs"->"Debugging Tools For Windows"->"WinDbg". |
| 37 | - NOTE: you need to run it with elevated privileges (i.e. "Run As Administrator") the first time you want to setup a 1394 kernel debugging so that it is able to install the necessary 1394 debugging driver. |
| 38 | 1. For 1394 debugging: in WinDbg do: "File"->"Kernel Debug"->open "1394" tab and type "10" (w/o quotes) in the "Chanel" edit box->press "OK" |
| 39 | - The first time you do it you'll see some progress while WinDbg is installing the 1394d driver. |
| 40 | - Finally windbg should print something like |
| 41 | {{{ |
| 42 | Opened \.\DBG1394_INSTANCE10 |
| 43 | Waiting to reconnect... |
| 44 | }}} |
| 45 | |
| 46 | === Target Computer === |
| 47 | 1. Power-on the Target Computer |
| 48 | 1. In the displayed boot menu select the entry you previously added using steps in the "Kernel Debugging Setup" section above, e.g. "Windows with 1394 debugger enabled (ch 10)" |
| 49 | |
| 50 | == Common Kernel Debugging Tasks == |
| 51 | NOTE: unless otherwise specified all the tasks here list the WinDbg commands that should be entered in a debugger command window. |
| 52 | The command window becomes active only when the debuggee is break in the debugger. |
| 53 | To force the target system to break use <ctrl>+<break>, to resume use "g" command (in a debugger command window ofc) |
| 54 | |
| 55 | === Creating a dump file with WinDbg === |
| 56 | 1. Minidump |
| 57 | {{{ |
| 58 | .dump /m <dump\file\path\on\the\host\system.dmp> |
| 59 | }}} |
| 60 | 1. Full memory dump |
| 61 | {{{ |
| 62 | .dump /f <dump\file\path\on\the\host\system.dmp> |
| 63 | }}} |