Setting up Pretty Printers in GDB

There’s an official page on gcc website: And here is how to set up it under Ubuntu.

Under Ubuntu 12.04(Precise), simply install the libstdc++6 debug package. It includes the python script for pretty printers:

Create a .gdbinit file in your home directory, with the content:

My test program looks like:

Build it with debugging enabled(-g):

Debug it with GDB:

Without pretty printers, the output is tedious and hard to understand:

Under Ubuntu 14.04(Trusty), the 4.8 version of debug package should be installed:

There’s an additional step. Since GDB in Trusty is built with python3, not python2, and the python scripts for pretty printers are in python2 syntax. A simple conversion is required:

Backup it before conversion if neccessary.

Leave a Reply

Your email address will not be published.