This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: GDB pretty printers for iterators
>>>>> "Jonathan" == Jonathan Wakely <jwakely.gcc@gmail.com> writes:
Tom> We could easily add a new gdb parameter to let you choose whether these
Tom> printers are activated. ÂSomething like "set print libstdcxx-iterators off"
Tom> (or whatever name you like).
Jonathan> FWIW I think that's an excellent idea.
I had written the patch, then I forgot about this until last night.
I intend to check this in, barring objections or comments. It adds a
new option, "set print dereference-iterators", defaulting to enabled.
Tom
2010-03-25 Tom Tromey <tromey@redhat.com>
* python/libstdcxx/v6/printers.py (PrintIterators): New class.
Instantiate it.
(lookup_function): Check iterator_printers_dict.
(build_libstdcxx_dictionary): Put iterators into
iterator_printers_dict.
(iterator_printers_dict): Initialize.
Index: python/libstdcxx/v6/printers.py
===================================================================
--- python/libstdcxx/v6/printers.py (revision 157496)
+++ python/libstdcxx/v6/printers.py (working copy)
@@ -639,6 +639,22 @@
def display_hint (self):
return 'map'
+# Let the user disable iterator printers.
+class PrintIterators (gdb.Parameter):
+ """When enabled, printing an iterator will automatically dereference it.
+When disabled, an iterator must be explicitly dereferenced using `*'."""
+
+ show_doc = "Show whether libstdc++ iterators are automatically dereferenced when printing."
+
+ set_doc = "Set whether libstdc++ iterators are automatically dereferenced when printing."
+
+ def __init__ (self, name):
+ super (PrintIterators, self).__init__ (name, gdb.COMMAND_DATA,
+ gdb.PARAM_BOOLEAN)
+ self.value = True
+
+iterator_param = PrintIterators ("print dereference-iterators")
+
def register_libstdcxx_printers (obj):
"Register libstdc++ pretty-printers with objfile Obj."
@@ -672,6 +688,11 @@
if function.search (typename):
return pretty_printers_dict[function] (val)
+ if iterator_param.value:
+ for function in iterator_printers_dict:
+ if function.search (typename):
+ return iterator_printers_dict[function] (val)
+
# Cannot find a pretty printer. Return None.
return None
@@ -740,24 +761,25 @@
if True:
# These shouldn't be necessary, if GDB "print *i" worked.
# But it often doesn't, so here they are.
- pretty_printers_dict[re.compile('^std::_List_iterator<.*>$')] = lambda val: StdListIteratorPrinter("std::_List_iterator",val)
- pretty_printers_dict[re.compile('^std::_List_const_iterator<.*>$')] = lambda val: StdListIteratorPrinter("std::_List_const_iterator",val)
- pretty_printers_dict[re.compile('^std::_Rb_tree_iterator<.*>$')] = lambda val: StdRbtreeIteratorPrinter(val)
- pretty_printers_dict[re.compile('^std::_Rb_tree_const_iterator<.*>$')] = lambda val: StdRbtreeIteratorPrinter(val)
- pretty_printers_dict[re.compile('^std::_Deque_iterator<.*>$')] = lambda val: StdDequeIteratorPrinter(val)
- pretty_printers_dict[re.compile('^std::_Deque_const_iterator<.*>$')] = lambda val: StdDequeIteratorPrinter(val)
- pretty_printers_dict[re.compile('^__gnu_cxx::__normal_iterator<.*>$')] = lambda val: StdVectorIteratorPrinter(val)
- pretty_printers_dict[re.compile('^__gnu_cxx::_Slist_iterator<.*>$')] = lambda val: StdSlistIteratorPrinter(val)
+ iterator_printers_dict[re.compile('^std::_List_iterator<.*>$')] = lambda val: StdListIteratorPrinter("std::_List_iterator",val)
+ iterator_printers_dict[re.compile('^std::_List_const_iterator<.*>$')] = lambda val: StdListIteratorPrinter("std::_List_const_iterator",val)
+ iterator_printers_dict[re.compile('^std::_Rb_tree_iterator<.*>$')] = lambda val: StdRbtreeIteratorPrinter(val)
+ iterator_printers_dict[re.compile('^std::_Rb_tree_const_iterator<.*>$')] = lambda val: StdRbtreeIteratorPrinter(val)
+ iterator_printers_dict[re.compile('^std::_Deque_iterator<.*>$')] = lambda val: StdDequeIteratorPrinter(val)
+ iterator_printers_dict[re.compile('^std::_Deque_const_iterator<.*>$')] = lambda val: StdDequeIteratorPrinter(val)
+ iterator_printers_dict[re.compile('^__gnu_cxx::__normal_iterator<.*>$')] = lambda val: StdVectorIteratorPrinter(val)
+ iterator_printers_dict[re.compile('^__gnu_cxx::_Slist_iterator<.*>$')] = lambda val: StdSlistIteratorPrinter(val)
# Debug (compiled with -D_GLIBCXX_DEBUG) printer registrations.
# The Rb_tree debug iterator when unwrapped from the encapsulating __gnu_debug::_Safe_iterator
# does not have the __norm namespace. Just use the existing printer registration for that.
- pretty_printers_dict[re.compile('^__gnu_debug::_Safe_iterator<.*>$')] = lambda val: StdDebugIteratorPrinter(val)
- pretty_printers_dict[re.compile('^std::__norm::_List_iterator<.*>$')] = lambda val: StdListIteratorPrinter ("std::__norm::_List_iterator",val)
- pretty_printers_dict[re.compile('^std::__norm::_List_const_iterator<.*>$')] = lambda val: StdListIteratorPrinter ("std::__norm::_List_const_iterator",val)
- pretty_printers_dict[re.compile('^std::__norm::_Deque_const_iterator<.*>$')] = lambda val: StdDequeIteratorPrinter(val)
- pretty_printers_dict[re.compile('^std::__norm::_Deque_iterator<.*>$')] = lambda val: StdDequeIteratorPrinter(val)
+ iterator_printers_dict[re.compile('^__gnu_debug::_Safe_iterator<.*>$')] = lambda val: StdDebugIteratorPrinter(val)
+ iterator_printers_dict[re.compile('^std::__norm::_List_iterator<.*>$')] = lambda val: StdListIteratorPrinter ("std::__norm::_List_iterator",val)
+ iterator_printers_dict[re.compile('^std::__norm::_List_const_iterator<.*>$')] = lambda val: StdListIteratorPrinter ("std::__norm::_List_const_iterator",val)
+ iterator_printers_dict[re.compile('^std::__norm::_Deque_const_iterator<.*>$')] = lambda val: StdDequeIteratorPrinter(val)
+ iterator_printers_dict[re.compile('^std::__norm::_Deque_iterator<.*>$')] = lambda val: StdDequeIteratorPrinter(val)
pretty_printers_dict = {}
+iterator_printers_dict = {}
build_libstdcxx_dictionary ()