#include <stdio.h>
typedef struct ThingStruct {
int arr[8];
int after;
} Thing;
void foo(int i) {
Thing thing;
int* ip = &thing.after;
thing.after = 12345;
printf("beforehand\n");
thing.arr[i] = 55;
printf("done\n");
}
int main() {
foo(8);
}
This code changes thing.after
by accidentally going off the end of the array. I want to try to find the line where where thing.after
is changing by using gdb. So I compile with -g , put a breakpoint on line 12, then put a watchpoint on thing.after
, but the watchpoint doesn't trigger, even though putting a breakpoint on line 14 does show that thing.after
did change.
I even tried taking the address of thing.after
and setting a watchpoint on that, but it still does not trigger.