GDB - Setting Watchpoints

From EdWiki

Setting Watchpoints

  • Whereas breakpoints interrupt the program at a particular line or function, watchpoints act on variables.
  • They pause the program whenever a watched variable’s value is modified. For example, the following watch command:
(gdb) watch my_var
  • Now, whenever my_var’s value is modified, the program will interrupt and print out the old and new values.