Directory Freebies VS CheatSheet Forum

RSS

Email

Translate

Home About Archive Privacy Contact Advertise Guest Post
Posted by Shahar Y on Dec 29th, 2008 | Filed under .Net, ASP.Net, C#, Unmanaged Code, Visual Studio |

bugs

We all know what breakpoints are, they tell the debugger that an application should break and pause execution, at a certain point. If we want to get certain information at this point, we need to copy it down to a paper or to the notepad. There are breakpoints which get hit hundred of times during the execution of a program, so it may be very exhausting to write down the breakpoint information each time it is hit. Well, last week, while I saw John Cunninghams session at PDC 2008 about Visual Studio Debugger Tips & Tricks, I learned something new. The Visual Studio debugger has another feature called tracepoints.

A tracepoint is a variation of a breakpoint, the difference between them is:

  • Tracepoints can log information to the debug window. You can use tracepoints for many of the same purposes for which you would use Trace, but without the need to modify your code.
  • Tracepoints can continue the execution of the program, without pausing it.

To set a tracepoint, we first have to set a breakpoint in code. Then right click on the breakpoint and select the “When Hit” context menu item:

 

image

The following screen appears, where we can add a log message for the breakpoint and tell it to continue with the program execution when it gets hit:

image

As can be seen in the image above, the log message can include the value of a variable or another expression like the current function name, call stack, thread ID… After pressing the OK button, the tracepoint will look like that:

image

This feature is very useful and can certainly save a lot of time. It came with Visual Studio 2005 but I am sure that, like me, some of you didn’t know about it, so enjoy.

Tags: , , , , , , ,

3 Responses to “Debugging With Tracepoints”


  1. O. Askari Said on Dec 31, 2008 :

    Great tip, thanks for sharing.

  2. Gadi Said on Dec 31, 2008 :

    GREAT
    this was long time ago in Texas Instruments debugger.
    we used it for generating graphs out of numeric data, for debugging signal processing.

  3. Rocjoe Said on Jan 1, 2009 :

    This rocks! For the longest time I wanted to have “trace comments” in my code, this comes closest to fitting that bill.

    The “Run a macro” checkbox is an interesting option too– I wonder if you could write one that makes a diagnostic snapshot. You could replay all the snapshots to watch your system change over time.

Post a Comment

Advertise on Dev102 Bitrix Site Manager

Read reviews and compare prices on : Laptops , Software Like Windows, Office Suites & Many More.

Advertise on Dev102
Write Article for Dev102

Write for us!

We pay for user submitted tutorials and articles that we publish. Anyone can send in a contribution

Learn More