Printed version of GDB ImportError: no module named "printers"

I am trying to add pretty print for STL in my GDB on Ubuntu 14.04. Some information about the tools:

OS: Ubuntu 14.04

gdb version: 7.7

python version: 2.7.6

python3 version: 3.4.0

But after I set up exactly what the instruction said. I still get the following errors:

Traceback (most recent call last): File "<string>", line 3, in <module> File "/home/jerry/myLib/gdb_stl_support/python/libstdcxx/v6/__init__.py", line 19, in <module> from printers import register_libstdcxx_printers ImportError: No module named 'printers' /home/jerry/.gdbinit:6: Error in sourced command file: Error while executing Python code. Reading symbols from main...done. 

Then I put a double check on my beautiful print installation directory. In the directory /home/jerry/myLib/gdb_stl_support/python/libstdcxx/v6/ I can see that I have a file printerers.py. And I am also browsing the contents of printers.py, I am sure that it also has a register_libstdcxx_printers class. Why is the python interpreter still complaining that the printers module is missing? It seems strange to me.

+7
c ++ python pretty-print stl gdb
source share
1 answer

I just tried something, and, fortunately, it works now. At the very least, it can print map and vector content as expected. Here is what I did:

Since he complains that he cannot find the printer.py module, I think probably I should tell the python interpreter where this file is located. Therefore, I first added this extra line to my ~ / .gdbinit file: sys.path.append("/home/jerry/myLib/gdb_stl_support/python/libstdcxx/v6")

(After the line sys.path.insert(0, '/home/jerry/myLib/gdb_stl_support/python') )

Then running gdb again, I got the following error:

 Traceback (most recent call last): File "<string>", line 5, in <module> File "/home/jerry/myLib/gdb_stl_support/python/libstdcxx/v6/printers.py", line 1247, in register_libstdcxx_printers gdb.printing.register_pretty_printer(obj, libstdcxx_printer) File "/usr/share/gdb/python/gdb/printing.py", line 146, in register_pretty_printer printer.name) RuntimeError: pretty-printer already registered: libstdc++-v6 /home/jerry/.gdbinit:7: Error in sourced command file: Error while executing Python code. 

Given the error information, I edited the ~ / .gdbinit file and commented out the register_libstdcxx_printers (None) .

Then, after starting gdb, it works.

But I'm still wondering if directory lookups are recursive in sys.path? I mean, the python interpreter should work as follows: as soon as you add one directory to sys.path , then the subdirectory in this directory will also look for the module file.

+10
source share

All Articles