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.
Watchpoints currently execute two orders of magnitude more slowly than other breakpoints, but this can be well worth it to catch errors where you have no clue what part of your program is the culprit.
watch expr
watch
command.
However the hardware breakpoint registers can only take two data watchpoints,
and both watchpoints must be the same kind. For example, you can set two
watchpoints with watch
commands, two with rwatch
commands, or two with awatch
commands, but you cannot set one
watchpoint with one command and the other with a different command.
will reject the command if you try to mix watchpoints.
Delete or disable unused watchpoint commands before setting new ones.
rwatch expr
rwatch
command.
awatch expr
awatch
command.
info watchpoints
info break
.
Warning: in multi-thread programs, watchpoints have only limited usefulness. With the current watchpoint implementation, GDB can only watch the value of an expression in a single thread. If you are confident that the expression can only change due to the current thread's activity (and if you are also confident that no other thread can become current), then you can use watchpoints as usual. However, GDB may not notice when a non-current thread's activity changes the expression.
Go to the first, previous, next, last section, table of contents.