Accepted answer

you need a version of gdb capable of using python to pretty print structures. i know at least on windows using mingw that this is not provided in the default install.

pretty printers are python modules which tell gdb how to display a given structure. you can write your own, but there are already printers for stl available for download.

to get pretty printers working on windows (instructions should be similiar for other os's):



  • open a command shell and type:

    mingw-get install gdb-python
  • when its finished cd to a local directory and install the printers by typing:

    svn co svn://
  • open the .gdbinit (create it in a text editor if need be) and type the following replaceing "c:/directory" with the folder that you checked the printers into.

    import sys
    sys.path.insert(0, 'c:/directory')
    from libstdcxx.v6.printers import register_libstdcxx_printers
    register_libstdcxx_printers (none)

eclipse setup

  • go to windows > preferences > c/c++ > debug > gdb
  • where it says gdb debugger put the path to the python enabled gdb it will most likely be in the mingw /bin folder with a name like gdb-python27.exe
  • where it says gdb command file put the path to the .gdb init file you made earlier.

that's it, debug like normal, the stl structures should be much easier to read.


i know that jdt (java environment in eclipse) provides custom "formatters" to be applied when displaying variable values in debug views. a quick look at google for the same in cdt brings this page:

i don't know if this has been yet integrated in the main cdt line, may be you can try to right click on a variable while debugging (in the last cdt) and see if there is a custom formater entry. if not available i recomend you to add a new tracker entry in cdt tracker to ask this enhancement.


i would like to expand on the windows 7 response because some key steps are left out:

this is for mingw users with eclipse cdt

0) if you don't have python gdb, open a shell/command and use mingw-get.exe to 'install' python-enabled gdb e.g.

   mingw-get.exe install gdb-python

1a) get python 2.7.x from and install

1b) make sure pythonpath and pythonhome are set in your environment:

 pythonpath should be c:\python27\lib   (or similar)
 pythonhome should be c:\python27

1c) add pythonhome to your path


2a) open a text enter, enter the following statements. notice the 3rd line is pointing to where the python scripts are located. see notes below about this!

import sys
sys.path.insert(0, 'c:/mingw/share/gcc-4.6.1/python')         
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (none)

2b) save as '.gdbinit' note: windows explorer will not let you name a file that starts with with a period from explorer. most text edits (including notepad) will let you. gdb init files are like 'scripts' of gdb commands that gbd will execute upon loading.

2c) the '.gdbinit' file needs to be in the working directory of gdb (most likely this is your projects root directory but your ide can tell you.

3) open your eclipse (or other ide) preferences dialog. go to the c++ debugger sub-menu.

4) configure eclipse to use c:\mingw\bin\gdb-python27.exe as the debugger and your .gdbinit as the config file.

5a) re-create all your debug launch configurations (delete the old one and create a new one from scratch).


5b) edit each debug configuration and point it to the new gdb-python.exe and point it to the.

if you run into issues:

--don't forget to change the location to the python directory in the above python code! this directory is created by mingw, so don't go looking to download the pretty printers, mingw did it for you in step zero. just goto your mingw install director, the share folder, the gcc folder (has version number) and you will find python folder. this location is what should be in python script loaded by gdb.

--also, the .gdbinit is a pita, make sure its named correctly and in the working folder of gdb which isn't necessarily where gdb-python.exe is located! look at your gdb output when loading gdb to see if a) 'python-enabled' appears during load and that the statements in the .gdbinit are appearing.

--finally, i had alot of issues with the system variables. if python gives you 'importerror' then most likely you have not set pythonpath or pythonhome.

--the directory with 'gdb-python27' (e.g. c:\mingw\bin') should also be on your path and if it is, it makes setting up eclipse a bit nicer because you don't need to put in absolute paths. but still, sometimes the .gbdinit needs an absoulte path. if it works you'll see output from gbd (console->gdb traces) like this on startup of debugger:

835,059 4^done
835,059 (gdb) 
835,059 5-enable-pretty-printing
835,069 5^done
835,129 12^done
835,129 (gdb) 
835,129 13source c:\mingw\bin\.gdbinit
835,139 &"source c:\\mingw\\bin\\.gdbinit\n"
835,142 13^done
835,142 (gdb) 


if you have gdb support for cdt (see, for example, gdb in eclipse), you could try this: de-referencing stl containers

long ago i also stumbled upon your same problem. it was a pain to check the stl containers. then i found that link and added to my .gdbinit file some of those definitions. life was easier after that.

note: my gdb version is 7.1 and adding those definitions work fine. i don't know if in newer versions of gdb they are already included.


in debug view in variables list expand vector:

"vector_name" -> std::_vector_base<"datatype"> -> _m_impl

then right click on _m_start and select "display as array...", type its length and then click ok. now you can expand each item of your vector.


well, gdb don't natively support stl containers. you can't say this is incorrect, since it will expose the inner workings of the stl objects, but most of the time it is not what we want, right?

if you're using gdb 7.0 you can take advantage of the pretty printers. this website has a pretty simple tutorial on how to set them. i copied below the part that interests you:

  1. check-out the latest python libstdc++ printers to a place on your machine. in a local directory, do:

        svn co svn://
  2. add the following to your ~/.gdbinit. the path needs to match where the python module above was checked-out. so if checked out to: /home/maude/gdb_printers/, the path would be as written in the example:

        import sys
        sys.path.insert(0, '/home/maude/gdb_printers/python')
        from libstdcxx.v6.printers import register_libstdcxx_printers
        register_libstdcxx_printers (none)

the path should be the only element that needs to be adjusted in the example above. once loaded, stl classes that the printers support should printed in a more human-readable format. to print the classes in the old style, use the /r (raw) switch in the print command (i.e., print /r foo). this will print the classes as if the python pretty-printers were not loaded.

since you're using eclipse cdt, don't forget to point your debug configuration to your .gdbinit file. when creating a new debug configuration, go to the debugger tab and put the path to the .gdbinit file in the "gdb command file" field.

i hope that helps!

Related Query

More Query from same tag