How to access the std :: tr1 :: shared_ptr object in GDB

How can I access the std :: tr1 :: shared_ptr object in GDB. This does not work:

(gdb) p sharedPtr->variableOfTarget 

If I try with the pointer object itself ( p sharedPtr ), I get something like this:

 $1 = std::tr1::shared_ptr (count 2) 0x13c2060 

With a normal pointer, I can do p *ptr and get all the data or p ptr->variable for only one variable.

I am on Centos 6.5, GCC 4.4.7-4.el6 and GDB 7.2-64.el6_5.2.

+8
source share
3 answers

Try

 (gdb) p (*sharedPtr.get()) 

this function returns a pointer to an object belonging to a smart pointer.

+7
source

ptr-> get () does not always work.

when I try to do ptr-> get (), gdb complains about: it is not possible to allow the ***: get () method for any overloaded instance

In the end, I go to / usr / include / to find the source code for shared_ptr to see the private member.

It turns out

ptr._M_ptr

This works for me. Source code works for everyone.

+23
source

I tried p (*frame.get()) but that didn't work (frame is my name shared_ptr)

 (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 is 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 this _M_ptr field, it worked.

 (gdb) p *frame._M_ptr $5 = { ... } 

I used std :: shared_ptr and gdb 7.6.

0
source

Source: https://habr.com/ru/post/972719/


All Articles