漂亮的打印不适用于 C++ stl 列表

pretty print not working for c++ stl list

在将 gdb 用于以下代码时,对于 stl 向量和字符串,漂亮的打印似乎按预期工作,但列表的输出似乎很神秘。

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

gdb 漂亮打印的输出:

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

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

UPD1:我在 x86-64

上将以下版本的 gcc 和 gdb 与 Ubuntu 16.04 一起使用
gcc 5.4.1
gdb 7.11.1

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

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

(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

很好地打印出数据结构是某些 Python 代码的一个功能(没有双关语意),extends GDB. There is a section of the GDB manual on pretty printing in GDB

事实证明,对于共享库(也可能对于静态链接库,还不完全清楚)GDB has a way to automatically load them。在我的 Fedora 25 系统上,GDB 自动加载 /usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.22-gdb.py 并且此文件加载 libstdc++ 漂亮的打印机。

联机手册在 Python 中有一个 pretty extensive section on writing your own GDB pretty printer

对于您所遇到的特定问题,libstdc++ 漂亮的打印机一定是出了问题,因为 ::std::vector 的打印机似乎已打开并正常工作,并且::std::list 的那个没有。也许这正是发生的事情。 ::std::list 的那个以某种方式被取消注册或关闭。 section on how GDB selects a pretty printer 表示可以单独启用或禁用它们以处理不工作的问题。