Blogs

Paul Kimmel's Blog

Debugging with Tracepoints

     

When you press F9 in Visual Studio—or select Debug|Toggle breakpoint—a little red circle representing the breakpoint is placed in the left-hand column of the editor window adjacent to the line of code containing the break. Breakpoints used to be a literal interrupt 0x03 inserted in the code quietly. I am not sure if that is how Visual Studio ultimately does it way underneath the covers, just thought I’d throw that bit if Jeopardy trivia out there.

A variation on the Breakpoint is called a Tracepoint. A Tracepoint is represented as a red diamond in the left hand margin. You can insert a Tracepoint by right-clicking on a line of code and selecting Breakpoint|Insert Tracepoint. This option is the same as clicking an existing Breakpoint in the left margin and selecting the When Hit Count… (You can also access this feature from the Breakpoints window.) When you insert a Tracepoint the When Breakpoint Is Hit dialog is displayed (see Figure 1). If you click Print a message then you can use pre-defined constants like $FUNCTION or $TID to write trace information to the Output window. $FUNCTION represents the current function, and $TID is the thread id. (Other special keywords include $CALLER, $ADDRESS, $CALLSTACK, and $PID (process id). In the same dialog—see Figure 1—you can leave Continue execution checked, and the ‘When Breakpoint is Hit’ feature will act just like a Debug.Trace statement in your code. The final thing you can do is check Run a macro. Run a macro has a dropdownlist of existing macros you can choose from to run when the Tracepoint is hit. Visual Studio also has a Macro IDE, and you can code your own macros. If you write a macro then your macro (or macros) will also show up in the dropdownlist for the Run a macro section.

image
Figure 1: The Tracepoint dialog is part of the Visual Studio Debugging environment. 

Given the (default) settings shown in the When Breakpoint Is Hit in Figure 1 and the code in Listing 1, the Output window in the IDE will contain the content shown in Figure 1.

Listing 1: A simple ‘Jello Mold’ style demo with the Tracepoint as configured in Figure 1.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TracePointDemo
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("This is a test!");
      Console.ReadLine();

    }
  }
}

image
Figure 2:  The Tracepoint writes the literal text and replaces the special keywords with their values, in this instance the function name and thread id is displayed in the Output window.

Published Jun 18 2009, 06:32 PM by Paul Kimmel (DevExpress)
Bookmark and Share

Comments

 

Matthew said:

Cool feature; thanks for point it out.

June 18, 2009 4:08 PM
 

Paul Kimmel (DevExpress) said:

You are welcome Matthew.

June 18, 2009 10:34 PM
 

Robert O'Brien said:

Yes, thanks. It's not something I've come across before.

June 19, 2009 3:36 AM
 

Paul Kimmel (DevExpress) said:

Glad to hear it. There is a longer piece on Javascript debugging that will be on Informit.com if you are interested. Thanks for reading,

Paul

June 19, 2009 9:24 AM
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.