Debugging the World
1 / 22

Debugging the World - PowerPoint PPT Presentation

  • 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

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

PowerPoint Slideshow about 'Debugging the World' - paul2

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

Debugging the World

Starting with the CLR

Corneliu I. Tusnea

Senior Consultant, Readify

It works on my machine!

Discover, Master, Influence


  • (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


Discover, Master, Influence

Sample source code
Sample Source Code


"Id={id} Name={firstName, nq} {lastName, nq}")]

public class Customer



private int id;


private string firstName;


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


- 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


<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


Use IP from Exception


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.exe

Discover, Master, Influence


  • Good to know tips:

    • sxeav break on access violation

    • sxeclr break on all clr exceptions

    • SRV*c:\..*

    • bpnative breakpoint

      • bpntdll!zwterminateprocess breakpoint when process is terminated

    • sxe -c "!pe;!clrstack;gc" clr stop, display exception, dump stack, go

    • !dumpheap -type CompilerError 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


  • DbgHelp (trigger memory dumps from .net code)


  • Hawkeye



  • Good references





Discover, Master, Influence

A Readify Developer Network session

By Corneliu I. Tusnea, Senior Consultant, Readify

Email Address: [email protected]

RDN Website:


Discover, Master, Influence