My class is defined in a header file, and I need to watch for its private non-static member in GDB, like this:
class foo {
int bar;
};
Set a watchpoint that will break when watch expr is read by the program. Set a watchpoint that will break when expr is either read or written into by the program. This command prints a list of watchpoints, breakpoints, and catchpoints; it is the same as info break . GDB sets a hardware watchpoint if possible.
Able to set a watchpoint on a variable in order to break a program when a variable changes. Use display to automatically print how variables change throughout the program's execution. watch allows us to stop the execution every time the value of a variable changes.
An instance variable is a variable which is declared in a class but outside of constructors, methods, or blocks. Instance variables are created when an object is instantiated, and are accessible to all the constructors, methods, or blocks in the class. Access modifiers can be given to the instance variable.
You can set watchpoint on memory address.
You should stop in your code somewhere after foo
constructor execution and print bar
variable address.
Then you can set watchpoint on address like this:
(gdb) p &bar
$1 = (int *) 0x10793ad0
(gdb) watch *0x10793ad0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With