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

发布于 2024-08-25 16:08:12 字数 190 浏览 3 评论 0原文

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

有人能说明一下如何吗?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

归属感 2024-09-01 16:08:12

从 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

然后 print 应该可以工作:

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 表示原始)。

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

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

笨笨の傻瓜 2024-09-01 16:08:12

libstdcxx_printers 包含在最新版本的 GCC 中,因此如果您使用 GCC 4.5 或更高版本,则无需执行任何操作,即可正常打印。

(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/rprint/r 获取“原始”输出。

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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文