Here is an extremely simplified version of my class:
Class MyClass {
public:
int sizeDesired;
};
I'm creating a vector of MyClass
instances in main:
int main(int argc, char **argv) {
std::vector<MyClass> myvec;
for(int i=0; i<10; ++i)
myvec.push_back(MyClass());
for(int i=0; i<myvec.size(); ++i)
doWork(myvec[i]);
return 0;
}
There's some memory corruption (I think) error that is causing my program to crash. I have observed that the value of MyClass::sizeDesired
is garbage when the program crashes. So, I want to set a watchpoint on each MyClass:sizeDesired
member so I can see exactly when any of these members' values changes.
Using GDB, how can I do this?
When I break after pushing all the instances of MyClass
onto the std::vector<MyClass>
in main, I then do
(gdb) watch myvec[0].sizeDesired
but GDB just hangs. It doesn't display a new command prompt (i.e., it doesn't show (gdb)
on the succeeding line... just a blank line and nothing seems to be happening).
I'm open to non-GDB based solutions. If this type of inspection/monitoring is not possible in GDB, is there an alternative tool that could be used?