How can I set a breakpoint on a variable?

Ever had some code where a pointer was overwritten, causing a horrible crash? Here's how you can set a watchpoint in the debugger to find it.


watch *

will cause gdb to break whenever the memory at is changed. Thanks to Eric Albert (http://rescomp.stanford.edu/~ejalbert/) for this tip.
If you're seeing a pointer randomly get stomped on, try using a watchpoint.