From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30896 invoked by alias); 5 Feb 2008 06:17:19 -0000 Received: (qmail 30883 invoked by uid 22791); 5 Feb 2008 06:17:18 -0000 X-Spam-Check-By: sourceware.org Received: from main.gmane.org (HELO ciao.gmane.org) (80.91.229.2) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 05 Feb 2008 06:16:59 +0000 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1JMH71-0005Vf-Ld for gdb@sources.redhat.com; Tue, 05 Feb 2008 06:16:55 +0000 Received: from 77.246.241.246 ([77.246.241.246]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 05 Feb 2008 06:16:55 +0000 Received: from ghost by 77.246.241.246 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 05 Feb 2008 06:16:55 +0000 To: gdb@sources.redhat.com From: Vladimir Prus Subject: Re: Variable objects and STL containers Date: Tue, 05 Feb 2008 06:17:00 -0000 Message-ID: References: <18343.64413.689019.489727@kahikatea.snap.net.nz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit User-Agent: KNode/0.10.5 X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2008-02/txt/msg00016.txt.bz2 Nick Roberts wrote: > > Using variable objects, if I display a watch expression for an STL container, e.g. > > vector v (3); > v[0] = 1; > v[1] = 11; > v[2] = 22; > > in Emacs, I get something like this: > > v std::vector > > std::_Vector_base > std::_Vector_base > > public > _M_impl std::_Vector_base >::_Vector_impl > std::allocator std::allocator > __gnu_cxx::new_allocator {...} > 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