Partilhar via


How to: Specify a Tracepoint/Breakpoint Action 

This topic applies to:

Visual Studio Edition

Visual Basic

C#

C++

J#

Express Edition

No

No

Yes

No

Standard Edition

Yes

Yes

Yes

Yes

Pro/Team Edition

Yes

Yes

Yes

Yes

Tracepoints are a new way of using breakpoints. A tracepoint is a breakpoint with a custom action associated with it. When the tracepoint is hit, it causes the debugger to perform the specified action instead of (or in addition to) breaking program execution. You can create a tracepoint in two different ways:

  • You can convert an existing breakpoint into a tracepoint by adding a tracepoint action. Any type of breakpoint can be converted into a tracepoint.

  • You can create a tracepoint from scratch with the New Tracepoint command.

NoteNote

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To Create a Tracepoint From Scratch

  1. In a source window, click a line where you want to set a tracepoint and choose Insert Tracepoint from Breakpoints in the shortcut menu.

  2. The When Hit dialog box appears. It contains two text boxes where you can enter custom actions: Print a message and Run a macro.

    At this point, you can accept the preselected tracepoint settings or edit them as follows:

    To create a tracepoint that prints a message, select Print a Message and enter the message text in the corresponding textbox. With Print a Message, you can use tracepoints for many of the same purposes that you would use the Trace Class, but without the need to modify your code.

    You can include programmatic information using DebuggerDisplayAttribute syntax. (See DebuggerDisplayAttribute.) For example:

    In function '{$FUNC}', on thread '{$TID}'

    —or—

    Used variable: {varName}, function name: {functionName($FUNC)}

    You can use any of the keywords shown on the When Breakpoint Is Hit dialog box. In addition, you can use two other keywords that are not shown on the dialog box: $TICK inserts the current CPU tick count, while $FILEPOS inserts the current file position.

    A default message appears in Print a Message when the When Breakpoint Is Hit dialog box opens. If you want to accept this message, just click OK.

    To run a Visual Studio automation model macro, select Run a Macro and choose a macro from the dropdown listbox.

    When you select Print a Message or Run a Macro, the Continue Execution checkbox becomes active. Select Continue Execution if you don't want the tracepoint to break execution of your program.

  3. Click OK.

To Create a Tracepoint From an Existing Breakpoint

  1. In a source, Disassembly, or Call Stack window, right-click on a breakpoint glyph and choose When Hit from the shortcut menu (Breakpoint submenu)

    —or—

    In the Breakpoints window, right-click on a breakpoint glyph and choose When Hit from the shortcut menu

  2. The When Hit dialog box appears.

  3. Click OK to accept the preselected tracepoint settings or edit them (as explained in the previous procedure).

See Also

Reference

Trace Class

Concepts

Breakpoints and Tracepoints