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 Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">