I have not done much C ++ debugging in gdb, so this is probably all the known issues.
The problem with your watchpoint is apparently caused by the inability of gdb to actually execute some methods, such as the [] operator or method (). You can try this by simply printing myvec.at (0). This test seems to be missing from the watchpoint code, and it freezes gdb. (This is probably a known gdb bug, but I will check.)
Now a workaround. You can access the nth element of a vector using:
(MyClass*)(myvec._M_impl._M_start+n)
For sizeDesired, which will then be:
(((MyClass*)(myvec._M_impl._M_start+n))->sizeDesired)
Adding a watchpoint to this expression still freezes gdb. But printing works, so if you do something like:
print &(((MyClass*)(myvec._M_impl._M_start+3))->sizeDesired)
You will get a pointer to the field you want to see. Something like this will print: $ 1 = (int *) 0x40508c Now it prints:
watch *((int*)0x40508c) continue
Access to hardware (read / write) watchpoint 3: ((int) 0x40508c) ...
BTW: Ideas on how to print std containers were ripped out from http://sourceware.org/ml/gdb/2008-02/msg00064/stl-views.gdb .
source share