Skip to content

Instantly share code, notes, and snippets.

@tuantmb
Forked from reinaldocoelho/DebugWithWindbg.md
Last active April 6, 2024 13:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuantmb/e2239a8cbfad39482c5478fef1a45284 to your computer and use it in GitHub Desktop.
Save tuantmb/e2239a8cbfad39482c5478fef1a45284 to your computer and use it in GitHub Desktop.
Debug on Windows using WinDbg

Links:

Get WinDbg

  • goto WDK and WinDbg downloads
  • scroll down to Standalone Debugging Tools for Windows (WinDbg)
  • Get the standalone debugging tools (WinDbg) as part of Windows 8.1 SDK
  • execute sdksetup.exe
  • just select Debugging Tools for Windows
  • install

Use WinDbg

Prepare for crash

  • Start -> All Programs -> Windows Kits -> Debugging Tools for Windows (x64) -> WinDbg (x64)
  • File -> Open -> Executable:
    • File name:C:\Program Files\mapbox-studio\resources\app\vendor\node.exe
    • Arguments: "C:\Program Files\mapbox-studio\resources\app\index.js"
    • check Debug child processes also
  • Check in Task Manager that there is only one instance of node.exe
  • Enter commands one at a time on the prompt at the bottom
.sympath SRV*C:\debugsymbols*http://msdl.microsoft.com/download/symbols
.symfix+ c:\debugsymbols
!sym noisy
.reload /f
  • wait till *BUSY* at the bottom left disappears
  • Enter commands one at a time on the prompt at the bottom
.logopen /t c:\mbslog\log.txt
.childdbg 1
.tlist
|* lm
  • now run mbs by: Debug -> Go

If you see an exception in the WinDbg command window that says ntdll32!LdrpDoDebuggerBreak+0x2c or ntdll32!LdrpDoDebuggerBreak+0x30, enter those commands:

bp ntdll!LdrpDoDebuggerBreak+0x30
bp ntdll!LdrpDoDebuggerBreak+0x2c
eb ntdll!LdrpDoDebuggerBreak+0x30 0x90
eb ntdll!LdrpDoDebuggerBreak+0x2c 0x90
----
To continue click: Debug -> Go

After the crash

  • Enter commands:
!peb
.reload /f
!teb
|* ~* kp
|* !analyze -v -f
|* lm
  • Create a dump file (might take some time): .dump /ma c:\mbslog\mbs-crash.dmp
  • exit WinDbg
  • the DMP files can be huge, but they compress really well with 7z (www.7-zip.org) and compression set to Ultra.
  • send log and 7-zipped dump files from c:\mbslog\ to developer, who pointed you to this gist

Use WinDbg on DotNet

  1. Point Symbol path for code .pdb files
  2. Add SOS.dll to WinDBG understand .Net
    • .load D:\PATH\sos.dll
    • SOS.dll was found on .Net framework folder
  3. Adding CoreClr (Not real understand, but needed)
    • .cordll -I coreclr.dll -N -ve

References

Command references

  1. !peb - Show "Dump machine" system information.
  2. !runaway - Show what is running on the "Dump time".
  3. ~s - Go focus on thread number. Command example: ~4s, moves to thread 4.
  4. kb - On thread, this command show the Stack was running on the moment.
  5. .sympath - Add references to new Symbol path, used when work with nom C code.
  6. !clrstack - Show Dotnet Stack
  7. !ip2md - Detail to point of Memory (ip2md = internal point to memory definition). Ex: "!ip2md 00007ffe4ec4910"

###General

WinDbg General

Stack Trace

Memory

!address -summary -> build memory map
!heap -s -> heap summary
!heap -stat -h 0 -> allocation statistics
!heap -srch [Size] <pattern> -> scan all heap for pattern
!heap -flt s <obj-size> -> filter heap by object size
filter all loaded modules by object size:
!for_each_module ".echo @#ModuleName;dt -v -s <obj-size>  ${@#ModuleName}!*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment