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

后端 未结 3 1325
执笔经年
执笔经年 2021-02-14 12:09

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

3条回答
  •  攒了一身酷
    2021-02-14 12:34

    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.

提交回复
热议问题