Viewing vectors in the debugger?
-
Hi, all –
I hope this question is considered on-topic. I've been using Creator as my IDE for several months now. In debugging sessions, it appears that visibility into vector objects is limited (not to mention cumbersome). Has anyone found a way to deal with this? It's greatly slowing down my debugging efforts.
Thanks.
-
Sure...so, I'm sure you know how arrays look: you can see the contents of each element. Well, with vectors, I can only see the first and the final elements, as the picture shows. I'm having some kind of problem with my constructors, and all I know is that the first element in the vector is properly initialized, and the last isn't. With my limited knowledge of the debugger, I have no way to view the elements in between.
!http://www.scopedin.com/images/vectors.jpg(vectors in debugger)!
-
to your question 1:
as you are using them yes, but not necessarily in general.to your question 2:
I would love to know the trick myself. Aren't vectors having all elements in sequence in memory? Then you could use a memory window, but this will work only for the basic types. -
You might try updating Qt Creator... I read something about std::vector support in the commit logs, so it might work with a newer version;-) I am tracking master, so this might or might not be in 2.3...
In general the GDB debugger (used for mingw binaries) tends to be a bit more complete than the CDB one, mostly since GDB sees much more action (and thus testing;-), being used by linux, mac and windows/mingw. So switching to mingw might be a quick way to improve debugging for you.
Please "file bug reports":http://bugreports.qt.nokia.com/ if something works in gdb but not cdb:-) Feel free to request features in the bug tracker, too.
-
[quote author="koahnig" date="1317845048"]to your question 2:
I would love to know the trick myself. Aren't vectors having all elements in sequence in memory? Then you could use a memory window, but this will work only for the basic types. [/quote]This is not enforced. For the clients, they look like a block of memory, as you just access via index, but it might have any implementation behind, e.g. for optimizing moving of objects, inserting them etc.
-
Hi, Tobias –
I'm running the latest (stable) Creator already. I think I'm using GDB...please remind me where that setting is, so I can confirm it?
Thanks.
EDIT: I just took a closer look at your comment regarding mingw. I don't believe that's an option for me, since I'm running on a Mac.
-
[quote author="Gerolf" date="1317891713"][quote author="koahnig" date="1317845048"]to your question 2:
I would love to know the trick myself. Aren't vectors having all elements in sequence in memory? Then you could use a memory window, but this will work only for the basic types. [/quote]This is not enforced. For the clients, they look like a block of memory, as you just access via index, but it might have any implementation behind, e.g. for optimizing moving of objects, inserting them etc.
[/quote]
Gerolf, I am certainly not arguing that this is a good solution and one should do it. However, in principle, you may do it for build-in data types also supported by the debugger. For vector they should allocate continuous memory according to "this":http://www.cplusplus.com/reference/stl/vector/ . However, you need to be very desperate to do so.Tobias, I am certainly will keep an eye on this next time when using creator. That is an interesting feedback.
-
If you are on the Mac then you are using GDB, alright:-)
-
OK, I've discovered a partial workaround. Not perfect, but helpful. Adding an iterator for the vector, and assigning it to the "current" element will at least allow you to see an element other than the first one.
Also, from my ongoing tinkering, it appears that the _M_finish element is not (as I first thought) the last valid element in the vector. It appears to be more of a sentinel element...I'm getting the impression that vectors are sort of a cross between arrays and linked lists.
Hope this helps someone.