Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to debug stl containers?



Permlink Replies: 9 - Last Post: Mar 29, 2017 7:43 AM Last Post By: Alex Belo
fasdfasdfasdf a...

Posts: 3
Registered: 4/18/16
How to debug stl containers?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 24, 2017 1:55 AM
How to get human readable representation of stl containers in debug window (use clang compiler)?

Edited by: fasdfasdfasdf asdfadsf on Mar 24, 2017 1:59 AM
Johannes Weinert

Posts: 90
Registered: 7/19/02
Re: How to debug stl containers? [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 24, 2017 4:39 AM   in response to: fasdfasdfasdf a... in response to: fasdfasdfasdf a...
Hi,

at least for std::vector of basic types (like int or double) you can use
*v._Myfirst()

for the first element. You can use the "Repeat count" option in the
watch to get more elements at once.

To get element i you can use
*(v._Myfirst() + i)


This will also work for strings but the evaluation is ugly.

I do not know any solution for complex element types or other STL
containers.

HTH

Hans

Am 24.03.2017 um 09:59 schrieb fasdfasdfasdf asdfadsf:

How to get human readable representation of stl containers in debug window (use clang compiler)?

Edited by: fasdfasdfasdf asdfadsf on Mar 24, 2017 1:59 AM
fasdfasdfasdf a...

Posts: 3
Registered: 4/18/16
Re: How to debug stl containers? [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 24, 2017 5:23 AM   in response to: Johannes Weinert in response to: Johannes Weinert
I'm doing it this way now. But it is very ugly way.
Why nobody write custom visualisers like it made for string?
I already write such for XCode (for stlport map, list, set), it was not very difficult.

Edited by: fasdfasdfasdf asdfadsf on Mar 24, 2017 5:59 AM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to debug stl containers? [Edit] [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 24, 2017 8:17 AM   in response to: fasdfasdfasdf a... in response to: fasdfasdfasdf a...
fasdfasdfasdf wrote:

Why nobody write custom visualisers like it made for string?

Because it can't be done easily, not unless Embarcadero first implements
RSP-16874 ("Support a wildcard syntax in debug visualizers"). Otherwise,
you would have to write a separate visualizer for every possible instantiation
of an STL container that you use (separate visualizers for std::vector<X>
vs std::vector<Y>, std::list<X> vs std::list<Y>, etc). STL containers are
templated, and visualizers do not support templates (or Delphi Generics)
yet. The only reason the std::(w)string visualizer works is because std::(w)string
are concrete specializations of a single templated class (std::basic_string),
so they are only to data types to visualize. When you start getting into
other STL containers, there are a lot more variations to support, and that
gets very ugly very quickly.

Visual Studio's debug visualizers are scripted, not compiled, so they are
very easy and flexible to write, and they support templates. Why Borland/CodeGear/Embarcadero
went the compiled route in the first place is beyond me. Even when they
wrote the std::(w)string visualizer, they didn't stop to think "hey, we just
wrote two separate visualizers that do the exact same thing for separate
instantiations, wouldn't it have been nice to just write one visualizer that
recognizes template parameters?".

--
Remy Lebeau (TeamB)
fasdfasdfasdf a...

Posts: 3
Registered: 4/18/16
Re: How to debug stl containers? [Edit] [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 24, 2017 3:54 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thanks for explanation.It sounds very sad.
Could you explain me how to use "Repeat num" to look some vector elements.
Alex Belo

Posts: 626
Registered: 10/8/06
Re: How to debug stl containers? [Edit] [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 24, 2017 10:25 PM   in response to: fasdfasdfasdf a... in response to: fasdfasdfasdf a...
fasdfasdfasdf asdfadsf wrote:

Could you explain me how to use "Repeat num" to look some vector
elements.

(I use RAD2007 and it works).

Just set required number of elements to see and debugger will show you
this number of sequential elements in array. Of course, this works for
arrays only (not for lists, for example); new C++ standard determines
internal vector's buffer as array in C terms (and it was C-arrays in
the past in most stl implementations).

--
Alex
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to debug stl containers? [Edit] [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 27, 2017 9:38 AM   in response to: Alex Belo in response to: Alex Belo
Alex wrote:

new C++ standard determines internal vector's buffer as array
in C terms (and it was C-arrays in the past in most stl
implementations).

A vector has always been defined as a contigious array in memory. That is
nothing "new" about that, that is one of its defining characteristics.

--
Remy Lebeau (TeamB)
Alex Belo

Posts: 626
Registered: 10/8/06
Re: How to debug stl containers? [Edit] [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 28, 2017 8:40 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

A vector has always been defined as a contigious array in memory.
That is nothing "new" about that, that is one of its defining
characteristics.

AFAIK this characteristic was officially declared only in C++11.
Formally before it was realization specific.

--
Alex
Arkady Semylio

Posts: 87
Registered: 9/18/15
Re: How to debug stl containers? [Edit] [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 28, 2017 11:38 AM   in response to: Alex Belo in response to: Alex Belo
Alex Belo wrote:
AFAIK this characteristic was officially declared only in C++11.
Formally before it was realization specific.

It's guaranteed the contiguity in C++03 standard (23.2.4.1)

Edited by: Arkady Semylio on Mar 28, 2017 11:57 AM
Alex Belo

Posts: 626
Registered: 10/8/06
Re: How to debug stl containers? [Edit] [Edit] [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2017 7:43 AM   in response to: Arkady Semylio in response to: Arkady Semylio
Arkady Semylio wrote:

It's guaranteed the contiguity in C++03 standard (23.2.4.1)

OK, thank you for information.

--
Alex
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02