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

时间:2022-04-24 16:41:34

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.

我一直在使用宏解决方案,如此处所述。但是,提到了如何在没有宏的情况下查看它们。我指的是GDB版本7及更高版本。

Would someone illustrate how?

有人会说明怎么样?

Thanks

谢谢

2 个解决方案

#1


21  

Get the python viewers from SVN

从SVN获取python查看器

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

Add the following to your ~/.gdbinit

将以下内容添加到〜/ .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中:

(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).

要返回旧视图,请使用print / r(/ r表示原始)。

See also: http://sourceware.org/gdb/wiki/STLSupport

另见:http://sourceware.org/gdb/wiki/STLSupport

#2


2  

The libstdcxx_printers are included with recent versions of GCC, so if you're using GCC 4.5 or later then you don't need to do anything, pretty printing Just Works.

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}

To disable the pretty printing use p/r or print/r to get "raw" output.

要禁用漂亮的打印,请使用p / r或print / r来获得“原始”输出。

#1


21  

Get the python viewers from SVN

从SVN获取python查看器

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

Add the following to your ~/.gdbinit

将以下内容添加到〜/ .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中:

(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).

要返回旧视图,请使用print / r(/ r表示原始)。

See also: http://sourceware.org/gdb/wiki/STLSupport

另见:http://sourceware.org/gdb/wiki/STLSupport

#2


2  

The libstdcxx_printers are included with recent versions of GCC, so if you're using GCC 4.5 or later then you don't need to do anything, pretty printing Just Works.

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}

To disable the pretty printing use p/r or print/r to get "raw" output.

要禁用漂亮的打印,请使用p / r或print / r来获得“原始”输出。