Skip to main content Skip to navigation

Debugging template classes using Eclipse in windows

Eclipse provides a very good development environment for writing and debugging C++ in Windows. This is usually done using the gcc compiler within cygwin in that if you want to use the microsoft compiler it is most sensible to use Visual C++. Debugging within cygwin is done using the cygwin gdb tool (preferably with the gcc-debuginfo package loaded). Unfortunately its support for visualising the contents of standard template classes such as vectors and maps is awful

It is possible to enable a python plugin within gdb which improves the display of these classes as described here. However there is a problem in that it requires gdb to have been compiled with python support, and the default gdb that ships with cygwin does not include python support.

Building gdb with python support

In order to rebuild python from the source a number of additional packages will need to be installed using cygwin setup

  • Packages that may well have been installed in order to allow C++ builds within Eclipse:
    gcc-G++, make, makedepend
  • Additional packages that may well not have already been installed:
    diffutils, perl (required by makeinfo), m4 interpreter, libncursesw-devel (for termcap), bison, flex, libexpat-devel (for xml support), libreadline-devel

In order to compile gdb, gdb itself needs to first be installed using cywin setup, and then the install mode changed to source and the install repeated. The source is then in in C:\cygwin64\usr\src (or equivalent if cywin was installed other than the default C:\cygwin64). gdb should then be built from the cygwin command prompt by navigating to the gdb src directory and building and installing as follows:

./configure 'CXXFLAGS=-O3' 'CFLAGS=-O3' --with-python --disable-gdbtk \
--with-auto-load-dir=$debugdir:$datadir/auto-load \
--with-auto-load-safe-path=$debugdir:$datadir/auto-load --with-expat --with-gdb-datadir=/usr/share/gdb \
--with-jit-reader-dir=/usr/lib/gdb --without-libunwind-ia64 --without-lzma \
--with-separate-debug-dir=/usr/lib/debug --with-zlib --without-babeltrace
make
make install

The ./configure options are based on the ./configure options for the default gdb (which can be found by running gdb and using 'show configuration', with the following changes:

The default Makefiles produced using ./configure have CXXFLAGS build flags of '-g -O2'. The optional 'CXXFLAGS=-O3' 'CFLAGS=-O3' options in the configure command ensure that a smaller (and presumably faster) release version of the code is built.

The tk/tcl aspects of gdb need to be disabled with --disable-gdbtkbecause there are problems importing the libraries associated with the tcl components. There are workarounds, but they are cumbersome and do not appear fully to work, and the tcl components are probably not needed for most normal debugging.

--with-python includes python, which is not in the default gdb, which is the whole point of the rebuild.

If the build fails because a package is missing, or for some other reason a 'make clean' or 'make distclean' followed by a ./configure ... may be enough to rebuild, but in some cases it appears to be necessary to delete all of the files in C:\cygwin64\usr\src and then resinstall the gdb source package.

After building there will now be two copies of gdb on the system, the original at in C:\cygwin64\bin and the new one in C:\cygwin64\usr\local\bin.

Within Eclipse the Debugger settings of the individual run configurations then need to be changed so that the GDB debugger points to the new executable (C:\cygwin64\usr\local\bin\gdb.exe).

Enabling the improved visualisation

The instructions here should now be followed. Note that the path to the .gdbinit file should be the full windows format, e.g. C:\cygwin64\usr\local\.gdbinit, and directory name within .gdbinit should also be in windows format e.g.

python
import sys
sys.path.insert(0, 'C:\cygwin64\usr\local\share\gdb\libstdc')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end