Tracepoints

Tracepoints

Rate This
  • Comments 9

This blog post is part of a series on breakpoints in the Visual Studio debugger.

What is a Tracepoint? It’s not really a breakpoint at all, because it doesn’t cause the execution of the program to break. Instead, it allows the developer to find select a point in in the application to information to look at later, without having to stop the execution of the program.

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 right-click on the breakpoint and select When Hit…

clip_image001

This will bring up the following dialog. Select to print a message and continue execution. In the message, you can include custom text, variables and/or expressions, as well as special information called out in the dialog.

clip_image002

You’ll notice that after you click OK, the breakpoint icon takes on a diamond shape. This indicates that it is not a breakpoint and the program will not stop at that location.

clip_image003

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

clip_image004

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 through the Events view.

clip_image005

And when selecting the event, you can view the output of the tracepoint in the Locals window.

clip_image006

Leave a Comment
  • Please add 1 and 4 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)