Looking at C++ STL containers in GDB can be confusing - they’re full of internal details. With libstdc++’s Python pretty printers, GDB can show these containers in a much cleaner way. This guide will show you how to set them up and use them to make debugging easier.
Check if libstdc++ python available.
$ ls /usr/share/gcc/python/libstdcxx/
If not available, clone gcc source code.
$ wget https://github.com/gcc-mirror/gcc/archive/refs/heads/master.zip -O gcc.zip
$ unzip gcc.zip
Edit ~/.gdbinit to add libstdc++ python to sys.path.
pythonimport sys
0, '/root/gcc-master/libstdc++-v3/python/libstdcxx')
sys.path.insert(from libstdcxx.v6.printers import register_libstdcxx_printers
None)
register_libstdcxx_printers (
end
Check if libstdc++ pretty-printer added successfully.
$ gdb -batch -ex 'info pretty-printer'
global pretty-printers:
builtin
mpx_bound128
libstdc++-v6