This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
GDB pretty printers for iterators
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Cc: Tom Tromey <tromey at redhat dot com>, Phil Muldoon <pmuldoon at redhat dot com>
- Date: Wed, 17 Mar 2010 00:58:35 +0000
- Subject: 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.