This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Variable objects and STL containers


Nick Roberts wrote:

> 
> Using variable objects, if I display a watch expression for an STL container, e.g.
> 
>   vector<int> v (3);
>   v[0] = 1;
>   v[1] = 11;
>   v[2] = 22;
> 
> in Emacs, I get something like this:
> 
> v std::vector<int,std::allocator<int> >
>     std::_Vector_base<int,std::allocator<int> > std::_Vector_base<int,std::allocator<int> >
>       public
>         _M_impl       std::_Vector_base<int,std::allocator<int> >::_Vector_impl
>           std::allocator<int> std::allocator<int>
>             __gnu_cxx::new_allocator<int>     {...}
>           public
>             _M_start             int *            0x804c008
>               *_M_start                           0
>             _M_finish          int *      0x804c014
>               *_M_finish                    135153
>             _M_end_of_storage    int *      0x804c014
>               *_M_end_of_storage            135153
> 
> which is a bit meaningless to the end user.  This is for gcc, and I guess other
> compilers store STL containers differently.  In this case, I know where the
> values are really stored:
> 
>  v._M_impl._M_start   int *   0x804c008
>  *v._M_impl._M_start          1
>  *(v._M_impl._M_start+1)      11
>  *(v._M_impl._M_start+2)      22
> 
> (gdb) p v._M_impl._M_finish - v._M_impl._M_start
> $1 = 3
> 
> and it would be better to display these.
> 
> I have two questions:
> 
> 1) Does GDB know what compiler was used to create an object file/executable?
> 
> 2) _M_impl, _M_start are gcc internals and I guess they could change (like CLI!)
>    Is it meaningful to ask on the gcc list for a formal interface to these details?

Technically, there is formal interface, called iterators, provided by the
C++ standard. I don't have the slightest confidence in gdb not falling over
if you try to use them, though.

We discussed using Python scripting for that; in fact, I have a patch locally
that will make 

        -var-evaluate-expression V 

for a vector print something like:

        [1,2,3]

I'm working on making those element the children of the variable object,
but it's not done yet.

- Volodya



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]