This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Variable objects and STL containers
- From: Vladimir Prus <ghost at cs dot msu dot su>
- To: gdb at sources dot redhat dot com
- Date: Tue, 05 Feb 2008 09:16:53 +0300
- Subject: Re: Variable objects and STL containers
- References: <18343.64413.689019.489727@kahikatea.snap.net.nz>
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