Ubuntu 14.04,gcc 4.8.4:由于 Python 问题,gdb 漂亮的打印不起作用

Ubuntu 14.04, gcc 4.8.4: gdb pretty printing doesn't work because of Python issue

我在 gdb 中启动程序时遇到此错误:

Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Traceback (most recent call last):
File "/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19-gdb.py", line 63, in <module>
from libstdcxx.v6.printers import register_libstdcxx_printers
ImportError: No module named 'libstdcxx'

Google 发现了这个错误报告:http://osdir.com/ml/debian-gcc/2014-02/msg00061.html 此错误报告列表在 gdb 提示符下使用命令 python print sys.path。但是,当我尝试在 gdb 提示符下使用任何 python 时,会发生这种情况:

(gdb) python print sys.path
File "<string>", line 1
print sys.path
        ^
SyntaxError: invalid syntax
Error while executing Python code.

(gdb) python print "Hello"
File "<string>", line 1
print "HellO"
            ^
SyntaxError: invalid syntax
Error while executing Python code.

我使用的是Ubuntu 14.04 LTS,相关版本信息:

$ gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
$ gdb --version
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
$ python --version
Python 2.7.6

很明显,我的设置中有些东西坏了。是 python、gdb 还是其他?

我将此作为答案发布,以便其他人更容易找到它。 Mark Plotnick 和 webbertiger 的评论才是真正的答案。

总而言之,这对我有用:

  • 创建了一个 ~/.gdbinit 文件
  • 已将 python sys.path.append("/usr/share/gcc-4.8/python"); 添加到该文件

我正在使用 Eclipse CDT,所以我检查了这个文件是否正在 window > 首选项 > GDB > GDB 命令文件中使用。