How to access target of std::tr1::shared_ptr in GDB

百般思念 提交于 2019-12-04 03:26:34

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!