gdb: do not break when watchpoint on local variabl

2019-07-17 02:57发布

问题:

I have an application that basically creates a thread many times. I would like to watch changes to a local variable on these threads. I can install a watchpoint dynamically by setting a breakpoint after the variable was initialized, which then automatically installs a watch point whenever such a thread is run:

break somefile.c:123
commands
watch myvar
continue
end

This seems to work great, except that every time one of these threads terminates, gdb breaks with the following message:

Watchpoint 3 deleted because the program has left the block in which its expression is valid.

Which makes sense, because the local variable is going out of scope. But is there any way to make gdb not break when this happens, so that the application keeps running without me having to hit continue countless of times?