i have a vector of floats, is there anyway to use gdb to see whats inside?
Thanks
Printable View
i have a vector of floats, is there anyway to use gdb to see whats inside?
Thanks
Perhaps this is of interest.
http://staff.science.uva.nl/~gilad/stl/stl_gdb.html
well, that sucks....
thanks for the reply
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)
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.Hope this helps.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
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
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