<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sagar Nilay</title>
    <description>The latest articles on DEV Community by Sagar Nilay (@sagar_nilay_683fc0b5a5c3e).</description>
    <link>https://dev.to/sagar_nilay_683fc0b5a5c3e</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4244661%2Fdbe4b588-85ef-496d-88d6-be9dfb0c723b.jpg</url>
      <title>DEV Community: Sagar Nilay</title>
      <link>https://dev.to/sagar_nilay_683fc0b5a5c3e</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sagar_nilay_683fc0b5a5c3e"/>
    <language>en</language>
    <item>
      <title>Tracing a Crash with WinDbg: A Hands-On Lab</title>
      <dc:creator>Sagar Nilay</dc:creator>
      <pubDate>Sat, 14 Nov 2026 17:18:31 +0000</pubDate>
      <link>https://dev.to/sagar_nilay_683fc0b5a5c3e/tracing-a-crash-with-windbg-a-hands-on-lab-3p5i</link>
      <guid>https://dev.to/sagar_nilay_683fc0b5a5c3e/tracing-a-crash-with-windbg-a-hands-on-lab-3p5i</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Set up a Windows lab
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Creating a fault
&lt;/h2&gt;

&lt;p&gt;I made the application pass a null pointer to a function that writes an integer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include &amp;lt;cstdio&amp;gt;&lt;/span&gt;

&lt;span class="nf"&gt;__declspec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;noinline&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;WriteValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;destination&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;destination&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;__declspec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;noinline&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;RunCrashScenario&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;destination&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;nullptr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;WriteValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;destination&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nb"&gt;puts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Crash lab: attempting to write through a null pointer."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;RunCrashScenario&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The call sequence was main -&amp;gt; RunCrashScenario -&amp;gt; WriteValue. The bug was the write through &lt;code&gt;destination&lt;/code&gt;, which was null.&lt;/p&gt;

&lt;p&gt;I built it from PowerShell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="s1"&gt;'C:\WinDbgLab\Crash\build.cmd'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The build script produced &lt;code&gt;crash.exe&lt;/code&gt; and the matching &lt;code&gt;crash.pdb&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Open the app and configure symbols
&lt;/h2&gt;

&lt;p&gt;I launched x64 WinDbg from PowerShell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="s1"&gt;'C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\windbg.exe'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using &lt;strong&gt;File &amp;gt; Open Executable&lt;/strong&gt;, I selected &lt;code&gt;C:\WinDbgLab\Crash\crash.exe&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I minimized the application’s console without closing it and entered commands in WinDbg’s input box beside &lt;code&gt;0:000&amp;gt;&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.symfix C:\WinDbgLab\Symbols
.sympath+ C:\WinDbgLab\Crash
g
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fza2i6s3lymg57nizntki.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fza2i6s3lymg57nizntki.png" alt="Figure 1: WinDbg’s initial debugging session with the sample application open." width="800" height="519"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 1. The initial debugger breakpoint, before our application runs.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp9h3qfyvhf099iccn3ri.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp9h3qfyvhf099iccn3ri.png" alt="Figure 2: The application folder added to the symbol path so WinDbg can find the matching PDB." width="800" height="524"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 2. Adding the folder containing the application's matching PDB.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcm80jjm72fw9ecytb4zo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcm80jjm72fw9ecytb4zo.png" alt="Figure 3: The process resumed and stopped at the intentional access violation." width="800" height="522"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 3. The configured symbol path, before continuing with g.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;g&lt;/code&gt; separately to resume the process.&lt;/p&gt;

&lt;p&gt;The application stopped at an access violation, &lt;code&gt;c0000005&lt;/code&gt;, inside &lt;code&gt;crash!WriteValue+0xa&lt;/code&gt;. This was the intentional fault.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Check the exception and call stack
&lt;/h2&gt;

&lt;p&gt;I started with verbose analysis:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;!analyze -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsrco96ku1q8ilwn2t3gi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsrco96ku1q8ilwn2t3gi.png" alt="Figure 4: The verbose analysis output showing the exception details and initial diagnosis." width="799" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 4. The verbose analysis output showing the exception details and initial diagnosis. The exception record identifies a write to address zero.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;WriteValue&lt;/code&gt;; that instruction tried to write to invalid address zero.&lt;/p&gt;

&lt;p&gt;Then I inspected the call stack:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;k
00  crash!WriteValue+0xa          [crash.cpp @ 4]
01  crash!RunCrashScenario+0x17   [crash.cpp @ 9]
02  crash!main+0x15              [crash.cpp @ 15]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1e51i1ke07y3o5f4wfaa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1e51i1ke07y3o5f4wfaa.png" alt="Figure 5: The call stack tracing execution from main to the failing write in WriteValue." width="799" height="86"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 5. The call stack connects WriteValue to its callers.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The current function appears first. Frame 00 showed where execution stopped: &lt;code&gt;WriteValue&lt;/code&gt;, line 4. Frame 01 showed that &lt;code&gt;RunCrashScenario&lt;/code&gt; called it from line 9. Frame 02 showed that &lt;code&gt;main&lt;/code&gt; called &lt;code&gt;RunCrashScenario&lt;/code&gt; from line 15.&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;crash!WriteValue&lt;/code&gt;, &lt;code&gt;crash&lt;/code&gt; is the module and &lt;code&gt;WriteValue&lt;/code&gt; is the function. The file and line details came from the symbols.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Confirm the bad value
&lt;/h2&gt;

&lt;p&gt;I selected the top frame and displayed its variables, entering each command separately:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.frame 0
dv
destination = 0x0000000000000000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The destination was null. The source analysis pointed to &lt;code&gt;crash.cpp&lt;/code&gt;, line 4:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;destination&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0tx61aqg85l4xvqp9m20.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0tx61aqg85l4xvqp9m20.png" alt="Figure 6: Source-level details confirming the null destination pointer." width="799" height="435"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 6. The source statement and the null destination agree with the exception.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The observations agreed: a write access violation, a destination address of zero, a null pointer, and a source statement that writes through it.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Save and inspect the dump
&lt;/h2&gt;

&lt;p&gt;While execution was still paused at the access violation, I saved a dump:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.dump /ma C:\WinDbgLab\Crash\crash.dmp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpt9emaaqn8tadc2vtcq0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpt9emaaqn8tadc2vtcq0.png" alt="Figure 7: WinDbg’s confirmation that the crash dump was written successfully." width="800" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 7. WinDbg’s confirmation that the crash dump was written successfully.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I waited for WinDbg to confirm &lt;strong&gt;Dump successfully written&lt;/strong&gt;. The &lt;code&gt;/ma&lt;/code&gt; 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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;After writing the dump, I stopped live debugging and used &lt;strong&gt;File &amp;gt; Open Crash Dump&lt;/strong&gt; to open it. In the dump session, I entered these commands one at a time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.symfix C:\WinDbgLab\Symbols
.sympath+ C:\WinDbgLab\Crash
!analyze -v
k
.frame 0
dv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The saved-dump analysis identified the same &lt;code&gt;c0000005&lt;/code&gt; exception, write address zero, &lt;code&gt;WriteValue+0xa&lt;/code&gt;, and source line 4. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Real-world dumps may contain sensitive process-memory contents and should be stored and shared carefully.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I took away
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

</description>
      <category>debugging</category>
    </item>
  </channel>
</rss>
