[转] gdb 查看vector, list, map 内容

转:http://blog.chinaunix.net/uid-13982689-id-34282.html
先下载gdb_stl_utils.tar.gz, extract it, and run make. This will compile and install the necessary files in ~/.gdb (edit the Makefile if you want to use a different directory). To use the p_stl_* functions, add:

source ~/.gdb/gdb_stl_utils

to your ~/.gdbinit.

I've tested this with GCC 3.3.3 and 3.4.0, and GDB 6.0. Let me know if you have any problems with it!

如何使用请查看gdbint文件,里面描述得很详细。

注意:
比如打印vector:
1.(gdb) p vec
$1 = {
  >> = {
    _M_impl = {
      > = {
        <__gnu_cxx::new_allocator> = {}, },
      members of std::_Vector_base >::_Vector_impl:
      _M_start = 0x92ec040,
      _M_finish = 0x92ec058,
      _M_end_of_storage = 0x92ec060
    }
  }, }

2.(gdb) p_stl_vector vec->_M_impl(_M_start和_M_finish位于_M_impl具体情况可能不同)
Vector Element 0:  $2 = 0
Vector Element 1:  $3 = 1
Vector Element 2:  $4 = 2
Vector Element 3:  $5 = 3
Vector Element 4:  $6 = 4
Vector Element 5:  $7 = 100

https://github.com/brianchenming/profile/blob/master/.gdb/gdb_stl_utils

 http://www.cnblogs.com/wangkangluo1/archive/2011/09/06/2169080.html

原文地址:https://www.cnblogs.com/qiangxia/p/4689149.html