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

how to view contents of STL containers using GDB 7.x(如何使用 GDB 7.x 查看 STL 容器的内容)

本文介绍了如何使用 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

这篇关于如何使用 GDB 7.x 查看 STL 容器的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何使用 GDB 7.x 查看 STL 容器的内容

基础教程推荐