Following is my source code:
#include <iostream>
#include <boost/shared_ptr.hpp>
class MyClass
{
public:
MyClass()
{
i=10;
}
private:
int i;
};
int main(int argc, const char *argv[])
{
boost::shared_ptr <MyClass> obj(new MyClass());
return 0;
}
I want to examine obj in gdb, and view the value of member variable i.
This is what I get with normal print:
29 boost::shared_ptr <MyClass> obj(new MyClass());
(gdb) n
30 return 0;
(gdb) p obj
$1 = {px = 0x602010, pn = {pi_ = 0x602030}}
I tried the tip mentioned in this link , but does not work.
(gdb) call (obj.get())->print()
Cannot evaluate function -- may be inlined
Is there any other way? gdb version is 7.0.1.
Got it.!
(gdb) set print pretty
(gdb) p obj
$5 = {
px = 0x602010,
pn = {
pi_ = 0x602030
}
}
(gdb) p obj.px
$6 = (MyClass *) 0x602010
(gdb) p *(obj.px)
$7 = {
i = 10
}
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