如何使用 GDB 7.x 查看 STL 容器的内容
我一直在使用宏解决方案,如 此处这里一个>.但是,提到了如何在没有宏的情况下查看它们.我指的是 GDB 版本 7 及更高版本.
有人能说明一下吗?
谢谢
解决方案从SVN获取python查看器
svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
将以下内容添加到您的 ~/.gdbinit
python导入系统sys.path.insert(0, '/path/to/pretty-printers/dir')从 libstdcxx.v6.printers 导入 register_libstdcxx_printersregister_libstdcxx_printers(无)结尾
那么打印应该就可以了:
std::map地图;the_map[23] = "你好";the_map[1024] = "世界";
在 gdb 中:
(gdb) 打印 the_map$1 = std::map with 2 个元素 = { [23] = "hello", [1024] = "world" }
要返回旧视图,请使用 print/r
(/r
用于原始视图).
另请参阅:http://sourceware.org/gdb/wiki/STLSupportp>
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.
Would someone illustrate how?
Thanks
解决方案Get the python viewers from SVN
svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
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";
In gdb:
(gdb) print the_map
$1 = std::map with 2 elements = { [23] = "hello", [1024] = "world" }
To get back to the old view use print /r
(/r
is for raw).
See also: http://sourceware.org/gdb/wiki/STLSupport
相关文章