【发布时间】:2011-01-30 07:48:30
【问题描述】:
【问题讨论】:
-
你说的是哪个数字版本的gdb
【问题讨论】:
从 SVN 获取 python 查看器
svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
将以下内容添加到您的~/.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
那么打印应该就可以了:
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(/r 用于原始视图)。
【讨论】:
libstdcxx_printers 包含在最新版本的 GCC 中,因此如果您使用的是 GCC 4.5 或更高版本,则无需执行任何操作,漂亮的打印 Just Works。
(gdb) p v
$1 = std::vector of length 3, capacity 3 = {std::set with 3 elements = {
[0] = 1, [1] = 2, [2] = 3}, std::set with 2 elements = {[0] = 12,
[1] = 13}, std::set with 1 elements = {[0] = 23}}
(gdb) p v[1]
$2 = std::set with 2 elements = {[0] = 12, [1] = 13}
要禁用漂亮的打印,请使用p/r 或print/r 来获得“原始”输出。
【讨论】: