Ubuntu 14.04,gcc 4.8.4:由于Python问题,gdb漂亮打印无法正常工作。

18

在使用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'

谷歌找到了这个Bug报告:http://osdir.com/ml/debian-gcc/2014-02/msg00061.html 这个Bug报告使用python print sys.path命令在gdb提示符下列出。然而,当我在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还是其他什么东西呢?


1
Ubuntu 14.04使用Python 3构建gdb,因此print现在是一个函数;使用(gdb) python print(sys.path) - Mark Plotnick
1
谢谢,这回答了我的问题。然而,原始错误“ImportError: No module named 'libstdcxx'”仍然存在。这是否意味着这个脚本需要转换为Python 3? - Philipp
11
libstdc++.so.6.0.19-gdb.py 中的脚本应该按照那封邮件的建议进行修复,并可能移植到Python 3(我还没有仔细研究过)。但是,如果您的目标是使用系统版本的gcc编译的(即您不是交叉编译,也不是使用与系统附带的gcc不同的版本),则可以执行(gdb) python sys.path.append("/usr/share/gcc-4.8/python");然后,libstdc++.so.6.0.19-gdb.py 脚本添加一个不存在的目录到路径中就无关紧要了。 - Mark Plotnick
7
@Mark:谢谢!我还在~/.gdbinit文件中添加了这一行,并且每次运行gdb时它都会自动加载:python sys.path.append("/usr/share/gcc-4.8/python") - webbertiger
1
已确认的错误:https://bugs.launchpad.net/ubuntu/+source/gcc-4.8/+bug/1473599...或者更有帮助的链接:https://bugs.launchpad.net/ubuntu/+source/gcc-4.8/+bug/1446828。将包含multiarch的if语句中的两行注释掉,问题就会消失(在/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19-gdb.py中)。 - cloudsurfin
1个回答

12

我把这个回答发表出来以便于其他人更容易地找到它。Mark Plotnick和webbertiger的评论提供了实际答案。

简而言之,以下为对我有效的步骤:

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

由于我正在使用Eclipse CDT,所以我检查了一下此文件是否被用于window > preferences > GDB > GDB command file。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接