advanced windows debugging

21
Advanced Windows Debugging Chris Ortman, Innovative Systems @chriso

Upload: chrisortman

Post on 20-May-2015

303 views

Category:

Technology


5 download

DESCRIPTION

How do you deal with issues that happen in production? Error and Event logs are helpful but often they provide little to no help with things like deadlocks and memory leaks. In this session we'll explore some low level utilities that allow us to take snapshots of running code and bring it back in house for analysis.

TRANSCRIPT

Page 1: Advanced windows debugging

Advanced Windows DebuggingChris Ortman, Innovative Systems

@chriso

Page 2: Advanced windows debugging

About meProfessional developer for 11 years

Telecom

Lots of web

Language wonk

Former Castle Contributor

User Group Founder

INETA Senior Mentor

Page 3: Advanced windows debugging

About this talk

Learn to troubleshoot systems in production using a low-level utility called windbg

Page 4: Advanced windows debugging

Sometimes things go wrong in production

Page 5: Advanced windows debugging

• Event Logs• Performance Monitor• Reproduce (Testing &

Staging)• Capture a dump of the

process and analyze

Page 6: Advanced windows debugging

True Story

Page 7: Advanced windows debugging

Obtaining a crash dump• Easiest way is with task manager

• Be careful of .NET version and platform architecture.

• Best to have them match

• Other tools• DebugDiag - Automate capture of

exceptions from IIS• ADPlus – Take dumps from the command

line• ProcDump – Capture running application

watches for thresholds

Page 8: Advanced windows debugging

Install windbg• Download from Microsoft

• Install via chocolatey

• Need to configure symbol paths

SOS - .NET Debugging extension

• Installed with .NET framework

• Must be manually copied to windbg folder

http://technet.microsoft.com/en-us/sysinternals/dd996900.aspx

C:\Program Files (x86)\Windows Kits\8.0\Debuggers\{x86,x64}

Page 9: Advanced windows debugging

Symbol Paths

symsrv*symsrv.dll*c:\localsymbols*http://msdl.microsoft.com/download/symbols

Page 10: Advanced windows debugging

Examine Heap!DumpHeap –stat

!DumpHeap –Type Person

We are looking for something with a high count of objects

Sometimes we will take 2 dumps and look for what is changing

!pe can print your exception

Page 11: Advanced windows debugging

DumpObjWe can see fields here.

Value types we see the value

Reference types we see the reference on the heap

MethodTable

EEClass

Page 12: Advanced windows debugging

DumpMTLookup for method invocation

Very fast

Page 13: Advanced windows debugging

DumpClassMore info about each type

Stuff you would get from reflection

Page 14: Advanced windows debugging

GCRootFind what is holding reference to your object

Pass an address or -all

Page 15: Advanced windows debugging

lmShows the modules loaded into your program

Page 16: Advanced windows debugging

!threadsView managed threads

~ shows all threads

~Ns – switch to a thread

~N e – do something to that thread like:~2 e !clrstack

Page 17: Advanced windows debugging

Threads that are locked

Page 18: Advanced windows debugging

!clrstack-p shows function arguments

-l shows information on local variables (no names for these, just address)

-a same as -l -p

Page 19: Advanced windows debugging

Review

• !DumpHeap – Look at all the objects in your process, memory leaks• !GCRoot – Find what is referencing the object• !GCWhere – Tells you if the runtime has tried to collect it

• !DumpObj – Examine the internals of an object, figure out behavior• !DumpMT• !DumpClass

• !threads – See whats going on right now, look for locks. Deadlocks• !clrstack – Drill into specific thread

Page 20: Advanced windows debugging

More Resources

• http://msdn.microsoft.com/en-us/library/bb190764(v=vs.110).aspx• http://www.slideshare.net/CoryFoy/debugging-net-applications-with-

windbg• http://blogs.msdn.com/tess• http://windbg.info/

Page 21: Advanced windows debugging

Thank You!

Don’t forget to rate the talk

http://tinyurl.com/rsdcc13

Further questions

@chriso

Firstnamelastname at gmail dot com