0% found this document useful (0 votes)
47 views

Advanced Debugging With Windbg and Sos: Sasha Goldshtein

The document discusses advanced debugging techniques using WinDbg and SOS. It covers how to capture crash and hang dumps, identify basic crash causes from dumps, inspect heap objects to find memory leaks, and identify deadlocked threads.

Uploaded by

indujcebala
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Advanced Debugging With Windbg and Sos: Sasha Goldshtein

The document discusses advanced debugging techniques using WinDbg and SOS. It covers how to capture crash and hang dumps, identify basic crash causes from dumps, inspect heap objects to find memory leaks, and identify deadlocked threads.

Uploaded by

indujcebala
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Advanced Debugging

with WinDbg and SOS


Sasha Goldshtein
CTO
Sela Group

@goldshtn
blog.sashag.net
ADVANCED DEBUGGING WITH WINDBG AND SOS

AN HOUR FROM NOW,


YOU’LL KNOW HOW TO:
 Capture crash and hang dumps
 Pinpoint basic crash causes from dumps
 Inspect heap objects and graphs to find
memory leaks
 Identify deadlocked threads

www.devconnections.com
ADVANCED DEBUGGING WITH WINDBG AND SOS

DUMPS 101

www.devconnections.com
ADVANCED DEBUGGING WITH WINDBG AND SOS

A DUMP IS A SNAPSHOT OF A
RUNNING PROCESS. YOU CAN SAVE
IT, MOVE IT AROUND, AND ANALYZE
IT LATER. YOU CAN’T “DEBUG” IT.

www.devconnections.com
ADVANCED DEBUGGING WITH WINDBG AND SOS

TWO TYPES OF DUMPS:


Crash Dump Hang Dump
 The program crashed  The program didn’t crash
 Yet

www.devconnections.com
ADVANCED DEBUGGING WITH WINDBG AND SOS

SYSINTERNALS PROCDUMP: TAKE


DUMPS EASILY, ANYWHERE, AND
WITH NO PUN INTENDED.

Procdump -ma -e MyApp.exe


Procdump -h -x C:\temp\myapp.exe
Procdump -c 90 -n 3 -s 5 MyApp.exe
Procdump -e 1 1234

www.devconnections.com
ADVANCED DEBUGGING WITH WINDBG AND SOS

CRASH ROOT CAUSE


FROM A DUMP

www.devconnections.com
ADVANCED DEBUGGING WITH WINDBG AND SOS

DRAG AND DROP A DUMP FILE INTO


VISUAL STUDIO. CLICK THE GREEN
BUTTON. VOILA, IT WORKS.*

* NITPICKER’S CORNER: YOU NEED SYMBOLS


AND SOURCES TO BE LINED UP PROPERLY.

www.devconnections.com
ADVANCED DEBUGGING WITH WINDBG AND SOS

“ YOU WILL INSTALL VISUAL STUDIO ON


MY BOXEN OVER MY DEAD BODY.
GOOD DAY.

I SAID “GOOD DAY”.

Joe the IT Admin


www.devconnections.com
ADVANCED DEBUGGING WITH WINDBG AND SOS

ENTER:

WinDbg SOS
 Lightweight GUI debugger  WinDbg extension for .NET
 Super-scriptable  Ships with .NET Framework
 Super-extensible  Or on the symbol server*
 Knows nothing about .NET   Knows all about .NET 

* As of CLR 4.0, for GDR versions

www.devconnections.com 10
ADVANCED DEBUGGING WITH WINDBG AND SOS

TAKE 2:

 Drag and drop a dump file into WinDbg.


Hmm. Now what?

!analyze -v !PrintException
!CLRStack .load sosex
!mk !mdt

.for (r $t0=@ebp; poi(@$t0)!=0; r


$t0=poi(@$t0)) { !mln poi(@$t0+4) }

www.devconnections.com
ADVANCED DEBUGGING WITH WINDBG AND SOS

MEMORY LEAKS: THE EASY WAY


 Not in this talk. Shell out $500 for a
decent memory profiler.

www.devconnections.com
ADVANCED DEBUGGING WITH WINDBG AND SOS

MEMORY LEAKS: THE


HARD WAY

www.devconnections.com
ADVANCED DEBUGGING WITH WINDBG AND SOS

WHAT WE NEED:

1. A list of all heap objects


2. A diff of heap objects between dumps
3. Why these heap objects won’t go
away

!dumpheap -stat !objsize


!gcroot !refs

www.devconnections.com
ADVANCED DEBUGGING WITH WINDBG AND SOS

DEADLOCKS

www.devconnections.com
ADVANCED DEBUGGING WITH WINDBG AND SOS

WHAT WE NEED:

1. What is thread X waiting for


2. (Suppose it’s sync object Y)
3. Which thread owns sync object Y

!syncblk !mwaits
!mlocks !dlk

www.devconnections.com
ADVANCED DEBUGGING WITH WINDBG AND SOS

ADDITIONAL REFERENCES

www.devconnections.com
ADVANCED DEBUGGING WITH WINDBG AND SOS

THANK YOU!

Sasha Goldshtein @goldshtn


[email protected] blog.sashag.net

www.devconnections.com 18

You might also like