views:

317

answers:

3

Hi all

I have a std::map< std::string, std::string> cont;

I want to see cont[ "some_key" ] in gdb. When I'm trying

p cont[ "some_ket" ]

I'm getting this message: One of the arguments you tried to pass to operator[] could not be converted to what the function wants.

I'm using GNU gdb Red Hat Linux (6.3.0.0-1.162.el4rh). Thanks

A: 

Gdb doesn't understand C++ operator overloading.

Marcelo Cantos
As I understand there aren't any way to see key-value during debug process?
Davit Siradeghyan
Not easily. std::map is a complex data structure. You can follow the (implementation-specific) private members and see what's going on, but it's quite a chore. @Eddy's answer may help, but I haven't played with that stuff at all.
Marcelo Cantos
+2  A: 

You can write your own dump functions and call them:

(gdb) call dump(m)

see this thread: http://www.mail-archive.com/[email protected]/msg02109.html

I'm curious about the GDB helper macros.

Eddy Pronk
+3  A: 

The latest gdb has python support baked in so one could easily write a function to print out the contents of any stl structure. However you'd have to learn the API and write the script. Luckily gcc 4.5 will ship with the needed python scripts to get gdb to intelligently handle stl data structures.

EDIT: you don't have to wait for GCC 4.5 (which by the way has already been released), you can just grab the code from SVN.

caspin