From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8932 invoked by alias); 10 Jan 2004 23:00:26 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 8925 invoked from network); 10 Jan 2004 23:00:26 -0000 Received: from unknown (HELO granger.mail.mindspring.net) (207.69.200.148) by sources.redhat.com with SMTP; 10 Jan 2004 23:00:26 -0000 Received: from user-119a90a.biz.mindspring.com ([66.149.36.10] helo=berman.michael-chastain.com) by granger.mail.mindspring.net with esmtp (Exim 3.33 #1) id 1AfS5h-0000WZ-00; Sat, 10 Jan 2004 18:00:25 -0500 Received: by berman.michael-chastain.com (Postfix, from userid 502) id 573844ACDA; Sat, 10 Jan 2004 18:00:36 -0500 (EST) To: gdb@sources.redhat.com, luis_solis@terra.es Subject: Re: c++ stl containers Message-Id: <20040110230036.573844ACDA@berman.michael-chastain.com> Date: Sat, 10 Jan 2004 23:00:00 -0000 From: mec.gnu@mindspring.com (Michael Elizabeth Chastain) X-SW-Source: 2004-01/txt/msg00140.txt.bz2 Just do: print xy[0], xy[1], and so on. gdb turns the '[0]' into a C++ method call just like the C++ compiler does. See the attached typescript for an example. Unfortunately, "print xy.size()" does not work because the test program does not call the "size" method. The template function is present in the executable only if the program uses it. If the test program calls std::vector::size somewhere, then "print xy.size()" will work in gdb. You need gdb 6.0, and you probably need a recent gcc. I use gcc 3.3.2. And compile and link with -gdwarf-2. -gstabs+ or just plain -g might work. Hope this helps, Michael C GDB QA Guy Script started on Sat Jan 10 17:44:59 2004 [mec.gnu@berman tmp]$ cat vf.cc #include void foo () { ; } int main () { std::vector xy(2); xy[0] = 2.0; xy[1] = 3.0; foo (); } [mec.gnu@berman tmp]$ /berman/migchain/install/target/native/gcc-3.3.2-as-2.14-ldgd-2.14/bin/g++ -gdwarf-2 vf.cc [mec.gnu@berman tmp]$ /berman/migchain/install/target/native/gdb-6.0/bin/gdb a.out GNU gdb 6.0 Copyright 2003 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i686-pc-linux-gnu"... (gdb) break main Breakpoint 1 at 0x804995b: file vf.cc, line 7. (gdb) run Starting program: /berman/home/mec.gnu/tmp/a.out Breakpoint 1, main () at vf.cc:7 7 std::vector xy(2); (gdb) next 8 xy[0] = 2.0; (gdb) 9 xy[1] = 3.0; (gdb) 10 foo (); (gdb) print xy[0] $1 = (float &) @0x80a9bb0: 2 (gdb) print xy[1] $2 = (float &) @0x80a9bb4: 3 (gdb) print xy.size() Cannot evaluate function -- may be inlined (gdb) print xy $3 = {<_Vector_base >> = {<_Vector_alloc_base,true>> = {_M_start = 0x80a9bb0, _M_finish = 0x80a9bb8, _M_end_of_storage = 0x80a9bb8}, }, } (gdb) quit The program is running. Exit anyway? (y or n) y [mec.gnu@berman tmp]$ exit exit Script done on Sat Jan 10 17:47:25 2004