Power Debugging

Advanced .NET Debugging 

John Robbins 
john@wintellect.com

Consulting & Debugging

- Architecture, analysis, and design services

- Full Lifecycle custom software development

- Content creation

- Project management

- Debugging & performance tuning

Training

- On-site instructor-led training

- Virtual instructor-led training

- Devscovery conferences

About the Presenter – John Robbins 

Session Code 

Prerequisites 

Turn off Just My Code 

Setting Debugging Properties 

What’s that VSHOST thing? 

Debugging Partially Trusted 

Debugging EXE Programs Without Compiling 

Debugging EXE Program without Compiling 

The .SUO Problem 

Advanced Breakpoints 

Before Setting Advanced Breakpoints 

Breakpoint Window Codes 

Glyph Meaning
  Normal breakpoint [enabled and disabled]
  Advanced BP (hit count, condition, filter) property set
  Mapped BP in ASP/ASP.NET and mapped to an HTML page
  Normal tracepoint
  Advanced tracepoint (hit count, condition, filter) property set
  Mapped TP in ASP/ASP.NET and mapped to an HTML page
  Breakpoint or tracepoint error (the BP or TP will never be set)
  Breakpoint or tracepoint warning (generally means the source location is not currently in any loaded module)

Location Breakpoints 

Advanced Location Breakpoints 

Advanced Location Breakpoints (cont.) 

Sub Expression Breakpoints 

Sub Expression Breakpoints 

Quickly Breaking on Any Function 

Quickly Breaking on Any Function (cont.) 

Choose Breakpoints Dialog 

Choose Breakpoints Dialog (cont.) 

Setting Breakpoints without Source 

Setting Breakpoints without Source (cont.) 

Setting Breakpoints without Source (cont.) 
 
 
 

Setting Breakpoints without Source (cont.) 

Setting Breakpoints without Source (cont.) 

Fun with the Find Combo Box 

Fun with the Find Combo Box (cont.) 

 
 
 
 

Location Breakpoint Modifiers 

Breakpoint Hit Count 

Breakpoint Hit Count Steps 

Breakpoint Hit Count Steps (cont.) 

Breakpoint Condition 

Breakpoint Condition Steps 

Breakpoint Condition Steps (cont.) 

Be Careful Setting Breakpoint Conditionals 

 
 
 
 

int i = 0 ; 
for ( i = 0 ; i < 10 ; i++ ) 
{

    Console.WriteLine ( “i = {0}” , i ) ; 
}

What Does It Mean? 

Assertions On the Fly 

Assertions On the Fly (cont.) 

 

#if DEBUG 
        public bool CheckName ( ) 
        { 
            if ( null == m_Name ) 
            { 
                return ( true ) ; 
            } 
            return ( false ) ; 
        } 
#endif

Filter Breakpoint Modifier 

Tracepoints 

The Watch Window (AKA Expression Evaluator) 

Calling Methods in the Watch Window 

Calling Methods in the Watch Window (cont.) 

Great Testing Trick 

What If the Expression Uses Objects? 

 
 
 
 

if ( false == String.IsNullOrEmpty ( ae.Name ) ) ... 

SomeClass x = new SomeClass ( ) ;

Data Tips/Watch Window Tricks 

What Generation is This Object In? 

 
 
 

Watch Window Format Specifiers 

 
Specifiers Format
,d Decimal integer
,h Hexadecimal integer
,nq String not bound by quotes

Watch Window Pseudovariables 

 
 
 
 
 
 

Auto Expanding Your Own Types 

Using DebuggerDisplayAttribute 

 
 
 

[DebuggerDisplay ( "{_Real}.{_Imaginary}i" )] 
public class ComplexNumber { . . .}

Using DebuggerDisplayAttribute (cont.) 

 
 
 

[DebuggerDisplay(“Object {count - 2}: {(flag) ? \"yes\" : \"no\"}”)]

Advanced DebuggerDisplayAttribute 

 

[DebuggerDisplay ( "{value}" , Name = "{key}" )] 
class KeyValuePairs

Advanced DebuggerDisplayAttribute (cont.) 

Advanced DebuggerDisplayAttribute (cont.) 

 

[DebuggerDisplay ( "{_Real}.{_Imaginary}i" )] 
public class ComplexNumber 

    [DebuggerBrowsable ( DebuggerBrowsableState.Never )] 
    private int _Real = 0;

     
    public int Real  
    { get { return ( _Real ) ; }  
      set { _Real = value ; }    } 
. . .

Advanced DebuggerDisplayAttribute (cont.) 

Expanding Types with No Source 

 
 
 
 

[assembly: DebuggerDisplay ( "Count={Count}" , 
                            Target = typeof ( WebCaching.Cache ) )]

Default Visualizers 

 
 
 
 
 
 

Custom Visualizers 

Installing Custom Visualizers 

Writing Visualizers 

Writing Visualizers (cont.) 

 

[assembly: DebuggerVisualizer (  
         typeof ( Wintellect.Visualizers.ImageVisualizer ) ,

         typeof ( VisualizerObjectSource )                 ,

         Target = typeof ( System.Drawing.Image )          ,

         Description = "Wintellect Image Visualizer" )      ]

Writing Visualizers (cont.) 

 

protected override void Show (  
                    IDialogVisualizerService  windowService ,  
      IVisualizerObjectProvider objectProvider ) 

   // This is all it takes to get the actual object from the  
   // debuggee address space into the debugger.   
   // How simple is that!?

   Image dbgImage = (Image)objectProvider.GetObject ( );

 
   // Create your dialog here.. 
 
 // Show it. 
    windowService.ShowDialog ( form ); 
}

Writing Visualizers (cont.) 

 

public static void TestImageVisualizer ( object itemToVisualize ) 
{

    VisualizerDevelopmentHost visualizerHost =

       new VisualizerDevelopmentHost ( itemToVisualize ,

                                       typeof ( ImageVisualizer ) );

    visualizerHost.ShowVisualizer ( );

}

Cool Free Visualizers 

Set Next Statement Command 

Using Set Next Statement Command 

Step Over Properties and Operators 

 

Threads Window

Threads Window (cont.) 

 
 
 
 

The .NET Reference Source Code  

The .NET Reference Source Code (cont.) 

The .NET Reference Source Code (cont.) 

Problems with .NET Reference Source Downloading 

 

netmassdownloader  
  -d "C:\Program Files\Reference Assemblies\Microsoft\Framework\v4.0"  
  -d C:\windows\Microsoft.NET\Framework\v4.0.30128

Debugging Exceptions 

 
 
 
 
 
 
 

Exceptions Handled by the Debugger 

The Debugging Tricks with Exceptions 

Adding Your Own Exceptions 

Mini Dumps with VS 

IntelliTrace: Why VS 2010 ROCKS! 

Initially Setting up IntelliTrace 

Initially Setting up IntelliTrace (cont.) 

IntelliTrace Usage Hints 

 
 
 
 
 

IntelliTrace Usage Oddness 

Remote Debugging 

Remote Machine Initial Setup 

 
 
 

Local Machine Initial Setup 

Using MSVSMON.EXE as a Service 

Setting Up a Project 

Where Do the PDB Files Go? 

Remote Debugging Troubleshooting 

Questions? 

john@wintellect.com