Presentation is loading. Please wait.

Presentation is loading. Please wait.

Discover, Master, InfluenceSlide 1 Debugging the World Starting with the CLR Corneliu I. Tusnea Senior Consultant, Readify It works on my machine!

Similar presentations


Presentation on theme: "Discover, Master, InfluenceSlide 1 Debugging the World Starting with the CLR Corneliu I. Tusnea Senior Consultant, Readify It works on my machine!"— Presentation transcript:

1 Discover, Master, InfluenceSlide 1 Debugging the World Starting with the CLR Corneliu I. Tusnea Senior Consultant, Readify It works on my machine!

2 Agenda (Improving) Visual Studio Debugging Production Debugging Tips & Tools Resources Discover, Master, InfluenceSlide 2

3 Visual Studio Debugging Attributes – Debug support DebuggerStepThroughAttribute DebuggerNonUserCodeAttribute – Debug enhancement DebuggerDisplayAttribute DebuggerTypeProxyAttribute DebuggerBrowsableAttribute DebuggerVisualizerAttribute Discover, Master, InfluenceSlide 3

4 Visual Studio Debugging Demo Attributes Discover, Master, InfluenceSlide 4

5 Sample Source Code [DebuggerDisplayAttribute( "Id={id} Name={firstName, nq} {lastName, nq}")] public class Customer { [DebuggerBrowsable(DebuggerBrowsableState.Never)] private int id; [DebuggerBrowsable(DebuggerBrowsableState.Never)] private string firstName; [DebuggerBrowsable(DebuggerBrowsableState.Never)] private string lastName; Discover, Master, InfluenceSlide 5

6 Improving Visual Studio Debugging Object Ids Custom breakpoints – Trace points – Breakpoint Conditions Discover, Master, InfluenceSlide 6

7 Visual Studio Debugging Demo Object Ids, Breakpoints and Trace points Discover, Master, InfluenceSlide 7

8 Production Debugging Memory dumps – Full memory dump – Mini memory dump Process crashes Start-up crashes Recovering code – Full memory dump – Mini memory dump Discover, Master, InfluenceSlide 8

9 Production Debugging Demo Taking memory dumps of processes Discover, Master, InfluenceSlide 9

10 Demo Walkthrough Vista/W2k8: - Task Manager - Right-click process - “Create Dump File” Memory dump on crash/exception: - adplus –crash –quiet –pn w3wp.exe Memory dump now: - adplus –hang –quiet –pn w3wp.exe Discover, Master, InfluenceSlide 10

11 Production Debugging Process crashes – Crash – Start-up crashes – Hang (deadlock) – Sudden death (unexpected exit) Exceptions First chance exceptions Second chance exceptions Discover, Master, InfluenceSlide 11

12 Production Debugging Demo Finding the cause of a crashing process Discover, Master, InfluenceSlide 12

13 Demo walkthrough Windbg.loadby sos mscorwks – load sos extentions !threads – check running threads ~xs – switch to thread id (x = thread id) !pe – print thread exception !dso – dump stack objects !do – dump object with address Discover, Master, InfluenceSlide 13

14 Production Debugging Demo Recovering the code from a memory dump Discover, Master, InfluenceSlide 14

15 Recovering Assemblies Discover, Master, InfluenceSlide 15 start endModule: 0125000001256000ACorns_Debugging_StartupCrashTest Method Table -> lmv m* * 800135c0public class MyClass { Method Desc -> !dumpmt 80013570private void MyFunction(string someParameter) {... 8015026fif (String.IsNullOrEmpty( someParameter )) IP -> !ip2md 801502c3throw new ApplicationException();... 801504d1 } 80014290private void MyOtherFunction() {...} } Use RetAddress from Call Stack (!clrstack) Use IP from Exception (!pe)

16 Demo walkthrough !ip2md - map instruction to method !dumpmt - show the method table lmv m* * - show details of module !savemodule - save the module Discover, Master, InfluenceSlide 16

17 Production Debugging Demo Finding crashes on start-up Discover, Master, InfluenceSlide 17

18 Start-up Crashes Start-up Crashes in Windows Services – Gflags.exe – Service has to be able to interact with desktop – Set Debugger for your ImageFile to windbg.exe Image file is the executable name This will modify the following registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT \ CurrentVersion\Image File Execution Options\ \Debugger – For processes set this value to allow long wait from SCM on start-up HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ ServicesPipeTimeout (30000000) Discover, Master, InfluenceSlide 18

19 GFlags Discover, Master, InfluenceSlide 19 gflags.exe

20 WinDbg & SOS Reference Run control – Ctrl + Break – F5 or g –.lastevent –.detach – F6 attach –.help.hh !help.NET Debug Extension: SOS –.load c:\...sos.dll –.loadby sos mscorwks Memory Dumps –.dump c:\.... Mini dump –.dump /ma c:\... Full dump Exceptions – sxe clr stop on CLR exceptions – sxi clr ignore exception – sxn clr notify but continue – !printexception (or.ecxr for native) – sx show exception types – !analyze –v analyse exception – !dae Discover, Master, InfluenceSlide 20

21 WinDbg & SOS Reference Control – bpmd module method set breakpoint – KB callstack details Threads – ~ unmanaged threads – ~##s switch thread – !threads managed Call stack – !clrstack (–a stack + parameters) – !dumpstack managed + unmanaged stack – ~*e!clrstack show CLR stack for all threads Discover, Master, InfluenceSlide 21

22 WinDbg & SOS Reference Heap – !dumpstackbobjects – !dumpheap heap info – !dumpheap -mt – !dumpheap –type type heap for a specific type – !dumpheap –type type -stat heap statistics for a type – !do address – !dumparray address (-details can help) – !gcroot address – !syncblk managed locks – !gcref – !objsize address Large Heap – !eeheap –gc – !dumpheap start end Discover, Master, InfluenceSlide 22

23 WinDbg Good to know tips: – sxe av break on access violation – sxe clr break on all clr exceptions – SRV*c:\..* http://msdl.microsoft.com/download/symbolshttp://msdl.microsoft.com/download/symbols – bp native breakpoint bp ntdll!zwterminateprocess breakpoint when process is terminated – sxe -c "!pe;!clrstack;gc" clr stop, display exception, dump stack, go – !dumpheap -type CompilerError asp.net compilation errors !dumpobject 0xxxxxxx !dumpobject errorMessageText – !dumpheap -stat -min 85000 Large Object Heap Objects – !dumpdomain -stat AdPlus (Memory dumps) – Adplus.vbs –crash –pn processname | –p processid – Adplus.vbs –hang –p|-pn Discover, Master, InfluenceSlide 23

24 Tools and Resources ACorns.Debugging Tools – FindDeadlock – FindStartupException SOS Assist SOS Extensions – http://www.stevestechspot.com/SOSEXANewDebuggingExtensionForManagedCode.aspx http://www.stevestechspot.com/SOSEXANewDebuggingExtensionForManagedCode.aspx DbgHelp (trigger memory dumps from.net code) – http://msdn.microsoft.com/en-us/library/ms679294(VS.85).aspx http://msdn.microsoft.com/en-us/library/ms679294(VS.85).aspx Hawkeye – www.acorns.com.au/projects/hawkeye/ www.acorns.com.au/projects/hawkeye/ – www.codeplex.com/hawkeye/ www.codeplex.com/hawkeye/ Good references – http://www.microsoft.com/whdc/ddk/debugging/ http://www.microsoft.com/whdc/ddk/debugging/ – http://dotnetdebug.net/category/windbg/ http://dotnetdebug.net/category/windbg/ – http://blogs.msdn.com/tess/pages/net-debugging-demos-information-and-setup- instructions.aspx http://blogs.msdn.com/tess/pages/net-debugging-demos-information-and-setup- instructions.aspx – http://www.codeproject.com/KB/debug/windbg_part1.aspx http://www.codeproject.com/KB/debug/windbg_part1.aspx Discover, Master, InfluenceSlide 24

25 Discover, Master, InfluenceSlide 25 A Readify Developer Network session By Corneliu I. Tusnea, Senior Consultant, Readify Email Address: corneliu.tusnea@readify.net RDN Website: www.readify.net/rdn Blog: http://www.acorns.com.auhttp://www.acorns.com.au


Download ppt "Discover, Master, InfluenceSlide 1 Debugging the World Starting with the CLR Corneliu I. Tusnea Senior Consultant, Readify It works on my machine!"

Similar presentations


Ads by Google