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

人走茶凉 提交于 2019-12-17 18:28:47

问题


I'm getting this error when launching a program in 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 turned up this bug report: http://osdir.com/ml/debian-gcc/2014-02/msg00061.html This bug report list using the command python print sys.path on the gdb prompt. However, when I try to use any python on the gdb prompt, this happens:

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

I'm using Ubuntu 14.04 LTS, relevant version information:

$ 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

Clearly, something in my setup is broken. Is it python, gdb, or something else?


回答1:


I'm posting this as an answer so it will be easier for others to find it. The comments from Mark Plotnick and webbertiger are the actual answer.

To summarize, here is what worked for me:

  • Created a ~/.gdbinit file
  • Added python sys.path.append("/usr/share/gcc-4.8/python"); to that file

I'm using Eclipse CDT so I checked that this file is being used in window > preferences > GDB > GDB command file.



来源:https://stackoverflow.com/questions/31062010/ubuntu-14-04-gcc-4-8-4-gdb-pretty-printing-doesnt-work-because-of-python-issu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!