from gdb.texinfo on 11 July 1994 --> Debugging with GDB - Set Watchpoints

Go to the previous, next section.

Setting watchpoints

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
Set a watchpoint for an expression.

info watchpoints
This command prints a list of watchpoints and breakpoints; it is the same as 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 previous, next section.