You can use a watchpoint to stop execution whenever the value of an
expression changes, without having to predict a particular place
where this may happen.
Although watchpoints currently execute two orders of magnitude more slowly than
other breakpoints, they can help catch errors where in cases where
you have no clue what part of your program is the culprit.
- watch expr
-
Set a watchpoint for an expression. GDB breaks when expr
is written into by the program and its value changes.
- rwatch arg
-
Set a watchpoint that breaks when watch arg is read by the program.
If you use both watchpoints, both must be set with the rwatch command.
- awatch arg
-
Set a watchpoint that breaks when arg is read and written into by the program.
If you use both watchpoints, both must be set with the awatch command.
- info watchpoints
- This command prints a list of watchpoints and breakpoints; it's the
same as info break.
Note:
In multithreaded programs, watchpoints have only limited
usefulness. With the current watchpoint implementation, GDB
can watch the value of an expression in a single thread only. If
you're confident that the expression can change due only to the current
thread's activity (and if you're also confident that no other thread
can become current), then you can use watchpoints as usual. However,
GDB may not notice when a noncurrent thread's activity changes
the expression.