|
-
September 24th, 2006, 08:13 PM
#1
using gdb to see into a c++ vector?
i have a vector of floats, is there anyway to use gdb to see whats inside?
Thanks
-
September 24th, 2006, 08:36 PM
#2
Re: using gdb to see into a c++ vector?
Windows XP, Visual Studio 2008, SVN
-
September 24th, 2006, 10:01 PM
#3
Re: using gdb to see into a c++ vector?
well, that sucks....
thanks for the reply
-
September 24th, 2006, 10:23 PM
#4
Re: using gdb to see into a c++ vector?
Supposedly you can just evaluate expressions and print it, but it doesn't work for me.
Code:
GNU gdb 5.2.1
Copyright 2002 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-mingw32"...
(gdb) break *0x004013ef
Breakpoint 1 at 0x4013ef: file t.cpp, line 9.
(gdb) run
Starting program: a.exe
Breakpoint 1, 0x004013ef in main (argc=1, argv=0x3d3cd8) at t.cpp:9
9 v.push_back(3);
(gdb) p v[0]
One of the arguments you tried to pass to operator[] could not be converted to w
hat the function wants.
(gdb)
Windows XP, Visual Studio 2008, SVN
-
September 26th, 2006, 08:35 AM
#5
Re: using gdb to see into a c++ vector?
You have to know how the vector is implemented. If you are using the same gcc version I use, vector is a struct that contains an element _M_start which points to the first member.
Code:
(gdb) r
Starting program: /home/treuss/src/vec2
Breakpoint 1, main () at vec2.cc:5
5 std::vector<float> v;
(gdb) n
6 v.push_back( 3.14 );
(gdb) n
7 v.push_back( 2.63 );
(gdb) n
8 exit( 1 );
(gdb) p *v._M_start
$1 = 3.1400001
(gdb) p *(v._M_start+1)
$2 = 2.63000011
Hope this helps.
-
September 26th, 2006, 10:06 AM
#6
Re: using gdb to see into a c++ vector?
As treusss mentioned, if you know how to get a pointer to the vector's internal buffer, then it's just a matter of going to the n'th element starting at the pointer to the buffer. Since a vector stores its values in contiguous memory, it is much simpler to view a vector's values then say, a std::list or std::map.
Overloaded operators are not supported by most debuggers, which is why using v[0] didn't work. To see v[0], you must call a function to invoke [], and most debuggers do not support function calling.
Regards,
Paul McKenzie
-
August 31st, 2009, 05:49 PM
#7
Re: using gdb to see into a c++ vector?
This topic is quite old, but problem is still present. If somebody would like to run gdb under VisualStudio, then please check our addin WinGDB. Browsing of vectors will be much easier, than directly under gdb 
Kind regards,
WinGDB team
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|