Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Using Eclipse and CDT to debug C++ code the variable windows is cumbersome and not very informative for types defined in the standard template library or in boost (e.g. shared_ptr).

Just an example how this may look like for an std::vector:

bar {…}     std::_Vector_base<TSample<MyTraits>, std::allocator<TSample<MyTraits> > >            _M_impl {…}              std::allocator<TSample<MyTraits> >  {…}              _M_start    0x00007ffff7fb5010               _M_finish   0x00007ffff7fd4410               _M_end_of_storage   0x00007ffff7fd5010   

Even if this information about the internals of those types may be useful, in almost any cases I would expect a clearer presentation here, i.e. a list of values for the std::vector. Are there any tools, plugins or other modifications around which can do this?

EDIT

The following solutions does not work for linux. I am using ubuntu 14.04, eclipse, g++, gdb.

I cant find a package gdb-python and linux does not use mingw

like image 780
Danvil Avatar asked Sep 06 '10 13:09

Danvil


1 Answers

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.

like image 96
DanChianucci Avatar answered Oct 14 '22 13:10

DanChianucci