Better variable exploring when debugging C++ code with Eclipse/CDT

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):

Prerequisites

  • Make sure you have you have Python 2.7 installed and in the system path.

    http://www.python.org/download/

  • Make sure MinGW-get is installed

    http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/

  • Make sure you have an SVN client are installed

Installation:

  • 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://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
    
  • 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.

    Python
    import sys
    sys.path.insert(0, ‘C:/directory’)
    from libstdcxx.v6.printers import register_libstdcxx_printers
    register_libstdcxx_printers (None)
    end

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)