How can I access target of a std::tr1::shared_ptr in GDB. This doesn\'t work:
(gdb) p sharedPtr->variableOfTarget
If I try with the pointer
Try with
(gdb) p (*sharedPtr.get())
that function returns the a pointer to the object owned by the smart pointer.
ptr->get() not always work.
when i try ptr->get(), gdb complains for: can not resolve method ***:get() to any overloaded instance
I eventually go to /usr/include/ to find the source code of shared_ptr to see the private member.
It turns out to be
ptr._M_ptr
It works for me. Source code works for everyone.
Answer first:
p *frame._M_ptr # frame is the shared_ptr's name
I tried p (*frame.get())
, but it didn't work(frame is my shared_ptr name)
(gdb) p frame
$4 = std::shared_ptr (count 2, weak 0) 0x2ea3080
(gdb) p (*frame.get())
Cannot evaluate function -- may be inlined
then I tried to get what's in this shared_ptr, then I found this
(gdb) p frame.
_M_get_deleter __shared_ptr operator* reset unique ~shared_ptr
_M_ptr get operator-> shared_ptr use_count
_M_refcount operator bool operator= swap ~__shared_ptr
I used it's _M_ptr field, it worked.
(gdb) p *frame._M_ptr
$5 = {
...
}
I used std::shared_ptr, and gdb 7.6.