Controlling Eclipse CDT debugger output?

10,081

Solution 1

Note that you don't want a general way of drilling down into objects; you want to pretty-print STL containers.

I think CDT delegates this to the debugger backend; i.e. it is up to your debugger (gdb, perhaps?) to inform CDT about the value of a variable and how it can be expanded.

Edit: I don't think that the GDB backend shipped with CDT has any support for "intelligent" display of STL containers. If you're really interested in this, I'd suggest that you contact the CDT development team at [email protected].

Update/Edit: Please see other responses below for instructions on how to enable pretty printers in CDT.

Solution 2

Displaying stl containers with eclipse/gdb was also a major pain for me for a long time.

But now I've just discovered that the latest version of gdb with python enabled can help with that.

It follows what I've done (using Ubuntu Linux 8.10):

  • Install gdb version >= 6.8.50 (for instance from debian experimental)
  • Create a file named .gdbinit in your project root with the following content:

    python import gdb.libstdcxx.v6.printers

Now the stl containers will be pretty printed.

If you want to check if you already have a python enabled gdb (or if your new installation have worked):

  • Start gdb from the console
  • On the gdb prompt execute the following

    (gdb) python print 'Python enabled GDB is working!'

  • If the above command produces what we are expecting then it is working.

For more details check this blog.

Solution 3

Windows 7

Get the pretty printers: svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python

Set up eclipse with: C/C++ Debug Gdb:

C:\MinGW\bin\gdb-python27.exe
C:\MinGW\bin\.gdbinit

Solution 4

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 http://python.org/download/ 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

 %PYTHONHOME%;...

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!

python
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)
end

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

--OR--

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) 
Share:
10,081
billcoke
Author by

billcoke

Updated on July 28, 2022

Comments

  • billcoke
    billcoke almost 2 years

    When using CDT I would like to have std::string show up in the 'variable' debug window with the string it contains. For instance if it is currently holding the word "history" I would like to see history in the debugger window labeled "variables".

    I think that there is a general way to have it drill down into objects but I can't put my finger on it. Does anyone out there know how to do this?

    This would also be useful for me to use when outputting just a single field from a complex object.

    Thanks, Bill