18

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?

Philipp
  • 957
  • 1
  • 6
  • 20
  • 1
    Ubuntu 14.04 builds gdb with python 3, so `print` is now a function; use `(gdb) python print(sys.path)` – Mark Plotnick Jun 26 '15 at 18:40
  • 1
    Thanks, that answers that question. However, the original error "ImportError: No module named 'libstdcxx'" still remains. Does that mean this script needs to be converted to python 3? – Philipp Jun 26 '15 at 19:41
  • 11
    The script in `libstdc++.so.6.0.19-gdb.py` ought to be fixed as per that email message, and possibly ported to python 3 (I haven't looked at it really closely yet). But if your target is compiled with the system version of gcc (i.e. you're not cross-compiling nor using a version of gcc different from the one that came with the system), you can just do `(gdb) python sys.path.append("/usr/share/gcc-4.8/python")`; then it won't matter that the `libstdc++.so.6.0.19-gdb.py` script adds a nonexistent directory to the path. – Mark Plotnick Jun 26 '15 at 20:58
  • 7
    @Mark: Thanks! I also added this line in ~/.gdbinit and it's automatically loaded each time gdb is run: `python sys.path.append("/usr/share/gcc-4.8/python")` – webbertiger Sep 23 '15 at 19:34
  • 1
    Confirmed bug: https://bugs.launchpad.net/ubuntu/+source/gcc-4.8/+bug/1473599...or more helpfully here: https://bugs.launchpad.net/ubuntu/+source/gcc-4.8/+bug/1446828. Comment out the two lines with the if statement containing multiarch and the problem will go away(in /usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19-gdb.py). – cloudsurfin Nov 09 '15 at 00:04

1 Answers1

12

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.

jotadepicas
  • 2,389
  • 2
  • 26
  • 48