1 # Pretty-printers for libstdc++.
3 # Copyright (C) 2008-2014 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ### Python 2 + Python 3 compatibility code
25 # Resources about compatibility:
27 # * <http://pythonhosted.org/six/>: Documentation of the "six" module
29 # FIXME: The handling of e.g. std::basic_string (at least on char)
30 # probably needs updating to work with Python 3's new string rules.
32 # In particular, Python 3 has a separate type (called byte) for
33 # bytestrings, and a special b"" syntax for the byte literals; the old
34 # str() type has been redefined to always store Unicode text.
36 # We probably can't do much about this until this GDB PR is addressed:
37 # <https://sourceware.org/bugzilla/show_bug.cgi?id=17138>
39 if sys.version_info[0] > 2:
42 # Python 3 folds these into the normal functions.
45 # Also, int subsumes long
50 """Compatibility mixin for iterators
52 Instead of writing next() methods for iterators, write
53 __next__() methods and use this mixin to make them work in
54 Python 2 as well as Python 3.
56 Idea stolen from the "six" documentation:
57 <http://pythonhosted.org/six/#six.Iterator>
61 return self.__next__()
63 # In Python 2, we still need these from itertools
64 from itertools import imap, izip
66 # Try to use the new-style pretty-printing if available.
73 # Try to install type-printers.
74 _use_type_printing = False
77 if hasattr(gdb.types, 'TypePrinter'):
78 _use_type_printing = True
82 # Starting with the type ORIG, search for the member type NAME. This
83 # handles searching upward through superclasses. This is needed to
84 # work around http://sourceware.org/bugzilla/show_bug.cgi?id=13615.
85 def find_type(orig, name):
86 typ = orig.strip_typedefs()
88 search = str(typ) + '::' + name
90 return gdb.lookup_type(search)
93 # The type was not found, so try the superclass. We only need
94 # to check the first superclass, so we don't bother with
95 # anything fancier here.
96 field = typ.fields()[0]
97 if not field.is_base_class:
98 raise ValueError("Cannot find type %s::%s" % (str(orig), name))
101 class SharedPointerPrinter:
102 "Print a shared_ptr or weak_ptr"
104 def __init__ (self, typename, val):
105 self.typename = typename
108 def to_string (self):
110 refcounts = self.val['_M_refcount']['_M_pi']
112 usecount = refcounts['_M_use_count']
113 weakcount = refcounts['_M_weak_count']
115 state = 'expired, weak %d' % weakcount
117 state = 'count %d, weak %d' % (usecount, weakcount - 1)
118 return '%s (%s) %s' % (self.typename, state, self.val['_M_ptr'])
120 class UniquePointerPrinter:
123 def __init__ (self, typename, val):
126 def to_string (self):
127 v = self.val['_M_t']['_M_head_impl']
128 return ('std::unique_ptr<%s> containing %s' % (str(v.type.target()),
131 class StdListPrinter:
134 class _iterator(Iterator):
135 def __init__(self, nodetype, head):
136 self.nodetype = nodetype
137 self.base = head['_M_next']
138 self.head = head.address
145 if self.base == self.head:
147 elt = self.base.cast(self.nodetype).dereference()
148 self.base = elt['_M_next']
150 self.count = self.count + 1
151 return ('[%d]' % count, elt['_M_data'])
153 def __init__(self, typename, val):
154 self.typename = typename
158 nodetype = find_type(self.val.type, '_Node')
159 nodetype = nodetype.strip_typedefs().pointer()
160 return self._iterator(nodetype, self.val['_M_impl']['_M_node'])
163 if self.val['_M_impl']['_M_node'].address == self.val['_M_impl']['_M_node']['_M_next']:
164 return 'empty %s' % (self.typename)
165 return '%s' % (self.typename)
167 class StdListIteratorPrinter:
168 "Print std::list::iterator"
170 def __init__(self, typename, val):
172 self.typename = typename
175 nodetype = find_type(self.val.type, '_Node')
176 nodetype = nodetype.strip_typedefs().pointer()
177 return self.val['_M_node'].cast(nodetype).dereference()['_M_data']
179 class StdSlistPrinter:
180 "Print a __gnu_cxx::slist"
182 class _iterator(Iterator):
183 def __init__(self, nodetype, head):
184 self.nodetype = nodetype
185 self.base = head['_M_head']['_M_next']
194 elt = self.base.cast(self.nodetype).dereference()
195 self.base = elt['_M_next']
197 self.count = self.count + 1
198 return ('[%d]' % count, elt['_M_data'])
200 def __init__(self, typename, val):
204 nodetype = find_type(self.val.type, '_Node')
205 nodetype = nodetype.strip_typedefs().pointer()
206 return self._iterator(nodetype, self.val)
209 if self.val['_M_head']['_M_next'] == 0:
210 return 'empty __gnu_cxx::slist'
211 return '__gnu_cxx::slist'
213 class StdSlistIteratorPrinter:
214 "Print __gnu_cxx::slist::iterator"
216 def __init__(self, typename, val):
220 nodetype = find_type(self.val.type, '_Node')
221 nodetype = nodetype.strip_typedefs().pointer()
222 return self.val['_M_node'].cast(nodetype).dereference()['_M_data']
224 class StdVectorPrinter:
225 "Print a std::vector"
227 class _iterator(Iterator):
228 def __init__ (self, start, finish, bitvec):
231 self.item = start['_M_p']
232 self.so = start['_M_offset']
233 self.finish = finish['_M_p']
234 self.fo = finish['_M_offset']
235 itype = self.item.dereference().type
236 self.isize = 8 * itype.sizeof
247 self.count = self.count + 1
249 if self.item == self.finish and self.so >= self.fo:
251 elt = self.item.dereference()
252 if elt & (1 << self.so):
256 self.so = self.so + 1
257 if self.so >= self.isize:
258 self.item = self.item + 1
260 return ('[%d]' % count, obit)
262 if self.item == self.finish:
264 elt = self.item.dereference()
265 self.item = self.item + 1
266 return ('[%d]' % count, elt)
268 def __init__(self, typename, val):
269 self.typename = typename
271 self.is_bool = val.type.template_argument(0).code == gdb.TYPE_CODE_BOOL
274 return self._iterator(self.val['_M_impl']['_M_start'],
275 self.val['_M_impl']['_M_finish'],
279 start = self.val['_M_impl']['_M_start']
280 finish = self.val['_M_impl']['_M_finish']
281 end = self.val['_M_impl']['_M_end_of_storage']
283 start = self.val['_M_impl']['_M_start']['_M_p']
284 so = self.val['_M_impl']['_M_start']['_M_offset']
285 finish = self.val['_M_impl']['_M_finish']['_M_p']
286 fo = self.val['_M_impl']['_M_finish']['_M_offset']
287 itype = start.dereference().type
288 bl = 8 * itype.sizeof
289 length = (bl - so) + bl * ((finish - start) - 1) + fo
290 capacity = bl * (end - start)
291 return ('%s<bool> of length %d, capacity %d'
292 % (self.typename, int (length), int (capacity)))
294 return ('%s of length %d, capacity %d'
295 % (self.typename, int (finish - start), int (end - start)))
297 def display_hint(self):
300 class StdVectorIteratorPrinter:
301 "Print std::vector::iterator"
303 def __init__(self, typename, val):
307 return self.val['_M_current'].dereference()
309 class StdTuplePrinter:
312 class _iterator(Iterator):
313 def __init__ (self, head):
316 # Set the base class as the initial head of the
318 nodes = self.head.type.fields ()
320 # Set the actual head to the first pair.
321 self.head = self.head.cast (nodes[0].type)
322 elif len (nodes) != 0:
323 raise ValueError("Top of tuple tree does not consist of a single node.")
330 nodes = self.head.type.fields ()
331 # Check for further recursions in the inheritance tree.
334 # Check that this iteration has an expected structure.
336 raise ValueError("Cannot parse more than 2 nodes in a tuple tree.")
338 # - Left node is the next recursion parent.
339 # - Right node is the actual class contained in the tuple.
341 # Process right node.
342 impl = self.head.cast (nodes[1].type)
344 # Process left node and set it as head.
345 self.head = self.head.cast (nodes[0].type)
346 self.count = self.count + 1
348 # Finally, check the implementation. If it is
349 # wrapped in _M_head_impl return that, otherwise return
351 fields = impl.type.fields ()
352 if len (fields) < 1 or fields[0].name != "_M_head_impl":
353 return ('[%d]' % self.count, impl)
355 return ('[%d]' % self.count, impl['_M_head_impl'])
357 def __init__ (self, typename, val):
358 self.typename = typename
362 return self._iterator (self.val)
364 def to_string (self):
365 if len (self.val.type.fields ()) == 0:
366 return 'empty %s' % (self.typename)
367 return '%s containing' % (self.typename)
369 class StdStackOrQueuePrinter:
370 "Print a std::stack or std::queue"
372 def __init__ (self, typename, val):
373 self.typename = typename
374 self.visualizer = gdb.default_visualizer(val['c'])
377 return self.visualizer.children()
379 def to_string (self):
380 return '%s wrapping: %s' % (self.typename,
381 self.visualizer.to_string())
383 def display_hint (self):
384 if hasattr (self.visualizer, 'display_hint'):
385 return self.visualizer.display_hint ()
388 class RbtreeIterator(Iterator):
389 def __init__(self, rbtree):
390 self.size = rbtree['_M_t']['_M_impl']['_M_node_count']
391 self.node = rbtree['_M_t']['_M_impl']['_M_header']['_M_left']
398 return int (self.size)
401 if self.count == self.size:
404 self.count = self.count + 1
405 if self.count < self.size:
406 # Compute the next node.
408 if node.dereference()['_M_right']:
409 node = node.dereference()['_M_right']
410 while node.dereference()['_M_left']:
411 node = node.dereference()['_M_left']
413 parent = node.dereference()['_M_parent']
414 while node == parent.dereference()['_M_right']:
416 parent = parent.dereference()['_M_parent']
417 if node.dereference()['_M_right'] != parent:
422 def get_value_from_Rb_tree_node(node):
423 """Returns the value held in an _Rb_tree_node<_Val>"""
425 member = node.type.fields()[1].name
426 if member == '_M_value_field':
427 # C++03 implementation, node contains the value as a member
428 return node['_M_value_field']
429 elif member == '_M_storage':
430 # C++11 implementation, node stores value in __aligned_buffer
431 p = node['_M_storage']['_M_storage'].address
432 p = p.cast(node.type.template_argument(0).pointer())
433 return p.dereference()
436 raise ValueError("Unsupported implementation for %s" % str(node.type))
438 # This is a pretty printer for std::_Rb_tree_iterator (which is
439 # std::map::iterator), and has nothing to do with the RbtreeIterator
441 class StdRbtreeIteratorPrinter:
442 "Print std::map::iterator"
444 def __init__ (self, typename, val):
447 def to_string (self):
448 typename = str(self.val.type.strip_typedefs()) + '::_Link_type'
449 nodetype = gdb.lookup_type(typename).strip_typedefs()
450 node = self.val.cast(nodetype).dereference()
451 return get_value_from_Rb_tree_node(node)
453 class StdDebugIteratorPrinter:
454 "Print a debug enabled version of an iterator"
456 def __init__ (self, typename, val):
459 # Just strip away the encapsulating __gnu_debug::_Safe_iterator
460 # and return the wrapped iterator value.
461 def to_string (self):
462 itype = self.val.type.template_argument(0)
463 return self.val['_M_current'].cast(itype)
466 "Print a std::map or std::multimap"
468 # Turn an RbtreeIterator into a pretty-print iterator.
469 class _iter(Iterator):
470 def __init__(self, rbiter, type):
479 if self.count % 2 == 0:
480 n = next(self.rbiter)
481 n = n.cast(self.type).dereference()
482 n = get_value_from_Rb_tree_node(n)
486 item = self.pair['second']
487 result = ('[%d]' % self.count, item)
488 self.count = self.count + 1
491 def __init__ (self, typename, val):
492 self.typename = typename
495 def to_string (self):
496 return '%s with %d elements' % (self.typename,
497 len (RbtreeIterator (self.val)))
500 rep_type = find_type(self.val.type, '_Rep_type')
501 node = find_type(rep_type, '_Link_type')
502 node = node.strip_typedefs()
503 return self._iter (RbtreeIterator (self.val), node)
505 def display_hint (self):
509 "Print a std::set or std::multiset"
511 # Turn an RbtreeIterator into a pretty-print iterator.
512 class _iter(Iterator):
513 def __init__(self, rbiter, type):
522 item = next(self.rbiter)
523 item = item.cast(self.type).dereference()
524 item = get_value_from_Rb_tree_node(item)
525 # FIXME: this is weird ... what to do?
526 # Maybe a 'set' display hint?
527 result = ('[%d]' % self.count, item)
528 self.count = self.count + 1
531 def __init__ (self, typename, val):
532 self.typename = typename
535 def to_string (self):
536 return '%s with %d elements' % (self.typename,
537 len (RbtreeIterator (self.val)))
540 rep_type = find_type(self.val.type, '_Rep_type')
541 node = find_type(rep_type, '_Link_type')
542 node = node.strip_typedefs()
543 return self._iter (RbtreeIterator (self.val), node)
545 class StdBitsetPrinter:
546 "Print a std::bitset"
548 def __init__(self, typename, val):
549 self.typename = typename
552 def to_string (self):
553 # If template_argument handled values, we could print the
554 # size. Or we could use a regexp on the type.
555 return '%s' % (self.typename)
558 words = self.val['_M_w']
561 # The _M_w member can be either an unsigned long, or an
562 # array. This depends on the template specialization used.
563 # If it is a single long, convert to a single element list.
564 if wtype.code == gdb.TYPE_CODE_ARRAY:
565 tsize = wtype.target ().sizeof
570 nwords = wtype.sizeof / tsize
578 # Another spot where we could use 'set'?
579 result.append(('[%d]' % (byte * tsize * 8 + bit), 1))
585 class StdDequePrinter:
588 class _iter(Iterator):
589 def __init__(self, node, start, end, last, buffer_size):
594 self.buffer_size = buffer_size
601 if self.p == self.last:
604 result = ('[%d]' % self.count, self.p.dereference())
605 self.count = self.count + 1
607 # Advance the 'cur' pointer.
609 if self.p == self.end:
610 # If we got to the end of this bucket, move to the
612 self.node = self.node + 1
613 self.p = self.node[0]
614 self.end = self.p + self.buffer_size
618 def __init__(self, typename, val):
619 self.typename = typename
621 self.elttype = val.type.template_argument(0)
622 size = self.elttype.sizeof
624 self.buffer_size = int (512 / size)
629 start = self.val['_M_impl']['_M_start']
630 end = self.val['_M_impl']['_M_finish']
632 delta_n = end['_M_node'] - start['_M_node'] - 1
633 delta_s = start['_M_last'] - start['_M_cur']
634 delta_e = end['_M_cur'] - end['_M_first']
636 size = self.buffer_size * delta_n + delta_s + delta_e
638 return '%s with %d elements' % (self.typename, long (size))
641 start = self.val['_M_impl']['_M_start']
642 end = self.val['_M_impl']['_M_finish']
643 return self._iter(start['_M_node'], start['_M_cur'], start['_M_last'],
644 end['_M_cur'], self.buffer_size)
646 def display_hint (self):
649 class StdDequeIteratorPrinter:
650 "Print std::deque::iterator"
652 def __init__(self, typename, val):
656 return self.val['_M_cur'].dereference()
658 class StdStringPrinter:
659 "Print a std::basic_string of some kind"
661 def __init__(self, typename, val):
665 # Make sure &string works, too.
667 if type.code == gdb.TYPE_CODE_REF:
668 type = type.target ()
670 # Calculate the length of the string so that to_string returns
671 # the string according to length, not according to first null
673 ptr = self.val ['_M_dataplus']['_M_p']
674 realtype = type.unqualified ().strip_typedefs ()
675 reptype = gdb.lookup_type (str (realtype) + '::_Rep').pointer ()
676 header = ptr.cast(reptype) - 1
677 len = header.dereference ()['_M_length']
678 if hasattr(ptr, "lazy_string"):
679 return ptr.lazy_string (length = len)
680 return ptr.string (length = len)
682 def display_hint (self):
685 class Tr1HashtableIterator(Iterator):
686 def __init__ (self, hash):
687 self.buckets = hash['_M_buckets']
689 self.bucket_count = hash['_M_bucket_count']
690 self.node_type = find_type(hash.type, '_Node').pointer()
692 while self.bucket != self.bucket_count:
693 self.node = self.buckets[self.bucket]
696 self.bucket = self.bucket + 1
704 node = self.node.cast(self.node_type)
705 result = node.dereference()['_M_v']
706 self.node = node.dereference()['_M_next'];
708 self.bucket = self.bucket + 1
709 while self.bucket != self.bucket_count:
710 self.node = self.buckets[self.bucket]
713 self.bucket = self.bucket + 1
716 class StdHashtableIterator(Iterator):
717 def __init__(self, hash):
718 self.node = hash['_M_before_begin']['_M_nxt']
719 self.node_type = find_type(hash.type, '__node_type').pointer()
727 elt = self.node.cast(self.node_type).dereference()
728 self.node = elt['_M_nxt']
729 valptr = elt['_M_storage'].address
730 valptr = valptr.cast(elt.type.template_argument(0).pointer())
731 return valptr.dereference()
733 class Tr1UnorderedSetPrinter:
734 "Print a tr1::unordered_set"
736 def __init__ (self, typename, val):
737 self.typename = typename
740 def hashtable (self):
741 if self.typename.startswith('std::tr1'):
743 return self.val['_M_h']
745 def to_string (self):
746 return '%s with %d elements' % (self.typename, self.hashtable()['_M_element_count'])
749 def format_count (i):
753 counter = imap (self.format_count, itertools.count())
754 if self.typename.startswith('std::tr1'):
755 return izip (counter, Tr1HashtableIterator (self.hashtable()))
756 return izip (counter, StdHashtableIterator (self.hashtable()))
758 class Tr1UnorderedMapPrinter:
759 "Print a tr1::unordered_map"
761 def __init__ (self, typename, val):
762 self.typename = typename
765 def hashtable (self):
766 if self.typename.startswith('std::tr1'):
768 return self.val['_M_h']
770 def to_string (self):
771 return '%s with %d elements' % (self.typename, self.hashtable()['_M_element_count'])
780 def format_one (elt):
781 return (elt['first'], elt['second'])
784 def format_count (i):
788 counter = imap (self.format_count, itertools.count())
789 # Map over the hash table and flatten the result.
790 if self.typename.startswith('std::tr1'):
791 data = self.flatten (imap (self.format_one, Tr1HashtableIterator (self.hashtable())))
792 # Zip the two iterators together.
793 return izip (counter, data)
794 data = self.flatten (imap (self.format_one, StdHashtableIterator (self.hashtable())))
795 # Zip the two iterators together.
796 return izip (counter, data)
799 def display_hint (self):
802 class StdForwardListPrinter:
803 "Print a std::forward_list"
805 class _iterator(Iterator):
806 def __init__(self, nodetype, head):
807 self.nodetype = nodetype
808 self.base = head['_M_next']
817 elt = self.base.cast(self.nodetype).dereference()
818 self.base = elt['_M_next']
820 self.count = self.count + 1
821 valptr = elt['_M_storage'].address
822 valptr = valptr.cast(elt.type.template_argument(0).pointer())
823 return ('[%d]' % count, valptr.dereference())
825 def __init__(self, typename, val):
827 self.typename = typename
830 nodetype = find_type(self.val.type, '_Node')
831 nodetype = nodetype.strip_typedefs().pointer()
832 return self._iterator(nodetype, self.val['_M_impl']['_M_head'])
835 if self.val['_M_impl']['_M_head']['_M_next'] == 0:
836 return 'empty %s' % (self.typename)
837 return '%s' % (self.typename)
840 # A "regular expression" printer which conforms to the
841 # "SubPrettyPrinter" protocol from gdb.printing.
842 class RxPrinter(object):
843 def __init__(self, name, function):
844 super(RxPrinter, self).__init__()
846 self.function = function
849 def invoke(self, value):
853 if value.type.code == gdb.TYPE_CODE_REF:
854 if hasattr(gdb.Value,"referenced_value"):
855 value = value.referenced_value()
857 return self.function(self.name, value)
859 # A pretty-printer that conforms to the "PrettyPrinter" protocol from
860 # gdb.printing. It can also be used directly as an old-style printer.
861 class Printer(object):
862 def __init__(self, name):
863 super(Printer, self).__init__()
865 self.subprinters = []
868 self.compiled_rx = re.compile('^([a-zA-Z0-9_:]+)<.*>$')
870 def add(self, name, function):
871 # A small sanity check.
873 if not self.compiled_rx.match(name + '<>'):
874 raise ValueError('libstdc++ programming error: "%s" does not match' % name)
875 printer = RxPrinter(name, function)
876 self.subprinters.append(printer)
877 self.lookup[name] = printer
879 # Add a name using _GLIBCXX_BEGIN_NAMESPACE_VERSION.
880 def add_version(self, base, name, function):
881 self.add(base + name, function)
882 self.add(base + '__7::' + name, function)
884 # Add a name using _GLIBCXX_BEGIN_NAMESPACE_CONTAINER.
885 def add_container(self, base, name, function):
886 self.add_version(base, name, function)
887 self.add_version(base + '__cxx1998::', name, function)
890 def get_basic_type(type):
891 # If it points to a reference, get the reference.
892 if type.code == gdb.TYPE_CODE_REF:
893 type = type.target ()
895 # Get the unqualified type, stripped of typedefs.
896 type = type.unqualified ().strip_typedefs ()
900 def __call__(self, val):
901 typename = self.get_basic_type(val.type)
905 # All the types we match are template types, so we can use a
907 match = self.compiled_rx.match(typename)
911 basename = match.group(1)
913 if val.type.code == gdb.TYPE_CODE_REF:
914 if hasattr(gdb.Value,"referenced_value"):
915 val = val.referenced_value()
917 if basename in self.lookup:
918 return self.lookup[basename].invoke(val)
920 # Cannot find a pretty printer. Return None.
923 libstdcxx_printer = None
925 class FilteringTypePrinter(object):
926 def __init__(self, match, name):
931 class _recognizer(object):
932 def __init__(self, match, name):
937 def recognize(self, type_obj):
938 if type_obj.tag is None:
941 if self.type_obj is None:
942 if not self.match in type_obj.tag:
943 # Filter didn't match.
946 self.type_obj = gdb.lookup_type(self.name).strip_typedefs()
949 if self.type_obj == type_obj:
953 def instantiate(self):
954 return self._recognizer(self.match, self.name)
956 def add_one_type_printer(obj, match, name):
957 printer = FilteringTypePrinter(match, 'std::' + name)
958 gdb.types.register_type_printer(obj, printer)
960 def register_type_printers(obj):
961 global _use_type_printing
963 if not _use_type_printing:
966 for pfx in ('', 'w'):
967 add_one_type_printer(obj, 'basic_string', pfx + 'string')
968 add_one_type_printer(obj, 'basic_ios', pfx + 'ios')
969 add_one_type_printer(obj, 'basic_streambuf', pfx + 'streambuf')
970 add_one_type_printer(obj, 'basic_istream', pfx + 'istream')
971 add_one_type_printer(obj, 'basic_ostream', pfx + 'ostream')
972 add_one_type_printer(obj, 'basic_iostream', pfx + 'iostream')
973 add_one_type_printer(obj, 'basic_stringbuf', pfx + 'stringbuf')
974 add_one_type_printer(obj, 'basic_istringstream',
975 pfx + 'istringstream')
976 add_one_type_printer(obj, 'basic_ostringstream',
977 pfx + 'ostringstream')
978 add_one_type_printer(obj, 'basic_stringstream',
979 pfx + 'stringstream')
980 add_one_type_printer(obj, 'basic_filebuf', pfx + 'filebuf')
981 add_one_type_printer(obj, 'basic_ifstream', pfx + 'ifstream')
982 add_one_type_printer(obj, 'basic_ofstream', pfx + 'ofstream')
983 add_one_type_printer(obj, 'basic_fstream', pfx + 'fstream')
984 add_one_type_printer(obj, 'basic_regex', pfx + 'regex')
985 add_one_type_printer(obj, 'sub_match', pfx + 'csub_match')
986 add_one_type_printer(obj, 'sub_match', pfx + 'ssub_match')
987 add_one_type_printer(obj, 'match_results', pfx + 'cmatch')
988 add_one_type_printer(obj, 'match_results', pfx + 'smatch')
989 add_one_type_printer(obj, 'regex_iterator', pfx + 'cregex_iterator')
990 add_one_type_printer(obj, 'regex_iterator', pfx + 'sregex_iterator')
991 add_one_type_printer(obj, 'regex_token_iterator',
992 pfx + 'cregex_token_iterator')
993 add_one_type_printer(obj, 'regex_token_iterator',
994 pfx + 'sregex_token_iterator')
996 # Note that we can't have a printer for std::wstreampos, because
997 # it shares the same underlying type as std::streampos.
998 add_one_type_printer(obj, 'fpos', 'streampos')
999 add_one_type_printer(obj, 'basic_string', 'u16string')
1000 add_one_type_printer(obj, 'basic_string', 'u32string')
1002 for dur in ('nanoseconds', 'microseconds', 'milliseconds',
1003 'seconds', 'minutes', 'hours'):
1004 add_one_type_printer(obj, 'duration', dur)
1006 add_one_type_printer(obj, 'linear_congruential_engine', 'minstd_rand0')
1007 add_one_type_printer(obj, 'linear_congruential_engine', 'minstd_rand')
1008 add_one_type_printer(obj, 'mersenne_twister_engine', 'mt19937')
1009 add_one_type_printer(obj, 'mersenne_twister_engine', 'mt19937_64')
1010 add_one_type_printer(obj, 'subtract_with_carry_engine', 'ranlux24_base')
1011 add_one_type_printer(obj, 'subtract_with_carry_engine', 'ranlux48_base')
1012 add_one_type_printer(obj, 'discard_block_engine', 'ranlux24')
1013 add_one_type_printer(obj, 'discard_block_engine', 'ranlux48')
1014 add_one_type_printer(obj, 'shuffle_order_engine', 'knuth_b')
1016 def register_libstdcxx_printers (obj):
1017 "Register libstdc++ pretty-printers with objfile Obj."
1020 global libstdcxx_printer
1023 gdb.printing.register_pretty_printer(obj, libstdcxx_printer)
1027 obj.pretty_printers.append(libstdcxx_printer)
1029 register_type_printers(obj)
1031 def build_libstdcxx_dictionary ():
1032 global libstdcxx_printer
1034 libstdcxx_printer = Printer("libstdc++-v6")
1036 # For _GLIBCXX_BEGIN_NAMESPACE_VERSION.
1038 # For _GLIBCXX_BEGIN_NAMESPACE_CONTAINER.
1039 container = '(__cxx1998::' + vers + ')?'
1041 # libstdc++ objects requiring pretty-printing.
1043 # http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01847.html
1044 libstdcxx_printer.add_version('std::', 'basic_string', StdStringPrinter)
1045 libstdcxx_printer.add_container('std::', 'bitset', StdBitsetPrinter)
1046 libstdcxx_printer.add_container('std::', 'deque', StdDequePrinter)
1047 libstdcxx_printer.add_container('std::', 'list', StdListPrinter)
1048 libstdcxx_printer.add_container('std::', 'map', StdMapPrinter)
1049 libstdcxx_printer.add_container('std::', 'multimap', StdMapPrinter)
1050 libstdcxx_printer.add_container('std::', 'multiset', StdSetPrinter)
1051 libstdcxx_printer.add_version('std::', 'priority_queue',
1052 StdStackOrQueuePrinter)
1053 libstdcxx_printer.add_version('std::', 'queue', StdStackOrQueuePrinter)
1054 libstdcxx_printer.add_version('std::', 'tuple', StdTuplePrinter)
1055 libstdcxx_printer.add_container('std::', 'set', StdSetPrinter)
1056 libstdcxx_printer.add_version('std::', 'stack', StdStackOrQueuePrinter)
1057 libstdcxx_printer.add_version('std::', 'unique_ptr', UniquePointerPrinter)
1058 libstdcxx_printer.add_container('std::', 'vector', StdVectorPrinter)
1061 # Printer registrations for classes compiled with -D_GLIBCXX_DEBUG.
1062 libstdcxx_printer.add('std::__debug::bitset', StdBitsetPrinter)
1063 libstdcxx_printer.add('std::__debug::deque', StdDequePrinter)
1064 libstdcxx_printer.add('std::__debug::list', StdListPrinter)
1065 libstdcxx_printer.add('std::__debug::map', StdMapPrinter)
1066 libstdcxx_printer.add('std::__debug::multimap', StdMapPrinter)
1067 libstdcxx_printer.add('std::__debug::multiset', StdSetPrinter)
1068 libstdcxx_printer.add('std::__debug::priority_queue',
1069 StdStackOrQueuePrinter)
1070 libstdcxx_printer.add('std::__debug::queue', StdStackOrQueuePrinter)
1071 libstdcxx_printer.add('std::__debug::set', StdSetPrinter)
1072 libstdcxx_printer.add('std::__debug::stack', StdStackOrQueuePrinter)
1073 libstdcxx_printer.add('std::__debug::unique_ptr', UniquePointerPrinter)
1074 libstdcxx_printer.add('std::__debug::vector', StdVectorPrinter)
1076 # These are the TR1 and C++0x printers.
1077 # For array - the default GDB pretty-printer seems reasonable.
1078 libstdcxx_printer.add_version('std::', 'shared_ptr', SharedPointerPrinter)
1079 libstdcxx_printer.add_version('std::', 'weak_ptr', SharedPointerPrinter)
1080 libstdcxx_printer.add_container('std::', 'unordered_map',
1081 Tr1UnorderedMapPrinter)
1082 libstdcxx_printer.add_container('std::', 'unordered_set',
1083 Tr1UnorderedSetPrinter)
1084 libstdcxx_printer.add_container('std::', 'unordered_multimap',
1085 Tr1UnorderedMapPrinter)
1086 libstdcxx_printer.add_container('std::', 'unordered_multiset',
1087 Tr1UnorderedSetPrinter)
1088 libstdcxx_printer.add_container('std::', 'forward_list',
1089 StdForwardListPrinter)
1091 libstdcxx_printer.add_version('std::tr1::', 'shared_ptr', SharedPointerPrinter)
1092 libstdcxx_printer.add_version('std::tr1::', 'weak_ptr', SharedPointerPrinter)
1093 libstdcxx_printer.add_version('std::tr1::', 'unordered_map',
1094 Tr1UnorderedMapPrinter)
1095 libstdcxx_printer.add_version('std::tr1::', 'unordered_set',
1096 Tr1UnorderedSetPrinter)
1097 libstdcxx_printer.add_version('std::tr1::', 'unordered_multimap',
1098 Tr1UnorderedMapPrinter)
1099 libstdcxx_printer.add_version('std::tr1::', 'unordered_multiset',
1100 Tr1UnorderedSetPrinter)
1102 # These are the C++0x printer registrations for -D_GLIBCXX_DEBUG cases.
1103 # The tr1 namespace printers do not seem to have any debug
1104 # equivalents, so do no register them.
1105 libstdcxx_printer.add('std::__debug::unordered_map',
1106 Tr1UnorderedMapPrinter)
1107 libstdcxx_printer.add('std::__debug::unordered_set',
1108 Tr1UnorderedSetPrinter)
1109 libstdcxx_printer.add('std::__debug::unordered_multimap',
1110 Tr1UnorderedMapPrinter)
1111 libstdcxx_printer.add('std::__debug::unordered_multiset',
1112 Tr1UnorderedSetPrinter)
1113 libstdcxx_printer.add('std::__debug::forward_list',
1114 StdForwardListPrinter)
1118 libstdcxx_printer.add_version('__gnu_cxx::', 'slist', StdSlistPrinter)
1121 # These shouldn't be necessary, if GDB "print *i" worked.
1122 # But it often doesn't, so here they are.
1123 libstdcxx_printer.add_container('std::', '_List_iterator',
1124 StdListIteratorPrinter)
1125 libstdcxx_printer.add_container('std::', '_List_const_iterator',
1126 StdListIteratorPrinter)
1127 libstdcxx_printer.add_version('std::', '_Rb_tree_iterator',
1128 StdRbtreeIteratorPrinter)
1129 libstdcxx_printer.add_version('std::', '_Rb_tree_const_iterator',
1130 StdRbtreeIteratorPrinter)
1131 libstdcxx_printer.add_container('std::', '_Deque_iterator',
1132 StdDequeIteratorPrinter)
1133 libstdcxx_printer.add_container('std::', '_Deque_const_iterator',
1134 StdDequeIteratorPrinter)
1135 libstdcxx_printer.add_version('__gnu_cxx::', '__normal_iterator',
1136 StdVectorIteratorPrinter)
1137 libstdcxx_printer.add_version('__gnu_cxx::', '_Slist_iterator',
1138 StdSlistIteratorPrinter)
1140 # Debug (compiled with -D_GLIBCXX_DEBUG) printer
1141 # registrations. The Rb_tree debug iterator when unwrapped
1142 # from the encapsulating __gnu_debug::_Safe_iterator does not
1143 # have the __norm namespace. Just use the existing printer
1144 # registration for that.
1145 libstdcxx_printer.add('__gnu_debug::_Safe_iterator',
1146 StdDebugIteratorPrinter)
1147 libstdcxx_printer.add('std::__norm::_List_iterator',
1148 StdListIteratorPrinter)
1149 libstdcxx_printer.add('std::__norm::_List_const_iterator',
1150 StdListIteratorPrinter)
1151 libstdcxx_printer.add('std::__norm::_Deque_const_iterator',
1152 StdDequeIteratorPrinter)
1153 libstdcxx_printer.add('std::__norm::_Deque_iterator',
1154 StdDequeIteratorPrinter)
1156 build_libstdcxx_dictionary ()