slide1 n.
Download
Skip this Video
Download Presentation
Debugging the World Starting with the CLR Corneliu I. Tusnea Senior Consultant, Readify

Loading in 2 Seconds...

play fullscreen
1 / 22

Debugging the World Starting with the CLR Corneliu I. Tusnea Senior Consultant, Readify - PowerPoint PPT Presentation


  • 422 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Debugging the World Starting with the CLR Corneliu I. Tusnea Senior Consultant, Readify' - paul2


Download Now 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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1

Debugging the World

Starting with the CLR

Corneliu I. Tusnea

Senior Consultant, Readify

It works on my machine!

Discover, Master, Influence

agenda
Agenda
  • (Improving) Visual Studio Debugging
  • Production Debugging
  • Tips & Tools
  • Resources

Discover, Master, Influence

visual studio debugging
Visual Studio Debugging
  • Attributes
    • Debug support
      • DebuggerStepThroughAttribute
      • DebuggerNonUserCodeAttribute
    • Debug enhancement
      • DebuggerDisplayAttribute
      • DebuggerTypeProxyAttribute
      • DebuggerBrowsableAttribute
      • DebuggerVisualizerAttribute

Discover, Master, Influence

visual studio debugging demo

Visual Studio DebuggingDemo

Attributes

Discover, Master, Influence

sample source code
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

improving visual studio debugging
Improving Visual Studio Debugging
  • Object Ids
  • Custom breakpoints
    • Trace points
    • Breakpoint Conditions

Discover, Master, Influence

visual studio debugging demo1

Visual Studio DebuggingDemo

Object Ids, Breakpoints and Trace points

Discover, Master, Influence

production debugging
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

production debugging demo

Production DebuggingDemo

Taking memory dumps of processes

Discover, Master, Influence

demo walkthrough
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

production debugging1
Production Debugging
  • Process crashes
    • Crash
    • Start-up crashes
    • Hang (deadlock)
    • Sudden death (unexpected exit)
  • Exceptions
      • First chance exceptions
      • Second chance exceptions

Discover, Master, Influence

production debugging demo1

Production DebuggingDemo

Finding the cause of a crashing process

Discover, Master, Influence

demo walkthrough1
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

production debugging demo2

Production DebuggingDemo

Recovering the code from a memory dump

Discover, Master, Influence

recovering assemblies
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

demo walkthrough2
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

production debugging demo3

Production DebuggingDemo

Finding crashes on start-up

Discover, Master, Influence

start up crashes
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

gflags
GFlags
  • gflags.exe

Discover, Master, Influence

windbg
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

tools and resources
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

slide22

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