我有测试程序如下图所示:如何在gdb中查看智能指针的内部数据?
#include<memory>
#include<iostream>
using namespace std;
int main()
{
shared_ptr<int> si(new int(5));
return 0;
}
调试它:
(gdb) l
1 #include<memory>
2 #include<iostream>
3 using namespace std;
4
5 int main()
6 {
7 shared_ptr<int> si(new int(5));
8 return 0;
9 }
10
(gdb) b 8
Breakpoint 1 at 0x400bba: file testshare.cpp, line 8.
(gdb) r
Starting program: /home/x/cpp/x01/a.out
Breakpoint 1, main() at testshare.cpp:8
8 return 0;
(gdb) p si
$1 = std::shared_ptr (count 1, weak 0) 0x614c20
,只打印出的si
指针类型的信息,但如何获取存储在它的值(这种情况下5
)? 如何在调试过程中检查si
的内部内容?
你是什么意思与*“在si商店”*? int''si的值指向? –
[如何在GDB中访问std :: tr1 :: shared \ _ptr的目标](https://stackoverflow.com/questions/24917556/how-to-access-target-of-stdtr1shared-ptr-in -gdb)| 'unique_ptr':https://stackoverflow.com/questions/22798601/how-to-debug-c11-code-with-unique-ptr-in-ddd-or-gdb –