Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* c++ stl containers
@ 2004-01-10 21:42 luis_solis
  0 siblings, 0 replies; 2+ messages in thread
From: luis_solis @ 2004-01-10 21:42 UTC (permalink / raw)
  To: gdb

Hi
I'd like look at the values of a stl container, but I only acces the
direction, not the values, ie
vector<float> xy(2); xy[0]=2.; xy[1]=3.;
xy[0]=xy[0]+xy[1]+ some_function();
How I could look xy[0] value, or all the values of xy
Thanks
Luis


^ permalink raw reply	[flat|nested] 2+ messages in thread
* Re: c++ stl containers
@ 2004-01-10 23:00 Michael Elizabeth Chastain
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Elizabeth Chastain @ 2004-01-10 23:00 UTC (permalink / raw)
  To: gdb, luis_solis

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<float>::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 <vector>

  void foo () { ; }

  int main ()
  {
    std::vector <float> 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 <float> 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<float,std::allocator<float> >> = {<_Vector_alloc_base<float,std::allocator<float>,true>> = {_M_start = 0x80a9bb0, _M_finish = 0x80a9bb8, 
	_M_end_of_storage = 0x80a9bb8}, <No data fields>}, <No data fields>}
  (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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-01-10 23:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-10 21:42 c++ stl containers luis_solis
2004-01-10 23:00 Michael Elizabeth Chastain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox