A reference to the value of a single variable.
An address cast to an appropriate data type. For example, ‘*(int *)0x12345678’ will watch a 4-byte region at the specified address (assuming an int occupies 4 bytes).
An arbitrarily complex expression, such as ‘a*b + c/d’. The expression can use any operators valid in the program’s native language (see Languages).
You can set a watchpoint on an expression even if the expression can not be evaluated yet. For instance, you can set a watchpoint on ‘*global_ptr’ before ‘global_ptr’ is initialized. GDB will stop when your program sets ‘global_ptr’ and the expression produces a valid value. If the expression becomes valid in some other way than changing a variable (e.g. if the memory pointed to by ‘*global_ptr’ becomes readable as the result of a malloc call), GDB may not stop until the next time the expression changes.
On some systems, such as most PowerPC or x86-based targets, GDB includes support for hardware watchpoints, which do not slow down the running of your program.
If the command includes a [thread thread-id] argument, GDB breaks only when the thread identified by thread-id changes the value of expr. If any other threads change the value of expr, GDB will not break. Note that watchpoints restricted to a single thread in this way only work with Hardware Watchpoints.
Ordinarily a watchpoint respects the scope of variables in expr (see below). The -location argument tells GDB to instead watch the memory referred to by expr. In this case, GDB will evaluate expr, take the address of the result, and watch the memory at that address. The type of the result is used to determine the size of the watched memory. If the expression’s result does not have an address, then GDB will print an error.
Set a watchpoint that will break when the value of expr is read by the program.
Set a watchpoint that will break when expr is either read from or written into by the program.
This command prints a list of watchpoints, using the same format as info break (see Set Breaks).
Cannot watch constant value 0x600850.
GDB sets a hardware watchpoint if possible. Hardware watchpoints execute very quickly, and the debugger reports a change in value at the exact instruction where the change occurs. If GDB cannot set a hardware watchpoint, it sets a software watchpoint, which executes more slowly and reports the change in value at the next statement, not the instruction, after the change occurs.
Set whether or not to use hardware watchpoints.
Show the current mode of using hardware watchpoints.
For remote targets, you can restrict the number of hardware watchpoints GDB will use, see set remote hardware-breakpoint-limit.
if it was able to set a hardware watchpoint.
Expression cannot be implemented with read/access watchpoint.
Sometimes, GDB cannot set a hardware watchpoint because the data type of the watched expression is wider than what a hardware watchpoint on the target machine can handle. For example, some systems can only watch regions that are up to 4 bytes wide; on such systems you cannot set hardware watchpoints for an expression that yields a double-precision floating-point number (which is typically 8 bytes wide). As a work-around, it might be possible to break the large region into a series of smaller ones and watch them with separate watchpoints.
If this happens, delete or disable some of the watchpoints.
Watching complex expressions that reference many variables can also exhaust the resources available for hardware-assisted watchpoints. That’s because GDB needs to watch every variable in the expression with separately allocated resources.
If you call a function interactively using print or call, any watchpoints you have set will be inactive until GDB reaches another kind of breakpoint or the call completes.
GDB automatically deletes watchpoints that watch local (automatic) variables, or expressions that involve such variables, when they go out of scope, that is, when the execution leaves the block in which these variables were defined. In particular, when the program being debugged terminates, all local variables go out of scope, and so only watchpoints that watch global variables remain set. If you rerun the program, you will need to set all such watchpoints again. One way of doing that would be to set a code breakpoint at the entry to the main function and when it breaks, set all the watchpoints.
In multi-threaded programs, watchpoints will detect changes to the watched expression from every thread.