Use watchpoints (sometimes referred to as access breakpoints) to halt program execution when a specific global location is accessed. After you set a watchpoint at a key point in memory, you can halt program execution whenever that point in memory is written to or read from. You can then examine the call chain, check register and variable values, and step through your code. You can also change values and alter the flow of normal program execution.
A watchpoint must be both enabled and resolved during a debug session in order to halt program execution. The Breakpoints view indicates the status of any watchpoint using a set of common icons and checkmark status badge. These include:
In effect, a watchpoint that is enabled by the user and resolved by the debugger during program launch can halt program execution. The table below shows the various states that cause the debugger to halt program execution:
Watchpoint | Resolved |
Unresolved |
---|---|---|
Enabled | Stops execution |
No |
Disabled | No |
No |
In addition, you can use these types of watchpoints:
A watchpoint is equivalent to a memory breakpoint.
Unlike a breakpoint, a watchpoint can detect when any part of your program affects memory. For example, if a write or write/read watchpoint is set, when the program writes a new value to the address or area of memory that has the watchpoint, the debugger suspends program execution.
NOTE You cannot set a watchpoint on a local variable, because the debugger cannot detect watchpoints for variables stored on the stack or in registers.
Type | State | Icon | Explanation |
---|---|---|---|
Write | enabled | ![]() |
The watchpoint is activated for write access operations on the specific memory location and if resolved, will halt program execution on a write operation at the watchpoint. |
disabled | ![]() |
Watchpoint is disabled for the source line, debugger does not halt program execution on a write operation. |
|
Read | enabled | ![]() |
The watchpoint is activated for read access operations on the specific memory location and if resolved, will halt program execution on a read operation at the watchpoint. |
disabled | ![]() |
Watchpoint is disabled for the source line, debugger does not halt program execution on a read operation. |
|
Write/Read | enabled | ![]() |
The watchpoint is activated for both read and write access operations on the specific memory location and if resolved, will halt program execution on any read or write operation at the watchpoint. |
disabled | ![]() |
Watchpoint is disabled for the source line, debugger does not halt program execution on a read or write operation. |
A project can have a different maximum number of watchpoints, depending on the build target. The IDE generally limits the acceptable range for watchpoints to memory that it can write-protect. This range also depends on the host and on the application.
All set watchpoints appear in the Breakpoints view list.