GDB: How to force a watchpoint to not be deleted after a function returned?
Watchpoints on function-local variables usually get removed upon the function return, with a message «Watchpoint 7 deleted because the program has left the block in». Illustration: struct mystruct{ int a, b, c; }; void MyFunc(){ mystruct obj; obj.a = 2; } int main(){ MyFunc(); } gdb session example (gdb) b 7 Breakpoint 1 at 0x4004f1: file /tmp/test2.cpp, line 7. (gdb) r Starting program: /tmp/test2 Breakpoint 1, MyFunc () at /tmp/test2.cpp:7 7 obj.a = 2; (gdb) wa obj Hardware watchpoint 2: obj (gdb) c Continuing. Hardware watchpoint 2: obj Old value = {a = 4195600, b = 0, c = 4195328} New