DEV Community

Sagar Nilay
Sagar Nilay

Posted on Edited on

Tracing a Crash with WinDbg: A Hands-On Lab

I ran an intentionally broken C++ application inside a Windows Server 2022 Hyper-V VM, inspected the live failure, saved a crash dump, and recovered the same findings from that file. This was user-mode application debugging, not Windows kernel or Hyper-V hypervisor debugging.

1. Set up a Windows lab

My VM used Windows Server 2022 Desktop Experience (Datacenter), two virtual CPUs, 4 GB of startup memory, and a 60 GB dynamically expanding disk. I installed MSVC C++ Build Tools and the x64 version of WinDbg classic from the Windows SDK debugging tools. A smoke test confirmed that the compiler, linker, executable, debugger, and symbol loading worked.

The commands below run inside the VM. A PDB must match the exact executable build. It doesn’t contain the source text, so I kept the executable, PDB, and source file together.

2. Creating a fault

I made the application pass a null pointer to a function that writes an integer:

#include <cstdio>

__declspec(noinline) void WriteValue(int* destination) {
    *destination = 42;
}

__declspec(noinline) void RunCrashScenario() {
    int* destination = nullptr;
    WriteValue(destination);
}

int main() {
    std::puts("Crash lab: attempting to write through a null pointer.");
    RunCrashScenario();
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

The call sequence was main -> RunCrashScenario -> WriteValue. The bug was the write through destination, which was null.

I built it from PowerShell:

& 'C:\WinDbgLab\Crash\build.cmd'
Enter fullscreen mode Exit fullscreen mode

The build script produced crash.exe and the matching crash.pdb.

3. Open the app and configure symbols

I launched x64 WinDbg from PowerShell:

& 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\windbg.exe'
Enter fullscreen mode Exit fullscreen mode

Using File > Open Executable, I selected C:\WinDbgLab\Crash\crash.exe.

I minimized the application’s console without closing it and entered commands in WinDbg’s input box beside 0:000>.

.symfix C:\WinDbgLab\Symbols
.sympath+ C:\WinDbgLab\Crash
g
Enter fullscreen mode Exit fullscreen mode

Figure 1: WinDbg’s initial debugging session with the sample application open.

Figure 1. The initial debugger breakpoint, before our application runs.

Figure 2: The application folder added to the symbol path so WinDbg can find the matching PDB.

Figure 2. Adding the folder containing the application's matching PDB.

Figure 3: The process resumed and stopped at the intentional access violation.

Figure 3. The configured symbol path, before continuing with g.

The first command configured Microsoft’s public symbol server with a local cache. The second added the folder containing my application’s matching PDB, which enabled function names, source-line mappings, and local-variable inspection. I entered g separately to resume the process.

The application stopped at an access violation, c0000005, inside crash!WriteValue+0xa. This was the intentional fault.

4. Check the exception and call stack

I started with verbose analysis:

!analyze -v
Enter fullscreen mode Exit fullscreen mode

Figure 4: The verbose analysis output showing the exception details and initial diagnosis.

Figure 4. The verbose analysis output showing the exception details and initial diagnosis. The exception record identifies a write to address zero.

The output gave me an exception record and an initial diagnosis. I treated that as a lead and checked it against the stack, source, and pointer value. My program was executing a valid instruction inside WriteValue; that instruction tried to write to invalid address zero.

Then I inspected the call stack:

k
00  crash!WriteValue+0xa          [crash.cpp @ 4]
01  crash!RunCrashScenario+0x17   [crash.cpp @ 9]
02  crash!main+0x15              [crash.cpp @ 15]
Enter fullscreen mode Exit fullscreen mode

Figure 5: The call stack tracing execution from main to the failing write in WriteValue.

Figure 5. The call stack connects WriteValue to its callers.

The current function appears first. Frame 00 showed where execution stopped: WriteValue, line 4. Frame 01 showed that RunCrashScenario called it from line 9. Frame 02 showed that main called RunCrashScenario from line 15.

In crash!WriteValue, crash is the module and WriteValue is the function. The file and line details came from the symbols.

5. Confirm the bad value

I selected the top frame and displayed its variables, entering each command separately:

.frame 0
dv
destination = 0x0000000000000000
Enter fullscreen mode Exit fullscreen mode

The destination was null. The source analysis pointed to crash.cpp, line 4:

*destination = 42;
Enter fullscreen mode Exit fullscreen mode

Figure 6: Source-level details confirming the null destination pointer.

Figure 6. The source statement and the null destination agree with the exception.

The observations agreed: a write access violation, a destination address of zero, a null pointer, and a source statement that writes through it.

6. Save and inspect the dump

While execution was still paused at the access violation, I saved a dump:

.dump /ma C:\WinDbgLab\Crash\crash.dmp
Enter fullscreen mode Exit fullscreen mode

Figure 7: WinDbg’s confirmation that the crash dump was written successfully.

Figure 7. WinDbg’s confirmation that the crash dump was written successfully.

I waited for WinDbg to confirm Dump successfully written. The /ma option requests a full-memory user-mode minidump with additional diagnostic information. WinDbg still labels it a mini user dump because that is the dump format.

The live process is temporary. Once it ends, I can’t inspect its memory and thread state as they were at the fault. A dump preserves the state available at capture, including process memory, thread contexts, loaded-module information, and exception information. It lets me investigate later without keeping the application running or reproducing the failure.

After writing the dump, I stopped live debugging and used File > Open Crash Dump to open it. In the dump session, I entered these commands one at a time:

.symfix C:\WinDbgLab\Symbols
.sympath+ C:\WinDbgLab\Crash
!analyze -v
k
.frame 0
dv
Enter fullscreen mode Exit fullscreen mode

The saved-dump analysis identified the same c0000005 exception, write address zero, WriteValue+0xa, and source line 4.

Note: Real-world dumps may contain sensitive process-memory contents and should be stored and shared carefully.

What I took away

Working through this lab helped me understand how WinDbg can turn a crash into something I can investigate step by step. I learned to check the exception, follow the call stack, and look at the values in the code instead of guessing at the cause. This exercise gave me a better feel for how the pieces fit together and made me more comfortable exploring a crash dump.

Top comments (0)