gdb查看C++的容器

来源:互联网 发布:c语言的书哪本比较好 编辑:程序博客网 时间:2024/05/16 16:13

转自:http://blog.csdn.net/flykobesummer/article/details/5268206

GDB的自定义命令非常有用,通过自定义命令,直接操作容器中的数据,可以方便的查看STL容器中的数据。

这个链接dbinit_stl_views 是Dan C Marinescu 写的查看STL容器的自定义命令(如果不适合你的STL版本的话,可以自行修改)。把它添加到你的.gdbinit中,就可以方便的查看STL容器了。它提供了查看vector,list,map,multimap,set,multiset,deque,stack,queue,priority_queue,bitset,string,widestring等对象的方法,非常好用!

dbinit_stl_views 连接地址:http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt

把内容粘贴到/home/your/.gdbinit

(gdb) pmap mReasonIndex
Map type =
std::map<long int,std::basic_string<char, std::char_traits<char>, std::allocator<char> >,std::less<long int>,std::allocator<std::pair<const long int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >
Use pmap <variable_name> <left_element_type> <right_element_type> to see the elements in the map.
Map size = 1
(gdb) pmap mReasonIndex long char*
elem[0].left: $38 = 1300000000
elem[0].right: $39 = 0x579688 "社圲14o 眲24/234蜲34/234蜲34/234 眲10?山"
Map size = 1

原创粉丝点击