Debugging Tips with Visual Studio 2010
page 8 of 12
by Scott Guthrie
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 44812/ 92

TracePoints – Running a Custom Macro

In a talk I gave last week in London, someone in the audience asked whether it was possible to automatically output all of the local variables when a TracePoint was hit. 

This capability isn’t built-in to Visual Studio – but can be enabled by writing a custom Macro in Visual Studio, and then wiring up a TracePoint to call the Macro when it is hit.  To enable this, open up the Macros IDE within Visual Studio (Tools->Macros->Macros IDE menu command).  Then under the MyMacros node in the project explorer, select a module or create a new one (for example: add one named “UsefulThings”).  Then paste the following VB macro code into the module and save it:

Sub DumpLocals() 
        Dim outputWindow As EnvDTE.OutputWindow 
        outputWindow = 
        Dim currentStackFrame As EnvDTE.StackFrame 
        currentStackFrame = DTE.Debugger.CurrentStackFrame 
        outputWindow.ActivePane.OutputString("*Dumping Local Variables*" + vbCrLf) 
        For Each exp As EnvDTE.Expression In currentStackFrame.Locals 
            outputWindow.ActivePane.OutputString(exp.Name + " = " + 
exp.Value.ToString() + vbCrLf) 
    End Sub 

The above macro code loops through the current stack frame and dumps all local variables to the output window.

View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-02-27 12:21:23 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search