From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3857 invoked by alias); 18 Jun 2007 11:15:29 -0000 Received: (qmail 3838 invoked by uid 22791); 18 Jun 2007 11:15:27 -0000 X-Spam-Check-By: sourceware.org Received: from mail.gmx.net (HELO mail.gmx.net) (213.165.64.20) by sourceware.org (qpsmtpd/0.31) with SMTP; Mon, 18 Jun 2007 11:15:23 +0000 Received: (qmail invoked by alias); 18 Jun 2007 11:15:20 -0000 Received: from port-83-236-52-166.dynamic.qsc.de (EHLO port-83-236-52-166.dynamic.qsc.de) [83.236.52.166] by mail.gmx.net (mp034) with SMTP; 18 Jun 2007 13:15:20 +0200 X-Authenticated: #9832049 From: Maik Beckmann To: gdb@sourceware.org Subject: Re: how to view content in stl vector Date: Mon, 18 Jun 2007 11:15:00 -0000 User-Agent: KMail/1.9.7 References: <200706151952.l5FJq2B7009679@brahms.sibelius.xs4all.nl> <1182156720.4609.31.camel@mikro.mikro> In-Reply-To: <1182156720.4609.31.camel@mikro.mikro> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200706181314.44405.maikbeckmann@gmx.de> X-Y-GMX-Trusted: 0 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: 2007-06/txt/msg00136.txt.bz2 Am Montag, 18. Juni 2007 10:52:00 schrieb Alp=C3=A1r J=C3=BCttner: > In a running On Fri, 2007-06-15 at 21:52 +0200, Mark Kettenis wrote: > > > Date: Tue, 12 Jun 2007 11:05:21 -0400 > > > From: kdsfinger@gmail.com > > > > > > hi, all > > > How may I view the content in a stl vector in ddd? (or the command to > > > print it in gdb?). It seems I can only view the first element. I > > > searched google but did not find answer. Thanks for help. Hello If you add this to your .gdbinit=20 <.gdbinit> define dump_vector_simple set $it =3D $arg0.data() set $size =3D $arg0.size() set $end =3D $it + $size set $i =3D 0 while ($it !=3D $end) printf "[%u] =3D=3D " , $i output *($it) printf "\n" set $it++ set $i++ end end define dump_vector_as_virtual_array set $it =3D $arg0.data() set $size =3D $arg0.size() output *$it@$size printf "\n" end the gdb output for this program #include int main(int argc, char **argv) { std::vector vec; for(int i =3D 0; i < 10; i++) vec.push_back(i+1); vec.data(); // dummy for gdb return 0; // breakpoint here } will be dump_vector_simple vec [0] =3D=3D 1 [1] =3D=3D 2 [2] =3D=3D 3 [3] =3D=3D 4 [4] =3D=3D 5 [5] =3D=3D 6 [6] =3D=3D 7 [7] =3D=3D 8 [8] =3D=3D 9 [9] =3D=3D 10 or respectively dump_vector_as_virtual_array vec {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} HTH, Maik Beckmann PS: I'm using g++-4.1.2 and gdb-6.6