Skip to content
Search

GDB:pretty-printing

lastmod 2018-08-17created 2014-12-1810 edits

A Python tool that makes it easier to inspect the data of container classes such as STL vector and map in GDB.

How to use

If GDB does not have the Python extension installed, you must recompile it.

Then get pretty-printing using svn and create a GDB initialization file. 1

$ svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python pretty-printing
$ vi ~/.gdbinit

Enter Python code like the following in the gdb initialization file.

python
import sys
sys.path.insert(0, 'pretty-printing/home/path/libstdcxx/v6')
from printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end

Then, if running the gdb command shows no errors, it worked.

To configure it in Eclipse, set ~/.gdbinit in the Window > Preferences > C/C++ > Debug > GDB > GDB command file field.

For reference, you can use an environment variable as follows.

printing_home = os.environ['PPRINTING_V6']
sys.path.insert(0, printing_home)
from printers import register_libstdcxx_printers
register_libstdcxx_printers(None)

Example

The full code as applied is as follows.

python
print "[PYTHON] Python initialize begin."

import os
import sys

## pretty-printing
## svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
PPRINTING_HOME = os.environ["PPRINTING_HOME"]
PPRINTING_V6 = os.path.join(PPRINTING_HOME, "libstdcxx/v6")

if os.path.isdir(PPRINTING_V6):
    print "[PPRINTING] Register libstdcxx printers."
    sys.path.insert(0, PPRINTING_V6)
    from printers import register_libstdcxx_printers
    register_libstdcxx_printers(None)
else:
    print "[PPRINTING] Not found printers.py file."

print "[PYTHON] Python initialize end."
end

See also

Favorite site

References


  1. For reference, the file /share/gdb/python/gdb/printing.py exists. ↩