GDB中print方法并不能直接打印STL容器中保存的变量,其实只要http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt这个文件保存为~/.gdbinit 就可以使用它提供的方法方便调试容器
- Data type GDB command
- std::vector<T> pvector stl_variable
- std::list<T> plist stl_variable T
- std::map<T,T> pmap stl_variable
- std::multimap<T,T> pmap stl_variable
- std::set<T> pset stl_variable T
- std::multiset<T> pset stl_variable
- std::deque<T> pdequeue stl_variable
- std::stack<T> pstack stl_variable
- std::queue<T> pqueue stl_variable
- std::priority_queue<T> ppqueue stl_variable
- std::bitset<n>td> pbitset stl_variable
- std::string pstring stl_variable
- std::widestring pwstring stl_variable
如正常我使用GDB自带的print打印一个STL list容器变量list
- (gdb) p lst
- $4 = {
- <std::_List_base<int, std::allocator<int> >> = {
- _M_impl = {
- <std::allocator<std::_List_node<int> >> = {
- <__gnu_cxx::new_allocator<std::_List_node<int> >> = {<No data fields>}, <No data fields>},
- members of std::_List_base<int, std::allocator<int> >::_List_impl:
- _M_node = {
- _M_next = 0x804d008,
- _M_prev = 0x804d048
- }
- }
- }, <No data fields>}
现在我使用这个脚本提供的plist方法打印
- (gdb) plist lst
- List size = 5
- List type = std::list<int, std::allocator<int> >
- Use plist <variable_name> <element_type> to see the elements in the list.
- (gdb)
详细查看list中的元素信息
- (gdb) plist lst int
- elem[0]: $5 = 7
- elem[1]: $6 = 1
- elem[2]: $7 = 5
- elem[3]: $8 = 9
- elem[4]: $9 = 2
- List size = 5
- (gdb)
作者:redsuntim 发表于2013-9-24 15:09:32 原文链接
阅读:21 评论:0 查看评论