WinDbg Tutorial
From ReactOS
WinDbg Quick-Start Guide
This is work in progress and probably has a lot of rough edges. Feel free to phrase more clearly or explain in more detail (preferably by linking to the appropriate pages)
Prerequisites
- a ROS source checkout
- an MSVC or WDK command prompt
- CMake
- a CMake build directory (run configure in the MSVC prompt inside ROS checkout, CMake's bin folder being in your PATH)
- some experience with getting debug logs from ROS
Steps
- build the kernel: nmake/nologo ntoskrnl
- build kdcom.dll: nmake/nologo kdcom -- preferably use the one from Windows 2003
- build any other modules you want to work on. I prefer having at least ntdll, and kernel32. nmake/nologo ntdll kernel32
- grab a trunk build. Usually the latest from http://www.reactos.org/getbuilds/ - or build one yourself
-
- if you can mount or otherwise access your target machine's file system, you can simply run first (and second, if you don't want to do any debugging there) stage setup, then replace the files on the target disk with the ones you built above
- alternatively, replace the corresponding files in the ISO
- now start WinDbg, and choose File->Kernel Debug (Ctrl+K)
- set up WinDbg according to how your target outputs its debug messages
- to use a Pipe, check the Pipe option, set Port to \\.\Pipe\TheNameOfYourPipe
- to use a com0com serial port, set Port to the name of the port, such as \\.\CNCA0
- to use a physical serial port, set Baud Rate to 115200 and Port to the name of the port, such as \\.\COM1
- boot up the target, and select the ReactOS (Debug) boot menu entry
- enjoy debugging with WinDbg. Some tips:
- break in with Tab+K works, just like with kdbg. This is useful since ROS sometimes doesn't react to WinDbg's break-in
- kernel breakpoints mostly work. In userspace they're not always too reliable. Adding __debugbreak(); in the source makes sure you'll break in
- with an MSVC-built ntdll and an MSVC-built xxx.dll, you should get complete backtraces from the kernel back to xxx.dll
- check out the WinDbg page for some useful commands. The help is also really good

