Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: mec.gnu@mindspring.com (Michael Elizabeth Chastain)
To: gdb@sources.redhat.com, luis_solis@terra.es
Subject: Re: c++ stl containers
Date: Sat, 10 Jan 2004 23:00:00 -0000	[thread overview]
Message-ID: <20040110230036.573844ACDA@berman.michael-chastain.com> (raw)

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


             reply	other threads:[~2004-01-10 23:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-10 23:00 Michael Elizabeth Chastain [this message]
  -- strict thread matches above, loose matches on Subject: below --
2004-01-10 21:42 luis_solis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040110230036.573844ACDA@berman.michael-chastain.com \
    --to=mec.gnu@mindspring.com \
    --cc=gdb@sources.redhat.com \
    --cc=luis_solis@terra.es \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox