BlackWaspTM

This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

Debugging
VS 2005+

Breakpoints and Tracepoints in Visual Studio

When debugging program code it is important to be able to pause the code at a specific location. Using Visual Studio breakpoints and tracepoints, the code can be halted at a desired line or can output trace information when conditions are met.

Creating Tracepoints

The final breakpoint modification to be considered in this article is the conversion from breakpoint to tracepoint. A tracepoint is similar to a breakpoint except that it outputs messages or executes macros when the tracepoint is hit. In addition, the halting of execution of a program is optional when using a tracepoint.

To change a breakpoint to a tracepoint, right-click the breakpoint and select "When Hit..." from the menu that appears. The When Breakpoint Is Hit dialog box will appear, as pictured below:

Tracepoint dialog box

To convert the breakpoint to a tracepoint, you set a message to be printed or a macro to be executed, or both, when the tracepoint is encountered. To output a message, tick the appropriate checkbox and type the message to be printed. The message can include current variable values by surrounding the variable name with braces {}. You can also include keywords to output information about the current function, process or thread. The available keywords are listed in the dialog box.

The example shown above outputs a message to indicate that a new multiplication table has been started and the number that is being multiplied. Each time the tracepoint is encountered, this information is added to the output window in Visual Studio.

The second option in the dialog box is to specify a macro to execute when the tracepoint is hit. You may select a standard macro from the set provided by Visual Studio or you can create and use your own. Creating macros is beyond the scope of this article.

Finally, the "Continue execution" checkbox allows you to specify whether the tracepoint should also act as a breakpoint. If ticked, the message and / or macro are processed and execution continues as normal. If cleared, the tracepoint also switches the code into break mode.

The Breakpoint Window

Visual Studio provides the Breakpoint window to show the details of breakpoints and tracepoints in the current project. You can view the window by clicking the Debug menu and selecting "Windows" followed by "Breakpoints".

The breakpoint window lists all of the current breakpoints and tracepoints, including the location of the marker and any conditions set. Each breakpoint has an associated checkbox, which may be cleared to temporarily disable it. If you right-click a breakpoint, you are given access to the context-sensitive menu that permits access to the advanced settings. You can also use the various tools to delete one or all breakpoints, disable all breakpoints or view the source code at a breakpoint's location.

Breakpoint window

20 August 2008