Tracepoints

Tracepoints

Rate This
  • Comments 9

This blog post is part of a series on breakpoints in the Visual Studio debugger and has been updated to reflect the experience of using Visual Studio “14”. If you are interested in details about setting tracepoints using earlier versions of Visual Studio please see the MSDN documentation.

What is a tracepoint? It is a point in the application that allows the developer to perform some action, like logging a message to the output window, and then have the option to continue execution of the program, so it does not have to break at that point during debugging.

To first illustrate how tracepoints are used, we will look at the GCD function in our managed sample. Let’s say we wanted to see all of the steps in calculating the GCD, but we didn’t want to have to stop the program at every iteration.

To get started, first create a breakpoint in the GCD function, and then hover over the breakpoint to bring up the breakpoint’s toolbar and click the “Settings…” icon.

You can also right-click on the breakpoint to bring up the context menu, and select “Settings…” or use the keyboard shortcut Alt+F9, C

This will bring up the Breakpoint Settings window. Select “Actions” and “Continue execution". In the message field you can include custom text, variables, and expressions.

You can include the value of a variable or other expression by placing it in curly braces. (To insert a curly brace or backslash into your message as text use “\{“ or “\\” respectively).

There are also many pseudo variables available to output for tracepoint messages. The following special keywords will be replaced with their current
values when the tracepoint is reached during debugging.
 

Pseudo Variable:

Description:

$ADDRESS

Current Instruction

$CALLER

Previous Function Name

$CALLSTACK

Call Stack

$FUNCTION

Current Function Name

$PID

Process Id

$PNAME

Process Name

$TID

Thread Id

$TNAME

Thread Name

You’ll notice that, the breakpoint icon takes on a diamond shape. This indicates that the action is set to continue execution automatically so the program will not stop at that location.

When the program is executed, you can view the results of the tracepoints in the Output Window.

In this way, tracepoints give you a way to print out values without having to make changes to your source code.

Additionally, if you use IntelliTrace, you can view your tracepoints in the Events View and after selecting the event, you can view the output of the tracepoint in the Locals window.

Leave a Comment
  • Please add 3 and 6 and type the answer here:
  • Post
  • Could you please fix the images? They are currently not accessible.

  • Is there a way to programmatically create/delete tracepoint which will not be visible to user? I mean, no diamond visible in left gutter and no entry in breakpoints window

  • "This indicated that it is not a tracepoint..."

    I think you meant to say "This indicated that it is not a BREAKpoint".

  • @MgSm88 Good catch, thanks.  Should be fixed now.

  • @Lukas

    There may have been some server issue when you were looking at the page.  If you refresh your browser, they should be there now.

  • @Przemo

    You can try using a Debug.Write statement if you do not want anything to appear as a breakpoint.

    msdn.microsoft.com/.../system.diagnostics.debug.write.aspx

  • Trace points are very handy.  Of course, under the covers, they really are breakpoints - they incur all of the (quite significant) overhead of pausing the program, switching into the debugger, processing the tracepoint, and restarting the program where it was paused.  Compared to writing to a log file, they're orders of magnitude slower, but you have the convenience of not needing to modify the program to add temporary logging.

  • Now, if there was an option to call out to some arbitrary managed code (eval expression with the substitutions) *that* would be incredibly useful.  (Yes, and very expensive - but that's up to the programmer to deal with that if there are any side-effects.)

  • @thelazydogsback – Not sure if you are asking for macro support or something different?  If you are asking for macros please feel free to vote for the item on the Visual Studio UserVoice site at visualstudio.uservoice.com/.../2650757-bring-back-macros.  Alternately if you are looking for a different feature please feel free to create a new entry describing the functionality you would like

Page 1 of 1 (9 items)