python - GDB打印STL数据

标签 python c++ printing stl gdb

按照本网站给出的说明进行操作后:https://sourceware.org/gdb/wiki/STLSupport GDB除了打印出大量无用信息外,仍然无法像vector一样打印STL容器的内容。当 GDB 加载时,我也得到以下错误,我认为这与我放入 ~/.gdbinit

的 Python 有关
Traceback (most recent call last):
  File "<string>", line 4, in <module>
  File "/Users/mayankp/gdb_printers/python/libstdcxx/v6/printers.py", line 1247, in register_libstdcxx_printers
    gdb.printing.register_pretty_printer(obj, libstdcxx_printer)
  File "/usr/local/share/gdb/python/gdb/printing.py", line 146, in register_pretty_printer
    printer.name)
RuntimeError: pretty-printer already registered: libstdc++-v6
/Users/mayankp/.gdbinit:6: Error in sourced command file:
Error while executing Python code.

最佳答案

When GDB loads, I also get the following errors...

它看起来像您在 https://sourceware.org/gdb/wiki/STLSupport 上遵循的说明现在无效。如果你查看 svn log,你会看到最近在 __init__.py 中添加了 pretty-print 的注册:

------------------------------------------------------------------------
r215726 | redi | 2014-09-30 18:33:27 +0300 (Вт., 30 сент. 2014) | 4 lines

2014-09-30  Siva Chandra Reddy  <sivachandra@google.com>

        * python/hook.in: Only import libstdcxx.v6.
        * python/libstdcxx/v6/__init__.py: Load printers and xmethods.
------------------------------------------------------------------------

因此第二次注册会抛出错误。您可以将其删除或注释掉:

#register_libstdcxx_printers (None)

GDB is still unable to print the contents of stl containers

您的 gcc 可能不匹配 pretty-print 。参见 https://stackoverflow.com/a/9108404/72178了解详情。

关于python - GDB打印STL数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26567110/

相关文章:

c++ - iOS:在 Objective-C++ 中定义和使用 C++

javascript - 谷歌浏览器打印预览第一次不加载页面

css - 打印时防止表格分页

python - 如何在 Python C-API 中动态创建派生类型

python - 如何比较python中的列表/集合列表?

c++ - 函数之间的数组指针丢失值(用 swig 编译以在 python3 中使用)

html - Firefox 打印表在第二页

python - 尝试创建一个 Discord webhook,在代码中分配了头像和用户名

python - 加速 python 中的 numpy 循环?

c++ - 仅寻址 WORD 的 15 位