1 / 22

Debugging the World Starting with the CLR Corneliu I. Tusnea Senior Consultant, Readify

Debugging the World Starting with the CLR Corneliu I. Tusnea Senior Consultant, Readify. It works on my machine!. Agenda. (Improving) Visual Studio Debugging Production Debugging Tips & Tools Resources. Visual Studio Debugging. Attributes Debug support DebuggerStepThroughAttribute

bisa
Download Presentation

Debugging the World Starting with the CLR Corneliu I. Tusnea Senior Consultant, Readify

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. Visual Studio Debugging • Attributes • Debug support • DebuggerStepThroughAttribute • DebuggerNonUserCodeAttribute • Debug enhancement • DebuggerDisplayAttribute • DebuggerTypeProxyAttribute • DebuggerBrowsableAttribute • DebuggerVisualizerAttribute Discover, Master, Influence

  4. Visual Studio DebuggingDemo Attributes Discover, Master, Influence

  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, Influence

  6. Improving Visual Studio Debugging • Object Ids • Custom breakpoints • Trace points • Breakpoint Conditions Discover, Master, Influence

  7. Visual Studio DebuggingDemo Object Ids, Breakpoints and Trace points Discover, Master, Influence

  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, Influence

  9. Production DebuggingDemo Taking memory dumps of processes Discover, Master, Influence

  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, Influence

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

  12. Production DebuggingDemo Finding the cause of a crashing process Discover, Master, Influence

  13. Demo walkthrough Windbg <load memory dump or attach to process> .loadbysosmscorwks – load sosextentions !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, Influence

  14. Production DebuggingDemo Recovering the code from a memory dump Discover, Master, Influence

  15. Recovering Assemblies start end Module: 01250000 01256000ACorns_Debugging_StartupCrashTest Method Table -> lmv m*<name>* 800135c0 public class MyClass { Method Desc -> !dumpmt 80013570 private void MyFunction(stringsomeParameter) { ... 8015026f if (String.IsNullOrEmpty( someParameter )) IP -> !ip2md 801502c3 throw new ApplicationException(); ... 801504d1 } 80014290 private void MyOtherFunction() {...} } Use RetAddress from Call Stack (!clrstack) Use IP from Exception (!pe) Discover, Master, Influence

  16. Demo walkthrough !ip2md <IP> - map instruction to method !dumpmt <method table> - show the method table lmv m*<module name>* - show details of module !savemodule <addr> <dll> - save the module Discover, Master, Influence

  17. Production DebuggingDemo Finding crashes on start-up Discover, Master, Influence

  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\<name of the exe>\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, Influence

  19. GFlags • gflags.exe Discover, Master, Influence

  20. WinDbg • Good to know tips: • sxeav break on access violation • sxeclr break on all clr exceptions • SRV*c:\..* http://msdl.microsoft.com/download/symbols • bpnative breakpoint • bpntdll!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 • !dumpobject0xxxxxxx • !dumpobjecterrorMessageText • !dumpheap -stat -min 85000 Large Object Heap Objects • !dumpdomain -stat • AdPlus (Memory dumps) • Adplus.vbs –crash –pnprocessname| –p processid • Adplus.vbs –hang –p|-pn Discover, Master, Influence

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

  22. 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.au Discover, Master, Influence

More Related