https://blogs.msdn.microsoft.com/visualstudioalm/2013/10/10/tracepoints/
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 2015. 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 “Actions…”
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. (Tip: Using the context menu will open the window with the Actions box already checked.)
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.