{"componentChunkName":"component---src-templates-post-template-js","path":"/windows-windbg-002-tutorial-en","result":{"data":{"markdownRemark":{"id":"74cb4712-0b8c-540a-b2e2-cf896ec1287b","html":"<blockquote>\n<p>This page has been machine-translated from the <a href=\"/windows-windbg-002-tutorial\">original page</a>.</p>\n</blockquote>\n<p>My goal is to become proficient with WinDbg for Windows debugging and dump-based troubleshooting.</p>\n<p>This time, I started by reproducing the steps in the official tutorial so I could try user-mode process debugging with WinDbg.</p>\n<p>For a full list of articles on Windows debugging and dump analysis with WinDbg, see the page below.</p>\n<p>Reference: <a href=\"/windows-windbg-001-index-en\">Debugging and Troubleshooting Techniques with WinDbg</a></p>\n<p>This article covers the following topics.</p>\n<!-- omit in toc -->\n<h2 id=\"table-of-contents\" style=\"position:relative;\"><a href=\"#table-of-contents\" aria-label=\"table of contents permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Table of Contents</h2>\n<ul>\n<li><a href=\"#what-is-windbg\">What Is WinDbg?</a></li>\n<li>\n<p><a href=\"#windbg-tutorial\">WinDbg Tutorial</a></p>\n<ul>\n<li><a href=\"#environment-used-this-time\">Environment Used This Time</a></li>\n<li><a href=\"#launching-notepadexe\">Launching Notepad.exe</a></li>\n<li><a href=\"#setting-and-loading-the-symbol-path\">Setting and Loading the Symbol Path</a></li>\n<li><a href=\"#listing-symbols\">Listing Symbols</a></li>\n<li><a href=\"#setting-a-breakpoint\">Setting a Breakpoint</a></li>\n<li><a href=\"#running-notepadexe\">Running Notepad.exe</a></li>\n<li><a href=\"#displaying-the-list-of-code-modules-loaded-in-the-process\">Displaying the List of Code Modules Loaded in the Process</a></li>\n<li><a href=\"#displaying-a-stack-trace\">Displaying a Stack Trace</a></li>\n<li><a href=\"#resuming-notepadexe\">Resuming Notepad.exe</a></li>\n<li><a href=\"#stopping-the-process-when-a-file-is-written\">Stopping the Process When a File Is Written</a></li>\n<li><a href=\"#displaying-the-list-of-threads-in-the-process\">Displaying the List of Threads in the Process</a></li>\n<li><a href=\"#getting-the-stack-trace-of-a-specific-thread\">Getting the Stack Trace of a Specific Thread</a></li>\n<li><a href=\"#ending-debugging-and-detaching-from-the-process\">Ending Debugging and Detaching from the Process</a></li>\n</ul>\n</li>\n<li><a href=\"#wrap-up\">Wrap-up</a></li>\n</ul>\n<h2 id=\"what-is-windbg\" style=\"position:relative;\"><a href=\"#what-is-windbg\" aria-label=\"what is windbg permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What Is WinDbg?</h2>\n<p>WinDbg is a tool used for debugging and troubleshooting in Windows environments.</p>\n<p>Reference: <a href=\"https://docs.microsoft.com/ja-jp/windows-hardware/drivers/debugger/getting-started-with-windows-debugging\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Getting Started with Windows Debugging - Windows drivers | Microsoft Docs</a></p>\n<p>WinDbg is mainly used for the following purposes.</p>\n<ul>\n<li>Analyzing Windows memory dumps and process dumps</li>\n<li>Live debugging in kernel mode</li>\n<li>Live debugging in user mode</li>\n</ul>\n<p>It is Microsoft’s official debugger, and it is also used by the Windows development team.</p>\n<p>One difference from the Visual Studio debugger is that WinDbg can also handle kernel-mode debugging and thread stack analysis.</p>\n<h2 id=\"windbg-tutorial\" style=\"position:relative;\"><a href=\"#windbg-tutorial\" aria-label=\"windbg tutorial permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>WinDbg Tutorial</h2>\n<p>As a first step with WinDbg, I followed the <a href=\"https://docs.microsoft.com/ja-jp/windows-hardware/drivers/debugger/getting-started-with-windbg\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">official tutorial</a>.</p>\n<p>In this tutorial, we attach WinDbg to a user-mode process and debug it.</p>\n<h3 id=\"environment-used-this-time\" style=\"position:relative;\"><a href=\"#environment-used-this-time\" aria-label=\"environment used this time permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Environment Used This Time</h3>\n<p>The environment used this time is as follows.</p>\n<ul>\n<li>Windows 10 20H2</li>\n<li>WinDbg 10.0.22000.1 AMD64 (launched with administrator privileges)</li>\n</ul>\n<h3 id=\"launching-notepadexe\" style=\"position:relative;\"><a href=\"#launching-notepadexe\" aria-label=\"launching notepadexe permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Launching Notepad.exe</h3>\n<p>After starting WinDbg in Windows, press [Ctrl+E] to open [Open Executable File], then select <code class=\"language-text\">C:\\Windows\\System32\\notepad.exe</code>.</p>\n<p>When I opened the executable file, the Command window appeared.</p>\n<h3 id=\"setting-and-loading-the-symbol-path\" style=\"position:relative;\"><a href=\"#setting-and-loading-the-symbol-path\" aria-label=\"setting and loading the symbol path permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Setting and Loading the Symbol Path</h3>\n<p>Enter the following command in the console at the bottom of the Command window.</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\"><span class=\"token punctuation\">.</span>sympath srv*</code></pre></div>\n<p>The <code class=\"language-text\">.sympath</code> command sets the symbol path.\nThe symbol path is the search location that the debugger uses when looking for symbol files.</p>\n<p>Symbol files are required for the debugger to obtain information about code modules (such as function names and variable names).</p>\n<p>Reference: <a href=\"https://docs.microsoft.com/ja-jp/windows-hardware/drivers/debugger/-sympath--set-symbol-path-\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">.sympath (Set Symbol Path) - Windows drivers | Microsoft Docs</a></p>\n<p>Now that the symbol path has been configured, run the following command.</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\"><span class=\"token punctuation\">.</span>reload</code></pre></div>\n<p>The <code class=\"language-text\">.reload</code> command clears symbol information and then reloads it.</p>\n<p>Reference: <a href=\"https://docs.microsoft.com/ja-jp/windows-hardware/drivers/debugger/-reload--reload-module-\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">.reload (Reload Module) - Windows drivers | Microsoft Docs</a></p>\n<p>Note that even when you run <code class=\"language-text\">.reload</code>, there may be no visible response.\nProceed once you see output like the following.</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">0:000> <span class=\"token punctuation\">.</span>reload\nReloading current modules\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<h3 id=\"listing-symbols\" style=\"position:relative;\"><a href=\"#listing-symbols\" aria-label=\"listing symbols permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Listing Symbols</h3>\n<p>After confirming the output above, run the <code class=\"language-text\">x notepad!*</code> command to display the symbols in the <code class=\"language-text\">Notepad.exe</code> module.\nIf no output appears here, run <code class=\"language-text\">.reload</code> again.</p>\n<p>Reference: <a href=\"https://docs.microsoft.com/ja-jp/windows-hardware/drivers/debugger/x--examine-symbols-\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">x notepad!*</a></p>\n<p>The output was close to 1,500 lines.\nThat’s quite a lot.</p>\n<h3 id=\"setting-a-breakpoint\" style=\"position:relative;\"><a href=\"#setting-a-breakpoint\" aria-label=\"setting a breakpoint permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Setting a Breakpoint</h3>\n<p>Next, using the symbol information confirmed above, set a breakpoint on the <code class=\"language-text\">wWinMain</code> function.</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">bu notepad!wWinMain</code></pre></div>\n<p>There is no particular output, but you can check the list of breakpoints with the <code class=\"language-text\">bl</code> command.\nReference: <a href=\"https://docs.microsoft.com/ja-jp/windows-hardware/drivers/debugger/bl--breakpoint-list-\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">bl (Breakpoint List) - Windows drivers | Microsoft Docs</a></p>\n<p>This confirms that a breakpoint has been set on <code class=\"language-text\">notepad!wWinMain</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">0:000> bu notepad!wWinMain\n0:000> bl\n     0 e Disable Clear  00007ff6`8402c0f8     0001 <span class=\"token punctuation\">(</span>0001<span class=\"token punctuation\">)</span>  0:<span class=\"token operator\">*</span><span class=\"token operator\">*</span><span class=\"token operator\">*</span><span class=\"token operator\">*</span> notepad!wWinMain</code></pre></div>\n<h3 id=\"running-notepadexe\" style=\"position:relative;\"><a href=\"#running-notepadexe\" aria-label=\"running notepadexe permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Running Notepad.exe</h3>\n<p>Now that the breakpoint has been set, run the application with the <code class=\"language-text\">g</code> command.\nReference: <a href=\"https://docs.microsoft.com/ja-jp/windows-hardware/drivers/debugger/g--go-\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">g (Go) - Windows drivers | Microsoft Docs</a></p>\n<p>Execution stopped when the <code class=\"language-text\">wWinMain</code> function specified by the breakpoint was called.</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">0:000> g\nModLoad: 00007ff9`9cd70000 00007ff9`9cda0000   C:\\WINDOWS\\System32\\IMM32<span class=\"token punctuation\">.</span>DLL\nBreakpoint 0 hit\nnotepad!wWinMain:\n00007ff6`8402c0f8 488bc4          mov     rax<span class=\"token punctuation\">,</span>rsp</code></pre></div>\n<h3 id=\"displaying-the-list-of-code-modules-loaded-in-the-process\" style=\"position:relative;\"><a href=\"#displaying-the-list-of-code-modules-loaded-in-the-process\" aria-label=\"displaying the list of code modules loaded in the process permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Displaying the List of Code Modules Loaded in the Process</h3>\n<p>With the process stopped at the breakpoint, run the <code class=\"language-text\">lm</code> command to check the code modules currently loaded in the process.\nReference: <a href=\"https://docs.microsoft.com/ja-jp/windows-hardware/drivers/debugger/lm--list-loaded-modules-\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">lm (List Loaded Modules) - Windows drivers | Microsoft Docs</a></p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">0:000> lm\n<span class=\"token function\">start</span>             <span class=\"token keyword\">end</span>                 module name\n00007ff6`84020000 00007ff6`8405a000   notepad    <span class=\"token punctuation\">(</span>pdb symbols<span class=\"token punctuation\">)</span>          C:\\Program Files <span class=\"token punctuation\">(</span>x86<span class=\"token punctuation\">)</span>\\Windows Kits\\10\\Debuggers\\x64\\sym\\notepad<span class=\"token punctuation\">.</span>pdb\\6539CE998C7CAFD73A8E13A54542E1121\\notepad<span class=\"token punctuation\">.</span>pdb\n00007ff9`8ef30000 00007ff9`8f1ca000   COMCTL32   <span class=\"token punctuation\">(</span>deferred<span class=\"token punctuation\">)</span>             \n00007ff9`982c0000 00007ff9`98350000   apphelp    <span class=\"token punctuation\">(</span>deferred<span class=\"token punctuation\">)</span>             \n00007ff9`9aa40000 00007ff9`9aadd000   msvcp_win   <span class=\"token punctuation\">(</span>deferred<span class=\"token punctuation\">)</span>             \n00007ff9`9ab90000 00007ff9`9ae59000   KERNELBASE   <span class=\"token punctuation\">(</span>deferred<span class=\"token punctuation\">)</span>             \n00007ff9`9aec0000 00007ff9`9afc0000   ucrtbase   <span class=\"token punctuation\">(</span>deferred<span class=\"token punctuation\">)</span>             \n00007ff9`9b010000 00007ff9`9b11b000   gdi32full   <span class=\"token punctuation\">(</span>deferred<span class=\"token punctuation\">)</span>             \n00007ff9`9b340000 00007ff9`9b362000   win32u     <span class=\"token punctuation\">(</span>deferred<span class=\"token punctuation\">)</span>             \n00007ff9`9bbc0000 00007ff9`9bcea000   RPCRT4     <span class=\"token punctuation\">(</span>deferred<span class=\"token punctuation\">)</span>             \n00007ff9`9bf20000 00007ff9`9c275000   combase    <span class=\"token punctuation\">(</span>deferred<span class=\"token punctuation\">)</span>             \n00007ff9`9c3c0000 00007ff9`9c46e000   shcore     <span class=\"token punctuation\">(</span>deferred<span class=\"token punctuation\">)</span>             \n00007ff9`9cc50000 00007ff9`9cd0e000   KERNEL32   <span class=\"token punctuation\">(</span>deferred<span class=\"token punctuation\">)</span>             \n00007ff9`9cd70000 00007ff9`9cda0000   IMM32      <span class=\"token punctuation\">(</span>deferred<span class=\"token punctuation\">)</span>             \n00007ff9`9cfd0000 00007ff9`9cffb000   GDI32      <span class=\"token punctuation\">(</span>deferred<span class=\"token punctuation\">)</span>             \n00007ff9`9d000000 00007ff9`9d1a1000   USER32     <span class=\"token punctuation\">(</span>deferred<span class=\"token punctuation\">)</span>             \n00007ff9`9d1b0000 00007ff9`9d24e000   msvcrt     <span class=\"token punctuation\">(</span>deferred<span class=\"token punctuation\">)</span>             \n00007ff9`9d290000 00007ff9`9d485000   ntdll      <span class=\"token punctuation\">(</span>pdb symbols<span class=\"token punctuation\">)</span>          C:\\Program Files <span class=\"token punctuation\">(</span>x86<span class=\"token punctuation\">)</span>\\Windows Kits\\10\\Debuggers\\x64\\sym\\ntdll<span class=\"token punctuation\">.</span>pdb\\E2BF5EA3ECAA1D5310F1E166306A0BCC1\\ntdll<span class=\"token punctuation\">.</span>pdb</code></pre></div>\n<h3 id=\"displaying-a-stack-trace\" style=\"position:relative;\"><a href=\"#displaying-a-stack-trace\" aria-label=\"displaying a stack trace permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Displaying a Stack Trace</h3>\n<p>With the process stopped, run the <code class=\"language-text\">k</code> command to display a stack trace.</p>\n<p>This time, I was able to capture the stack trace at the moment execution stopped in <code class=\"language-text\">notepad!wWinMain</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">0:000> k\n <span class=\"token comment\"># Child-SP          RetAddr               Call Site</span>\n00 00000055`5f11f7b8 00007ff6`840459b6     notepad!wWinMain\n01 00000055`5f11f7c0 00007ff9`9cc67034     notepad!__scrt_common_main_seh+0x106\n02 00000055`5f11f800 00007ff9`9d2e2651     KERNEL32!BaseThreadInitThunk+0x14\n03 00000055`5f11f830 00000000`00000000     ntdll!RtlUserThreadStart+0x21</code></pre></div>\n<h3 id=\"resuming-notepadexe\" style=\"position:relative;\"><a href=\"#resuming-notepadexe\" aria-label=\"resuming notepadexe permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Resuming Notepad.exe</h3>\n<p>If you run the <code class=\"language-text\">g</code> command once more, the paused process resumes and the Notepad application starts.</p>\n<p>In this state, the debugger becomes Busy and stops accepting additional command input.</p>\n<p>To stop the Notepad process again and continue using the debugger, click the Break button or press [Ctrl+Break].</p>\n<p>This stops the Notepad process again, and debugger operations become available once more.</p>\n<h3 id=\"stopping-the-process-when-a-file-is-written\" style=\"position:relative;\"><a href=\"#stopping-the-process-when-a-file-is-written\" aria-label=\"stopping the process when a file is written permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Stopping the Process When a File Is Written</h3>\n<p>Next, run <code class=\"language-text\">bu ntdll!ZwWriteFile</code> to set a breakpoint that interrupts the process when a file is written.</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">0:002> bu ntdll!ZwWriteFile\n0:002> bl\n     0 e Disable Clear  00007ff6`8402c0f8     0001 <span class=\"token punctuation\">(</span>0001<span class=\"token punctuation\">)</span>  0:<span class=\"token operator\">*</span><span class=\"token operator\">*</span><span class=\"token operator\">*</span><span class=\"token operator\">*</span> notepad!wWinMain\n     1 e Disable Clear  00007ff9`9d32ce60     0001 <span class=\"token punctuation\">(</span>0001<span class=\"token punctuation\">)</span>  0:<span class=\"token operator\">*</span><span class=\"token operator\">*</span><span class=\"token operator\">*</span><span class=\"token operator\">*</span> ntdll!NtWriteFile</code></pre></div>\n<p>After entering the <code class=\"language-text\">g</code> command again to resume the process, try writing and saving content in Notepad, and the process will stop.</p>\n<p>If you display a stack trace at this point, you can capture the stack trace at the time of the write.</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">0:011> k\n <span class=\"token comment\"># Child-SP          RetAddr               Call Site</span>\n00 00000055`5f8fdb78 00007ff9`9bc1f6f4     ntdll!NtWriteFile\n01 00000055`5f8fdb80 00007ff9`9bc0c641     RPCRT4!UTIL_WriteFile+0x5c\n02 00000055`5f8fdbe0 00007ff9`9bbf5863     RPCRT4!NMP_SyncSend+0x81\n03 00000055`5f8fdc60 00007ff9`9bbf2a56     RPCRT4!OSF_CCONNECTION::TransSendReceive+0xf7\n04 00000055`5f8fdcd0 00007ff9`9bbf239b     RPCRT4!OSF_CCONNECTION::SendBindPacket+0x2ee\n05 00000055`5f8fdf20 00007ff9`9bbf3ed1     RPCRT4!OSF_CCONNECTION::ActuallyDoBinding+0xeb\n06 00000055`5f8fdfd0 00007ff9`9bbf3c0e     RPCRT4!OSF_CCONNECTION::OpenConnectionAndBind+0x225\n07 00000055`5f8fe080 00007ff9`9bbf7736     RPCRT4!OSF_CCALL::BindToServer+0xce\n08 00000055`5f8fe120 00007ff9`9bbf84d6     RPCRT4!OSF_BINDING_HANDLE::InitCCallWithAssociation+0x8a\n09 00000055`5f8fe180 00007ff9`9bbf75e7     RPCRT4!OSF_BINDING_HANDLE::AllocateCCall+0x256\n0a 00000055`5f8fe2e0 00007ff9`9bca00f5     RPCRT4!OSF_BINDING_HANDLE::NegotiateTransferSyntax+0x37\n0b 00000055`5f8fe330 00007ff9`9bca3840     RPCRT4!NdrpClientCall3+0x715\n0c 00000055`5f8fe6a0 00007ff9`99bc139e     RPCRT4!NdrClientCall3+0xf0\n0d 00000055`5f8fea30 00007ff9`775c1e00     wkscli!NetWkstaGetInfo+0x5e\n0e 00000055`5f8feae0 00007ff9`83c62df6     ntlanman!NPOpenEnum+0x50\n0f 00000055`5f8fec40 00007ff9`83c61b7f     MPR!MprOpenEnumConnect+0x176</code></pre></div>\n<h3 id=\"displaying-the-list-of-threads-in-the-process\" style=\"position:relative;\"><a href=\"#displaying-the-list-of-threads-in-the-process\" aria-label=\"displaying the list of threads in the process permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Displaying the List of Threads in the Process</h3>\n<p>You can use the <code class=\"language-text\">~</code> command to get the list of threads in the process.\nReference: <a href=\"https://docs.microsoft.com/ja-jp/windows-hardware/drivers/debugger/---thread-status-\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">~ (Thread Status) - Windows drivers | Microsoft Docs</a></p>\n<p>It looks like the current Notepad process has the following 14 threads.</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">0:011> ~\n   0  Id: de4<span class=\"token punctuation\">.</span>7ac Suspend: 1 Teb: 00000055`5f35c000 Unfrozen\n   1  Id: de4<span class=\"token punctuation\">.</span>22f0 Suspend: 1 Teb: 00000055`5f36a000 Unfrozen\n   2  Id: de4<span class=\"token punctuation\">.</span>1500 Suspend: 1 Teb: 00000055`5f36e000 Unfrozen\n   3  Id: de4<span class=\"token punctuation\">.</span>198c Suspend: 1 Teb: 00000055`5f370000 Unfrozen\n   4  Id: de4<span class=\"token punctuation\">.</span>2094 Suspend: 1 Teb: 00000055`5f364000 Unfrozen\n   5  Id: de4<span class=\"token punctuation\">.</span>1d6c Suspend: 1 Teb: 00000055`5f372000 Unfrozen\n   6  Id: de4<span class=\"token punctuation\">.</span>1048 Suspend: 1 Teb: 00000055`5f368000 Unfrozen\n   7  Id: de4<span class=\"token punctuation\">.</span>1408 Suspend: 1 Teb: 00000055`5f374000 Unfrozen\n   8  Id: de4<span class=\"token punctuation\">.</span>30c Suspend: 1 Teb: 00000055`5f376000 Unfrozen\n   9  Id: de4<span class=\"token punctuation\">.</span>1b18 Suspend: 1 Teb: 00000055`5f378000 Unfrozen\n  10  Id: de4<span class=\"token punctuation\">.</span>af8 Suspend: 1 Teb: 00000055`5f37a000 Unfrozen\n<span class=\"token punctuation\">.</span> 11  Id: de4<span class=\"token punctuation\">.</span>898 Suspend: 1 Teb: 00000055`5f37e000 Unfrozen\n  12  Id: de4<span class=\"token punctuation\">.</span>1720 Suspend: 1 Teb: 00000055`5f380000 Unfrozen\n  13  Id: de4<span class=\"token punctuation\">.</span>37c Suspend: 1 Teb: 00000055`5f382000 Unfrozen</code></pre></div>\n<h3 id=\"getting-the-stack-trace-of-a-specific-thread\" style=\"position:relative;\"><a href=\"#getting-the-stack-trace-of-a-specific-thread\" aria-label=\"getting the stack trace of a specific thread permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Getting the Stack Trace of a Specific Thread</h3>\n<p>To get the stack trace of a specific thread, use the following commands in sequence.</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">~0s\nk</code></pre></div>\n<p>The <code class=\"language-text\">~0s</code> command switches to thread number 0.\nReference: <a href=\"https://docs.microsoft.com/ja-jp/windows-hardware/drivers/debugger/-s--set-current-thread-\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">~s (Set Current Thread) - Windows drivers | Microsoft Docs</a></p>\n<p>The output looked as follows.</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">0:011> ~0s\nwin32u!NtGdiGetCharABCWidthsW+0x14:\n00007ff9`9b3465e4 c3              ret\n0:000> k\n <span class=\"token comment\"># Child-SP          RetAddr               Call Site</span>\n00 00000055`5f117108 00007ff9`9b01a2ae     win32u!NtGdiGetCharABCWidthsW+0x14\n01 00000055`5f117110 00007ff9`9b01a211     gdi32full!LoadGlyphMetricsWithGetCharABCWidthsI+0x5e\n02 00000055`5f1174b0 00007ff9`9b019d60     gdi32full!LoadGlyphMetrics+0x99\n03 00000055`5f1174f0 00007ff9`8aa29016     gdi32full!CUspShapingFont::GetGlyphDefaultAdvanceWidths+0x150\n04 00000055`5f117550 00007ff9`9b020b65     TextShaping!ShapingGetGlyphPositions+0x516\n05 00000055`5f117750 00007ff9`9b0266e3     gdi32full!ShlPlaceOT+0x255\n06 00000055`5f117970 00007ff9`9b025d9b     gdi32full!RenderItemNoFallback+0x573\n07 00000055`5f117aa0 00007ff9`9b025c6b     gdi32full!RenderItemWithFallback+0xeb\n08 00000055`5f117af0 00007ff9`9b025a3f     gdi32full!RenderItem+0x3b\n09 00000055`5f117b40 00007ff9`9b027ac6     gdi32full!ScriptStringAnalyzeGlyphs+0x20f\n0a 00000055`5f117bf0 00007ff9`9b024ca2     gdi32full!ScriptStringAnalyse+0x626\n0b 00000055`5f117dc0 00007ff9`9b0246be     gdi32full!LpkCharsetDraw+0x5c2\n0c 00000055`5f117ff0 00007ff9`9d01f5f2     gdi32full!LpkDrawTextEx+0x5e\n0d 00000055`5f118060 00007ff9`9d01e9bf     USER32!DT_DrawStr+0xb6\n0e 00000055`5f118110 00007ff9`9d01eede     USER32!DT_GetLineBreak+0xf3\n0f 00000055`5f1181b0 00007ff9`9d01eb50     USER32!DrawTextExWorker+0x36e\n10 00000055`5f118300 00007ff9`6b8a6123     USER32!DrawTextW+0x40\n11 00000055`5f118370 00007ff9`6b89ac60     DUI70!DirectUI::Element::GetContentSize+0x463\n12 00000055`5f118450 00007ff9`6b8a7196     DUI70!DirectUI::Element::_UpdateDesiredSize+0x6a0\n<span class=\"token punctuation\">{</span><span class=\"token punctuation\">{</span> Omitted below <span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span></code></pre></div>\n<h3 id=\"ending-debugging-and-detaching-from-the-process\" style=\"position:relative;\"><a href=\"#ending-debugging-and-detaching-from-the-process\" aria-label=\"ending debugging and detaching from the process permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Ending Debugging and Detaching from the Process</h3>\n<p>Finally, use the <code class=\"language-text\">qd</code> command to end debugging and detach from the process.</p>\n<p>When debugging ended, the Command window closed and the paused write operation in Notepad resumed.</p>\n<h2 id=\"wrap-up\" style=\"position:relative;\"><a href=\"#wrap-up\" aria-label=\"wrap up permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Wrap-up</h2>\n<p>For now, I worked through the user-mode debugging steps from the <a href=\"https://docs.microsoft.com/ja-jp/windows-hardware/drivers/debugger/getting-started-with-windbg\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">official tutorial</a>.</p>\n<p>For other published information on Windows debugging and dump analysis with WinDbg, see the list on the following page.</p>\n<p>Reference: <a href=\"/windows-windbg-001-index-en\">Debugging and Troubleshooting Techniques with WinDbg</a></p>","fields":{"slug":"/windows-windbg-002-tutorial-en","tagSlugs":["/tag/win-dbg-en/","/tag/kernel-en/","/tag/reversing-en/","/tag/english/"]},"frontmatter":{"date":"2021-10-05","description":"","tags":["WinDbg (en)","Kernel (en)","Reversing (en)","English"],"title":"Trying the WinDbg User-Mode Debugging Tutorial","socialImage":{"publicURL":"/static/60c8ad2e26b79782f87890c91ca6d65f/windows-windbg-002-tutorial.png"}}}},"pageContext":{"slug":"/windows-windbg-002-tutorial-en"}},"staticQueryHashes":["251939775","401334301","825871152"]}