Set watchpoints

A watchpoint is a variable or expression that is monitored, so when it is changed or accessed the program is paused.

Program stopped at watchpoint

To add a watchpoint:

  • Right-click on the Watchpoints tab and select Add Watchpoint.

  • Right-click over a variable in the Source Code viewer then select Add Watchpoint.

  • Add watchpoints automatically by dragging a variable from the Local Variables, Current Line, or Evaluate views in to the Watchpoints tab.

The Watchpoints table

When you add a watchpoint, the Add Watchpoint dialog is displayed. You can use this dialog to apply restrictions to the watchpoint:

  • Process Group restricts the watchpoint to the chosen process group (see Process control and process groups).

  • Process restricts the watchpoint to the chosen process.

  • Expression is the variable name in the program to be watched.

  • Language is the language of the portion of the program containing the expression.

  • Trigger On allows you to select whether the watchpoint will trigger when the expression is read, written, or both.

You can set a watchpoint for either a single process, or every process in a process group.

Unlike breakpoints, watchpoints are not displayed in the Source Code viewer.

The automatic watchpoints are write-only by default.

A watchpoint is automatically removed when the target variable goes out of scope. If you are watching the value pointed to by a variable, that is, *p, you might want to continue watching the value at that address even after p goes out of scope. You can do this by right-clicking on *p in the Watchpoints tab and selecting Pin to address. This replaces the variable p with its address so the watch is not removed when p goes out of scope.

Modern processors have hardware support for a handful of watchpoints that are set to watch the contents of a memory location. Consequently, watchpoints can normally be used with no performance penalty.

Where the number of watchpoints used is over this quantity, or the expression being watched is too complex to tie to a fixed memory address, the implementation is through software monitoring, which imposes significant performance slowdown on the application being debugged.

The number of hardware watchpoints available depends on the system. The read watchpoints are only available as hardware watchpoints.

Consequently, watchpoints should, where possible, be a single value that is stored in a single memory location. While it is possible to watch the whole contents of non-trivial user defined structures or an entire array simultaneously, or complex statements involving multiple addresses, these can cause extreme application slow down during debugging.