This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GDB pretty printers for iterators


I've been playing with the GDB python printers again, and noticed that
printing an iterator just dereferences it and prints the value it
points to:

Breakpoint 1, main () at prettyprinter.cc:5
5         std::vector<int> s;
(gdb) n
6         s.push_back(2);
(gdb)
7         std::vector<int>::iterator j = s.begin();
(gdb)
8         std::vector<int>::iterator k = s.end();
(gdb)
9         return *j;
(gdb) p j
$1 = 2

I think I'd rather have iterators print something like "iterator
pointing to 2" or even "-> 2"

For the end iterator the value is misleading at best:

(gdb) p k
$2 = 0

We shouldn't be dereferencing past-the-end iterators.  Ideally that
would print a special value like "past-the-end" but I don't think that
is possible in general, only in debug mode.

Does anyone have any good ideas for improving the output?  I can look
into it, but it probably won't be soon.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]