在 Ubuntu 13.10 中设置 GDB 漂亮打印

在 Ubuntu 13.10 中设置 GDB 漂亮打印

我尝试设置 GDB 漂亮打印(为了更容易使用标准容器)这个答案。我没有使用 svn 中的 Python 漂亮打印机代码,而是使用了搭载 ubuntu完成其余过程后,我在启动 gdb 时收到以下错误消息:

For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "/home/nietaki/gdb_printers/python/libstdcxx/v6/printers.py", line 54
    raise ValueError, "Cannot find type %s::%s" % (str(orig), name)
                    ^
SyntaxError: invalid syntax
/home/nietaki/.gdbinit:6: Error in sourced command file:
Error while executing Python code.

在深入研究了这个问题之后,我发现根本原因更深——gdb 中使用的 Python 3 与 libstdc++ 漂亮打印机不兼容

有人有解决这个问题的实用方法吗?目前,我只能使用 Dan Marinescu 提供的帮助程序(同样有用,但功能不强):http://www.yolinux.com/TUTORIALS/GDB-Commands.html#STLDEREF

答案1

最简单的解决方法似乎是像平常一样设置漂亮的打印机,然后printers.py使用 2to3 转换为 python3:

2to3 printers.py -w

我只对其进行了简单的测试,但它似乎运行良好。

相关内容