22

I'm using Eclipse with the CDT plugin to develop in C++. I'm also using std library to create vectors and I am having an issue while debugging: Eclipse does not allow me to view the content of the vectors.

Is there any way to be able to debug it properly?

Garrett
  • 4,007
  • 2
  • 41
  • 59
Frion3L
  • 1,502
  • 4
  • 24
  • 34
  • The chances that there are errors in `std::vector` are quite slim indeed, compared to the probability that the error is in your *use* of it. Are you really sure you need this? If you do, you'd need a debug version of the C++ standard library installed, and link against that... no idea how to do that in Eclipse, though. I never debugged the standard library in fourteen years of doing professional C++ maintenance. (Found two bugs in Boost and one in the IBM AIX debugger, though, so never say never. ;-) ) – DevSolar Mar 07 '14 at 09:24
  • Whatever problems you have, if any, the chances they are in the standard library are slim to none. The problems are probably how you use these classes, or what you try to store in the containers. – Some programmer dude Mar 07 '14 at 09:26
  • 2
    I may explained myself wrongly. I don't want to check how is the class vector made, I want to see what is inside a vector (my classes). – Frion3L Mar 07 '14 at 09:38
  • Still can't help with Eclipse CDT as I don't use it, but you *should* be able to inspect any object's contents. For `std::vector`, there's probably an element `data` or somesuch inside the vector object, holding the individual elements of the vector... bowing out of this and leaving the field to people actually using Eclipse CDT. – DevSolar Mar 07 '14 at 14:07
  • 5
    There is not an easy way to check a std::vector, that's why I'm asking this. – Frion3L Mar 07 '14 at 15:38
  • 1
    [Possible duplicate](http://stackoverflow.com/questions/3651862/better-variable-exploring-when-debugging-c-code-with-eclipse-cdt). – Garrett May 09 '14 at 10:15

1 Answers1

21

Debugging STL containers in Eclipse is not quite straightforward. Please have a look at this question and the answers explaining the reasons for this. The simplest way without fiddling with the GDB for me is this answer, which can be summarized as follows:

Expand your vector in the variable view, you should find a nested variable _M_start. Right-click, choose "Display As Array..." and enter the desired range. The elements should then show up nested under _M_start.

Community
  • 1
  • 1
jurgispods
  • 745
  • 8
  • 19