How can I print the value of static const
class members in gdb?
Say I have:
#include <iostream>
struct foo {
static const int bar = 5;
};
int main() {
std::cout << foo::bar;
return 0;
}
How do I examine the contents foo::bar
in gdb?
I tried:
(gdb) p foo::bar
No symbol "foo" in current context.
(gdb) p 'foo::bar'
No symbol "foo::bar" in current context.
Static data members in C++. Static data member are class members that are declared using static keyword A static member has certain special characteristics These are: Only one copy of that member is created for the entire class and is shared by all the objects of that class , no matter how many objects are created.
A static member has certain special characteristics. These are: Only one copy of that member is created for the entire class and is shared by all the objects of that class, no matter how many objects are created. It is initialized to zero when the first object of its class is created.
GDB has four "standard" register names that are available (in expressions) on most machines--whenever they do not conflict with an architecture's canonical mnemonics for registers. The register names $pcand $spare used for the program counter register and the stack pointer.
In order to see the true contents of hardware registers, you must select the innermost frame (with `frame 0'). However, GDB must deduce where registers are saved, from the machine code generated by your compiler. If some registers are not saved, or if GDB is unable to locate the saved registers, the selected stack frame makes no difference.
You can't because gcc does not resolve this to a symbol but to an actual value in the assembly so gdb has nothing to look at. If you needed to you might be able to add the volatile
keyword to prevent the compiler from performing this optimization.
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