如何使用GDB 7.x查看STL容器的内容

如何使用GDB 7.x查看STL容器的内容

问题描述:

我一直在使用宏解决方案,此处 a>。但是,有一个提到如何查看他们没有宏。

I have been using the macro solution, as it is outlined here. However, there is a mention on how to view them without macros. I am referring to GDB version 7 and above.

感谢

从SVN获取python查看器

Get the python viewers from SVN

svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python

将以下内容添加到您的〜/ .gdbinit

Add the following to your ~/.gdbinit

python
import sys
sys.path.insert(0, '/path/to/pretty-printers/dir')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end

然后打印应该可以正常工作:

Then print should just work:

std::map<int, std::string> the_map;
the_map[23] = "hello";
the_map[1024] = "world";

在gdb中:

(gdb) print the_map 
$1 = std::map with 2 elements = { [23] = "hello", [1024] = "world" }

要返回旧视图,请使用 print / r

To get back to the old view use print /r (/r is for raw).

另请参阅:http://sourceware.org/gdb/wiki/STLSupport