3.2.6. Using GDB watchpoints to stop execution on data access and changes
GDB watchpoints pause execution when data changes or is accessed. Use them to debug unexpected variable corruption when the cause is unknown. Setting a watchpoint stops the program at the exact moment of access to inspect the state and find the root cause.
Procedure
To place a watchpoint for data change (write):
(gdb) watch expressionReplace expression with an expression that describes what you want to watch. For variables, expression is equal to the name of the variable.
To place a watchpoint for data access (read):
(gdb) rwatch expressionTo place a watchpoint for any data access (both read and write):
(gdb) awatch expressionTo inspect the status of all watchpoints and breakpoints:
(gdb) info brTo remove a watchpoint:
(gdb) delete numReplace the num option with the number reported by the
info brcommand.