I'm using Code::Blocks and want to have gdb python-enabled. So I followed the C::B wiki http://wiki.codeblocks.org/index.php?title=Pretty_Printers to configure it.
My pp.gdb is the same as that in the wiki except that I replace the path with my path to printers.py.
python
import sys
sys.path.insert(0, 'C:/Program Files (x86)/mingw-builds/x32-4.8.1-posix-dwarf-rev3/mingw32/share/gcc-4.8.1/python/libstdcxx/v6')
from printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end
Then I tested it:
(gdb) source C:\Program Files (x86)\mingw-builds\x32-4.8.1-posix-dwarf-rev3\mingw32\bin\pp.gdb
And the error message showed:
Traceback (most recent call last):
File "<string>", line 4, in <module>
File "C:/Program Files (x86)/mingw-builds/x32-4.8.1-posix-dwarf-rev3/mingw32/
share/gcc-4.8.1/python/libstdcxx/v6/printers.py", line 911, in register_libstdcxx_printers
gdb.printing.register_pretty_printer(obj, libstdcxx_printer)
File "c:\program files (x86)\mingw-builds\x32-4.8.1-posix-dwarf-rev3\mingw32\
share\gdb/python/gdb/printing.py", line 146, in register_pretty_printer
printer.name)
RuntimeError: pretty-printer already registered: libstdc++-v6
C:\Program Files (x86)\mingw-builds\x32-4.8.1-posix-dwarf-rev3\mingw32\bin\pp.gd
b:6: Error in sourced command file:
Error while executing Python code.
How can I fix it?
Today, I also see this similar issue, after I update my libstdcxx's pretty from an old gcc4.7.x version to the gcc's trunk HEAD version to fix some other problems.
I'm also using Codeblocks, and I have those two lines in my customized gdb script.
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
Note that I already have -nx
option parssed to gdb when it started. After tweak for a while, I found that the libstdcxx's pretty printer is automatically loaded and get registered after the from...import...
line. So, as a solution, you can just comment out the second line, and everything works just fine here.
from libstdcxx.v6.printers import register_libstdcxx_printers
#register_libstdcxx_printers (None)
Also, I think the GDB's official wiki STLSupport - GDB Wiki and Codeblocks' officical wiki Pretty Printers - CodeBlocks should be updated to state this issue.
EDIT: I just see the file: libstdcxx\v6__init__.py from GCC svn trunk(maybe, it was added recently), and I see it has code:
# Load the pretty-printers.
from printers import register_libstdcxx_printers
register_libstdcxx_printers(gdb.current_objfile())
So, I think this code will automatically register the printers, so you don't need explicitly call register_libstdcxx_printers (None)
.
You probably don't need to have this code. It seems like the libstdc++ prnters are preloaded -- which is normal in many setups... we designed printers to "just work", and the approach of using python code to explicitly load printers was a transitional thing.
One way to check is to run gdb -nx, start your C++ program, and then use "info pretty-printer".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With