Setting a Watchpoint

Use the Toggle Watchpoint command to set a watchpoint on a global variable in a C/C++ editor view. A watchpoint suspends program execution when the memory location that you specify is accessed with a write or read operation and it's based on the access setting. Watchpoints can also be added directly in the Variables, Breakpoints, Outline, and the Memory Rendering views.

The debugger halts program execution on the line of source code that triggered the watchpoint. This is different than a breakpoint, which halts program execution prior to executing the line of source code on which the breakpoint is set.

    Figure 1. Add Watchpoint window

Table 1. Add Watchpoint options
Name Description
Expression to watch
If not already entered, you can enter any arbitrary memory location for watching.
Units Define the size of the units to monitor. This setting defaults to the size of the variable to watch. If an arbitrary memory address is entered, then the default unit size is set to 1 byte. Once you enable the units checkbox, you're must enter a value for it.
Access: Write/Read Check the appropriate access type to trigger the watchpoint for the specified memory location.

Setting a Watchpoint

The following steps work with C/C++ editor views, as well as the Variables, Breakpoints, and Outline views:

NOTE Watchpoints are shown in the Outline view, while breakpoints are not.

  1. Right-click any global variable in the view
  2. The global variable is highlighted in the source file.

  3. Select the Toggle Watchpoint menu item
  4. The Add Watchpoint window appears (Figure 1).

  5. Select the Access type for the watchpoint (write, read, or select both)
  6. Click to set a checkmark in the Write, Read, or both checkboxes at once.

  7. Click OK
  8. The Add Watchpoint window closes, the new watchpoint appears in the Breakpoints view list, and the appropriate watchpoint status icon appears in the marker bar next to the global variable.

Setting a Watchpoint in Memory Rendering Views

  1. Right-click any global variable address previously added to the Memory Rendering view
  2. The global variable is highlighted in the source file.

  3. Select the Add Watchpoint (C/C++) menu item
  4. The Add Watchpoint window appears (Figure 1).

  5. Select the Access type for the watchpoint (write, read, or select both)
  6. Click to set a checkmark in the Write, Read, or both checkboxes at once.

  7. Click OK
  8. The Add Watchpoint window closes, the new watchpoint appears in the Breakpoints view list, and the appropriate watchpoint status icon appears in the marker bar next to the global variable.

Related concepts
Related tasks
Related references