漂亮的打印不适用于c + + stl列表 [英] pretty print not working for c++ stl list

查看:46
本文介绍了漂亮的打印不适用于c + + stl列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然在下面的代码中使用gdb进行了显示,但看起来对于stl向量和字符串来说,漂亮的打印效果还是可以预期的,但是list的输出似乎很隐秘.

While using gdb for the following code, it appears that pretty print works as expected for stl vector and strings but the output for list seems cryptic.

   list<int> l;
   string a = "Hello";
   vector<int> v(2,3);
   l.push_back(5);
   l.push_back(10);

gdb漂亮打印输出:

Output of gdb pretty print:

(gdb) set print pretty on
(gdb) disp v
1: v = std::vector of length 2, capacity 2 = {3, 3}
(gdb) disp a
2: a = "Hello"
(gdb) disp l
3: l = {
  <std::__cxx11::_List_base<int, std::allocator<int> >> = {
    _M_impl = {
      <std::allocator<std::_List_node<int> >> = {
        <__gnu_cxx::new_allocator<std::_List_node<int> >> = {<No data fields>}, <No data fields>}, 
      members of std::__cxx11::_List_base<int, std::allocator<int> >::_List_impl: 
      _M_node = {
        <std::__detail::_List_node_base> = {
          _M_next = 0x615c40, 
          _M_prev = 0x615c60
        }, 
        members of std::_List_node<unsigned long>: 
        _M_data = 2
      }
    }
  }, <No data fields>}

有人可以指出我在做什么错吗?

Can someone please point out what I am doing wrong?

UPD1:我在x86-64上的Ubuntu 16.04上使用以下版本的gcc和gdb

UPD1: I am using the following versions of gcc and gdb with Ubuntu 16.04 on x86-64

gcc 5.4.1
gdb 7.11.1

我尝试使用gcc 6.2.0,但是仍然存在相同的问题...

I tried using gcc 6.2.0, but the same problem remains ...

UPD2:似乎漂亮的列表打印机已启用(旁边没有[disabled](禁用))

UPD2: It appears that the pretty printer for list is enabled (does not have [disabled] next to it)

(gdb) info pretty-printer 
global pretty-printers:
  builtin
    mpx_bound128
  objfile /usr/lib/x86_64-linux-gnu/libstdc++.so.6 pretty-printers:
  libstdc++-v6
    __gnu_cxx::_Slist_iterator
    __gnu_cxx::__7::_Slist_iterator
    ..
    ..
    std::__7::forward_list
    std::__7::list
    std::__7::map

推荐答案

很好地打印出数据结构是

Printing out the data structures nicely is a function (no pun intended) of some Python code that extends GDB. There is a section of the GDB manual on pretty printing in GDB.

事实证明,对于共享库(可能还包括静态链接库,目前尚不清楚), GDB可以自动加载它们.在我的Fedora 25系统上,GDB自动加载/usr/share/gdb/auto-load/usr/lib64/libstdc ++.so.6.0.22-gdb.py ,此文件加载 libstdc ++漂亮的打印机.

It turns out that for shared libraries (and possibly for statically linked libraries too, it's not completely clear) that GDB has a way to automatically load them. On my Fedora 25 system GDB autoloads /usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.22-gdb.py and this file loads up the libstdc++ pretty printers.

在线手册中有有关编写自己的GDB的内容非常详尽漂亮的打印机(在Python中).

The online manual has a pretty extensive section on writing your own GDB pretty printer in Python.

要使您遇到特定的问题,必须将 libstdc ++ 漂亮的打印机弄得一团糟,因为那是用于 :: std :: vector 似乎已打开并且可以使用,而 :: std :: list 的那个却没有.也许这就是发生的事情.不知何故 :: std :: list 的那个已被注销或关闭.关于GDB如何选择漂亮打印机的部分说有可能分别启用或禁用它们,以处理不工作的问题.

For you to be having the specific problem you're having, something must be fairly messed up about the libstdc++ pretty printers since the one for ::std::vector appears to be turned on and working and the one for ::std::list does not. Perhaps that's exactly what happened. Somehow the one for ::std::list was de-registered or turned off. The section on how GDB selects a pretty printer says that it's possible to enable or disable them on an individual basis in order to deal with non-working ones.

这篇关于漂亮的打印不适用于c + + stl列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆