Printing STL List Entries in GDB

Eric Chun eric.chun@amd.com
Tue Jun 26 16:18:00 GMT 2007


Although I'd like to take credit for this idea, it isn't really my 
ambitious idea.  Many people have already done this.  Gilad Mishne 
created a set of commands to print out STL container structures (for SGI 
version of STL) in GDB 
(http://staff.science.uva.nl/~gilad/stl/stl_gdb.html).

And Ravi Menon created print commands for some of the GNU-STL structures 
(http://gcc.gnu.org/ml/libstdc++/2006-08/msg00009.html).  He didn't make 
commands for the list data structure though.

I'd like to make one for lists, but I don't know how the list data 
members are named.  I suppose I could go into the source code and find 
out, but does anybody have this information handy?


Benjamin Kosnik wrote:
>> I tried using single quotes as well, but it still won't print the
>> value: p (('std::_List_node' *) $curNode)->_M_data
>>     No symbol "std::_List_node" in current context.
> 
> Your planned usage of gdb is pretty ambitious. As far as I can tell,
> it's never supported such sophistication. Any non-trivial scoping seems
> to fail.
> 
> If you are debugging on linux, you might try compiling with the flags
> "-ggdb3 -O0".
> 
>> Do I need to the type of list entries I'm trying to print?  I'm
>> trying to create a user-defined command in gdb for printing stl lists
>> so I'd rather keep the command general so that I could reuse this
>> command for any other lists I might want to print.
> 
> In a perfect world, some theoretical future gdb would allow you to use
> std::list's own member functions for access.
> 
> -benjamin
> 
> 




More information about the Libstdc++ mailing list