STLのコンテナをみやすく表示してくれるgdbマクロ
gdb-stl-views
% cat -n foo.cc 1 #include <map> 2 #include <vector> 3 #include <list> 4 using namespace std; 5 6 void f() { } 7 8 int 9 main() 10 { 11 map<int,double> m; 12 m[0] = 0.0; 13 m[1] = 0.1; 14 m[2] = 0.2; 15 16 vector<int> v; 17 v.push_back(1); 18 v.push_back(2); 19 v.push_back(3); 20 21 list<int> lst; 22 lst.push_back(10); 23 lst.push_back(20); 24 lst.push_back(30); 25 26 f(); 27 } % c++ -g foo.cc -o foo % gdb foo GNU gdb Fedora (6.8-37.el5) Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu"... (gdb) break f Breakpoint 1 at 0x40092c: file foo.cc, line 6. (gdb) run Starting program: /home/koie/.../foo Breakpoint 1, f () at foo.cc:6 6 void f() { } (gdb) up #1 0x0000000000400a71 in main () at foo.cc:26 26 f(); (gdb) print v $1 = {<std::_Vector_base<int,std::allocator<int> >> = { _M_impl = {<std::allocator<int>> = {<__gnu_cxx::new_allocator<int>> = {<No data fields>}, <No data fields>}, _M_start = 0x1e4690d0, _M_finish = 0x1e4690dc, _M_end_of_storage = 0x1e4690e0}}, <No data fields>} (gdb) source stl-views-1.0.3.gdb (gdb) pvector v elem[0]: $2 = 1 elem[1]: $3 = 2 elem[2]: $4 = 3 Vector size = 3 Vector capacity = 4 Element type = int * (gdb) pmap m Map type = std::map<int,double,std::less<int>,std::allocator<std::pair<const int, double> > > Use pmap <variable_name> <left_element_type> <right_element_type> to see the elements in the map. Map size = 3 (gdb) plist lst List size = 3 List type = std::list<int,std::allocator<int> > Use plist <variable_name> <element_type> to see the elements in the list. (gdb) quit