I am attempting to have GDB print the value of a variable when it changes.
Given an example program, I would like to get the value of x
in func
when it changes, but for the program to continue without prompt:
#include <stdio.h>
#include <stdlib.h>
int func(int x, int y);
int main(void) {
int x = 5;
int y;
y = func(x, 4);
printf("%d\n", x);
printf("%d\n", y);
return EXIT_SUCCESS;
}
int func(int x, int y) {
y *= 2;
x += y;
return x;
}
What I have attempted:
break func
commands
silent
watch x
commands
continue
end
continue
end
While this will successfully acquire the value of x
when it changes, the problem is that when leaving the scope of x
, gdb will stop to inform me that it is leaving the scope of x
and that it is deleting the watchpoint. Is there any way to set GDB to go ahead and continue execution without a user prompt upon auto-removing a watchpoint?
I came across this question: gdb: do not break when watchpoint on local variable goes out of scope However it never did receive a solution.