Prevent gdb from stopping at watchpoints
file main.c:
#include <stdio.h>
int main()
{
int i;
for (i=0; i<30 ;i++) {
printf ("%d\n", i);
}
return 0;
}
In gdb, I usually set a breakpoint, then specify a watchpoint as command to be executed on that breakpoint:
(gdb) break main
Breakpoint 1 at 0x4004b0: file main.c, line 6.
(gdb) command
Type commands for when breakpoint 2 is hit, one per line.
End with a line saying just "end".
>watch i
>end
Execution is gonna stop whenever the watched variable is changed, the problem is that there is no way(to my knowledge) to tell gdb to just print the value of the watched variable and continue because it is a nested watchpoint. If it was a standalone watchpoint this could easily be done using command 'continue' (when I'm in the scope if main()):
(gdb) watch i
Hardware watchpoint 2: i
(gdb) command
Type commands for when breakpoint 2 is hit, one per line.
End with a line开发者_运维知识库 saying just "end".
>continue
>end
So, is there a way for gdb not to stop on a nested watchpoint, and only print the value change? Or better yes, to specify commands to be executed on nested watch/breakpoints?
I further tried 'set complaints 0' and 'set confirm off' in gdb but to no avail
GDB has no concept of nested watchpoints. All breakpoints and watchpoints are at the top level, regardless of where you've set them.
Here is what you want:
(gdb) break main
Breakpoint 1 at 0x40052c: file t.c, line 6.
(gdb) commands
>watch i
>commands
>c
>end
>c
>end
This sets command list on breakpoint 1:
watch i
continue
And separate command list on watchpoint (when it is created):
continue
精彩评论