GDB pretty printers for iterators
Jonathan Wakely
jwakely.gcc@gmail.com
Wed Mar 17 00:58:00 GMT 2010
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.
More information about the Libstdc++
mailing list