who’s afraid of windbg

22
Dror Helper [email protected] | http:// blog.drorhelper.com | @dhelper Who’s afraid of WinDBG?

Upload: dror-helper

Post on 17-Jul-2015

706 views

Category:

Technology


6 download

TRANSCRIPT

Page 1: Who’s afraid of WinDbg

Dror Helper

[email protected] | http://blog.drorhelper.com | @dhelper

Who’s afraid of WinDBG?

Page 2: Who’s afraid of WinDbg

About.Me

• Senior consultant @CodeValue

• Developing software (professionally) since 2002

• Clean coder

• Test Driven Developer

• Blogger: http://blog.drorhelper.com

Page 3: Who’s afraid of WinDbg

How I Learned to Stop Worrying and Love WinDbg

From Wikipedia Commons

Page 4: Who’s afraid of WinDbg

When we think about debugging

Page 5: Who’s afraid of WinDbg

Unfortunately

If (Production && Visual studio)

{

SysAdmin = VeryAngry;

Customer != Permission;

Application = NotWorking;

Debug != DateTime.Now;

}

Page 6: Who’s afraid of WinDbg

WinDbg to the rescue

Post mortem analysis of crash/hang dumps

Inspect heap and find memory leaks

Discover deadlocks

Learn more about your application

Page 7: Who’s afraid of WinDbg

Basic commands

| list all processes

|. current process

|<x>s switch to process

~ list all threads

~. current thread

~<n>s – switch to thread

k call stack (unmanged)~* all threads~* k – call stack for all threads

Page 8: Who’s afraid of WinDbg

Wait, you’re forgot something

For proper debugging you’ll need symbols

1. lm show all modules + symbol information

2. .symfix + .reload –f

3. ld Loads symbols for the specified module

Or use

File Symbol file path

Page 9: Who’s afraid of WinDbg

ICanHasWindows!

Page 10: Who’s afraid of WinDbg

PART I – CRASH ANALYSIS

11

Page 11: Who’s afraid of WinDbg

Analyzing Crush dump

A minidump is a snapshot of an application state:{

Process(s)Thread(s)Module(s)Register(s)Memory infoHandlesCall stack…

}

Page 12: Who’s afraid of WinDbg

Creating MiniDumps

WinDbg

Task Manager/ProcEx

ADPlus (Debugging tools for windows)

ProcDump (sysinternals)

Page 13: Who’s afraid of WinDbg

sos.dll

WinDBG extension

Knows .NET

Ships with .NET framework/symbol server

.loadby sos mscorwks (.net 3.5 or earlier)

.loadby sos clr (.net 4.0 or later)

Page 14: Who’s afraid of WinDbg

Now what?

1. Load MiniDump in WinDBG

2. Symbols!

3. Load sos.dll

4. !analyze –v

Page 15: Who’s afraid of WinDbg

More crash analysis commands (sos)

!printexception

!threads

!dae (dump all exceptions)

!dso (dump stack objects)

!clrstack

-p (shows parameters and values)

-l (show locals)

-a (same as –p –l)

Page 16: Who’s afraid of WinDbg

PART II - INVESTIGATING MEMORY ISSUES

17

Page 17: Who’s afraid of WinDbg

Finding memory issues

1. Look at heap

2. List all objects

3. Dive in to see specific object

4. Compare with previous results

!dumpheap -stat

!dumpheap –type

!do

!gcroot

Page 18: Who’s afraid of WinDbg

Other memory related commands

!FinalizeQueue!objsize!GCHandleLeaks

!dumpgen!gcgen!refs!mk!mdt

Page 19: Who’s afraid of WinDbg

PART III – DEADLOCK DETECTION

20

R1

R2

P2P1

Page 20: Who’s afraid of WinDbg

Deadlock detection

1. .load <folder>\sosex.dll

2. !dlk

Other options:!syncblk/!DumpHeap –thinlockPlain old !clrstack!mlocks!mwaits

Page 21: Who’s afraid of WinDbg

Making WinDBG user friendly(ier)

.cmdtree <cmd file>

.prefer_dml 1

Page 22: Who’s afraid of WinDbg

Dror Helper

C: 972.05.7668543

e: [email protected]

B: blog.drorhelper.com