Using STL containers with GDB

Vincent Bénony vbenony@nordnet.fr
Wed Apr 23 06:49:00 GMT 2008


Le 22 avr. 08 à 23:51, Daniel Jacobowitz a écrit :
>>
>> The Python branch appears to work for executables compiled with Gcc  
>> only.  I'm
>> curious to know if this approach will work for executables built  
>> using other
>> compilers?
>
> Vincent's implementation has the layout of the GNU STL implementation
> hardcoded into it - so even less portable than the Python
> implementation, which uses the field names.

You are right, this patch is very hardcoded. I assume that fields of  
STL containers are always in the same order. I ask GDB the size of  
"void *", and I compute fields offsets using this information to read  
things I need. If you use another compiler, but with GNU STL headers,  
this patch *should* continue to work...

The reason why I do not use fields name is that I had some problems  
with GDB parser: my first approach was to use GDB scripts, but there  
were many problems, like no recursive dump (an std::list into an  
std::vector for example), and I was unable to cast a pointer into a  
type that was a template, I mean GDB parser was able to parse a  
expression like

  (gdb) p (struct Something*) pointer

but not something like

  (gdb) p (std::list<int> *) pointer

  So, you should see my patch as a quick an ugly way of using GDB to  
debug program that use STL container today, but not a patch to be  
included into GDB for future releases.

  My idea was first to consider having GDB call some kind of external  
script in particular situation, and this seems to be the goal of  
Python scripting system, and that's why I feel very enthusiast about  
this project.



More information about the Gdb-patches mailing list