OSDN Git Service

2009-10-01 Phil Muldoon <pmuldoon@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / python / libstdcxx / v6 / printers.py
1 # Pretty-printers for libstc++.
2
3 # Copyright (C) 2008, 2009 Free Software Foundation, Inc.
4
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.
9 #
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.
14 #
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/>.
17
18 import gdb
19 import itertools
20 import re
21
22 class StdPointerPrinter:
23     "Print a smart pointer of some kind"
24
25     def __init__ (self, typename, val):
26         self.typename = typename
27         self.val = val
28
29     def to_string (self):
30         if self.val['_M_refcount']['_M_pi'] == 0:
31             return '%s (empty) %s' % (self.typename, self.val['_M_ptr'])
32         return '%s (count %d) %s' % (self.typename,
33                                      self.val['_M_refcount']['_M_pi']['_M_use_count'],
34                                      self.val['_M_ptr'])
35
36 class UniquePointerPrinter:
37     "Print a unique_ptr"
38
39     def __init__ (self, val):
40         self.val = val
41
42     def to_string (self):
43         return self.val['_M_t']
44
45 class StdListPrinter:
46     "Print a std::list"
47
48     class _iterator:
49         def __init__(self, nodetype, head):
50             self.nodetype = nodetype
51             self.base = head['_M_next']
52             self.head = head.address
53             self.count = 0
54
55         def __iter__(self):
56             return self
57
58         def next(self):
59             if self.base == self.head:
60                 raise StopIteration
61             elt = self.base.cast(self.nodetype).dereference()
62             self.base = elt['_M_next']
63             count = self.count
64             self.count = self.count + 1
65             return ('[%d]' % count, elt['_M_data'])
66
67     def __init__(self, typename, val):
68         self.typename = typename
69         self.val = val
70
71     def children(self):
72         itype = self.val.type.template_argument(0)
73         # If the inferior program is compiled with -D_GLIBCXX_DEBUG
74         # some of the internal implementation details change.
75         if self.typename == "std::list":
76             nodetype = gdb.lookup_type('std::_List_node<%s>' % itype).pointer()
77         elif self.typename == "std::__debug::list":
78             nodetype = gdb.lookup_type('std::__norm::_List_node<%s>' % itype).pointer()
79         else:
80             raise "Cannot cast list node for list printer."
81         return self._iterator(nodetype, self.val['_M_impl']['_M_node'])
82
83     def to_string(self):
84         if self.val['_M_impl']['_M_node'].address == self.val['_M_impl']['_M_node']['_M_next']:
85             return 'empty %s' % (self.typename)
86         return '%s' % (self.typename)
87
88 class StdListIteratorPrinter:
89     "Print std::list::iterator"
90
91     def __init__(self, typename, val):
92         self.val = val
93         self.typename = typename
94
95     def to_string(self):
96         itype = self.val.type.template_argument(0)
97         # If the inferior program is compiled with -D_GLIBCXX_DEBUG
98         # some of the internal implementation details change.
99         if self.typename == "std::_List_iterator" or self.typename == "std::_List_const_iterator":
100             nodetype = gdb.lookup_type('std::_List_node<%s>' % itype).pointer()
101         elif self.typename == "std::__norm::_List_iterator" or self.typename == "std::__norm::_List_const_iterator":
102             nodetype = gdb.lookup_type('std::__norm::_List_node<%s>' % itype).pointer()
103         else:
104             raise "Cannot cast list node for list iterator printer."
105         return self.val['_M_node'].cast(nodetype).dereference()['_M_data']
106
107 class StdSlistPrinter:
108     "Print a __gnu_cxx::slist"
109
110     class _iterator:
111         def __init__(self, nodetype, head):
112             self.nodetype = nodetype
113             self.base = head['_M_head']['_M_next']
114             self.count = 0
115
116         def __iter__(self):
117             return self
118
119         def next(self):
120             if self.base == 0:
121                 raise StopIteration
122             elt = self.base.cast(self.nodetype).dereference()
123             self.base = elt['_M_next']
124             count = self.count
125             self.count = self.count + 1
126             return ('[%d]' % count, elt['_M_data'])
127
128     def __init__(self, val):
129         self.val = val
130
131     def children(self):
132         itype = self.val.type.template_argument(0)
133         nodetype = gdb.lookup_type('__gnu_cxx::_Slist_node<%s>' % itype).pointer()
134         return self._iterator(nodetype, self.val)
135
136     def to_string(self):
137         if self.val['_M_head']['_M_next'] == 0:
138             return 'empty __gnu_cxx::slist'
139         return '__gnu_cxx::slist'
140
141 class StdSlistIteratorPrinter:
142     "Print __gnu_cxx::slist::iterator"
143
144     def __init__(self, val):
145         self.val = val
146
147     def to_string(self):
148         itype = self.val.type.template_argument(0)
149         nodetype = gdb.lookup_type('__gnu_cxx::_Slist_node<%s>' % itype).pointer()
150         return self.val['_M_node'].cast(nodetype).dereference()['_M_data']
151
152 class StdVectorPrinter:
153     "Print a std::vector"
154
155     class _iterator:
156         def __init__ (self, start, finish):
157             self.item = start
158             self.finish = finish
159             self.count = 0
160
161         def __iter__(self):
162             return self
163
164         def next(self):
165             if self.item == self.finish:
166                 raise StopIteration
167             count = self.count
168             self.count = self.count + 1
169             elt = self.item.dereference()
170             self.item = self.item + 1
171             return ('[%d]' % count, elt)
172
173     def __init__(self, typename, val):
174         self.typename = typename
175         self.val = val
176
177     def children(self):
178         return self._iterator(self.val['_M_impl']['_M_start'],
179                               self.val['_M_impl']['_M_finish'])
180
181     def to_string(self):
182         start = self.val['_M_impl']['_M_start']
183         finish = self.val['_M_impl']['_M_finish']
184         end = self.val['_M_impl']['_M_end_of_storage']
185         return ('%s of length %d, capacity %d'
186                 % (self.typename, int (finish - start), int (end - start)))
187
188     def display_hint(self):
189         return 'array'
190
191 class StdVectorIteratorPrinter:
192     "Print std::vector::iterator"
193
194     def __init__(self, val):
195         self.val = val
196
197     def to_string(self):
198         return self.val['_M_current'].dereference()
199
200 class StdStackOrQueuePrinter:
201     "Print a std::stack or std::queue"
202
203     def __init__ (self, typename, val):
204         self.typename = typename
205         self.visualizer = gdb.default_visualizer(val['c'])
206
207     def children (self):
208         return self.visualizer.children()
209
210     def to_string (self):
211         return '%s wrapping: %s' % (self.typename,
212                                     self.visualizer.to_string())
213
214     def display_hint (self):
215         if hasattr (self.visualizer, 'display_hint'):
216             return self.visualizer.display_hint ()
217         return None
218
219 class RbtreeIterator:
220     def __init__(self, rbtree):
221         self.size = rbtree['_M_t']['_M_impl']['_M_node_count']
222         self.node = rbtree['_M_t']['_M_impl']['_M_header']['_M_left']
223         self.count = 0
224
225     def __iter__(self):
226         return self
227
228     def __len__(self):
229         return int (self.size)
230
231     def next(self):
232         if self.count == self.size:
233             raise StopIteration
234         result = self.node
235         self.count = self.count + 1
236         if self.count < self.size:
237             # Compute the next node.
238             node = self.node
239             if node.dereference()['_M_right']:
240                 node = node.dereference()['_M_right']
241                 while node.dereference()['_M_left']:
242                     node = node.dereference()['_M_left']
243             else:
244                 parent = node.dereference()['_M_parent']
245                 while node == parent.dereference()['_M_right']:
246                     node = parent
247                     parent = parent.dereference()['_M_parent']
248                 if node.dereference()['_M_right'] != parent:
249                     node = parent
250             self.node = node
251         return result
252
253 # This is a pretty printer for std::_Rb_tree_iterator (which is
254 # std::map::iterator), and has nothing to do with the RbtreeIterator
255 # class above.
256 class StdRbtreeIteratorPrinter:
257     "Print std::map::iterator"
258
259     def __init__ (self, val):
260         self.val = val
261
262     def to_string (self):
263         valuetype = self.val.type.template_argument(0)
264         nodetype = gdb.lookup_type('std::_Rb_tree_node < %s >' % valuetype)
265         nodetype = nodetype.pointer()
266         return self.val.cast(nodetype).dereference()['_M_value_field']
267
268 class StdDebugIteratorPrinter:
269     "Print a debug enabled version of an iterator"
270
271     def __init__ (self, val):
272         self.val = val
273
274     # Just strip away the encapsulating __gnu_debug::_Safe_iterator
275     # and return the wrapped iterator value.
276     def to_string (self):
277         itype = self.val.type.template_argument(0)
278         return self.val['_M_current'].cast(itype)
279
280 class StdMapPrinter:
281     "Print a std::map or std::multimap"
282
283     # Turn an RbtreeIterator into a pretty-print iterator.
284     class _iter:
285         def __init__(self, rbiter, type):
286             self.rbiter = rbiter
287             self.count = 0
288             self.type = type
289
290         def __iter__(self):
291             return self
292
293         def next(self):
294             if self.count % 2 == 0:
295                 n = self.rbiter.next()
296                 n = n.cast(self.type).dereference()['_M_value_field']
297                 self.pair = n
298                 item = n['first']
299             else:
300                 item = self.pair['second']
301             result = ('[%d]' % self.count, item)
302             self.count = self.count + 1
303             return result
304
305     def __init__ (self, typename, val):
306         self.typename = typename
307         self.val = val
308
309     def to_string (self):
310         return '%s with %d elements' % (self.typename,
311                                         len (RbtreeIterator (self.val)))
312
313     def children (self):
314         keytype = self.val.type.template_argument(0).const()
315         valuetype = self.val.type.template_argument(1)
316         nodetype = gdb.lookup_type('std::_Rb_tree_node< std::pair< %s, %s > >' % (keytype, valuetype))
317         nodetype = nodetype.pointer()
318         return self._iter (RbtreeIterator (self.val), nodetype)
319
320     def display_hint (self):
321         return 'map'
322
323 class StdSetPrinter:
324     "Print a std::set or std::multiset"
325
326     # Turn an RbtreeIterator into a pretty-print iterator.
327     class _iter:
328         def __init__(self, rbiter, type):
329             self.rbiter = rbiter
330             self.count = 0
331             self.type = type
332
333         def __iter__(self):
334             return self
335
336         def next(self):
337             item = self.rbiter.next()
338             item = item.cast(self.type).dereference()['_M_value_field']
339             # FIXME: this is weird ... what to do?
340             # Maybe a 'set' display hint?
341             result = ('[%d]' % self.count, item)
342             self.count = self.count + 1
343             return result
344
345     def __init__ (self, typename, val):
346         self.typename = typename
347         self.val = val
348
349     def to_string (self):
350         return '%s with %d elements' % (self.typename,
351                                         len (RbtreeIterator (self.val)))
352
353     def children (self):
354         keytype = self.val.type.template_argument(0)
355         nodetype = gdb.lookup_type('std::_Rb_tree_node< %s >' % keytype).pointer()
356         return self._iter (RbtreeIterator (self.val), nodetype)
357
358 class StdBitsetPrinter:
359     "Print a std::bitset"
360
361     def __init__(self, typename, val):
362         self.typename = typename
363         self.val = val
364
365     def to_string (self):
366         # If template_argument handled values, we could print the
367         # size.  Or we could use a regexp on the type.
368         return '%s' % (self.typename)
369
370     def children (self):
371         words = self.val['_M_w']
372         wtype = words.type
373
374         # The _M_w member can be either an unsigned long, or an
375         # array.  This depends on the template specialization used.
376         # If it is a single long, convert to a single element list.
377         if wtype.code == gdb.TYPE_CODE_ARRAY:
378             tsize = wtype.target ().sizeof
379         else:
380             words = [words]
381             tsize = wtype.sizeof 
382
383         nwords = wtype.sizeof / tsize
384         result = []
385         byte = 0
386         while byte < nwords:
387             w = words[byte]
388             bit = 0
389             while w != 0:
390                 if (w & 1) != 0:
391                     # Another spot where we could use 'set'?
392                     result.append(('[%d]' % (byte * tsize * 8 + bit), 1))
393                 bit = bit + 1
394                 w = w >> 1
395             byte = byte + 1
396         return result
397
398 class StdDequePrinter:
399     "Print a std::deque"
400
401     class _iter:
402         def __init__(self, node, start, end, last, buffer_size):
403             self.node = node
404             self.p = start
405             self.end = end
406             self.last = last
407             self.buffer_size = buffer_size
408             self.count = 0
409
410         def __iter__(self):
411             return self
412
413         def next(self):
414             if self.p == self.last:
415                 raise StopIteration
416
417             result = ('[%d]' % self.count, self.p.dereference())
418             self.count = self.count + 1
419
420             # Advance the 'cur' pointer.
421             self.p = self.p + 1
422             if self.p == self.end:
423                 # If we got to the end of this bucket, move to the
424                 # next bucket.
425                 self.node = self.node + 1
426                 self.p = self.node[0]
427                 self.end = self.p + self.buffer_size
428
429             return result
430
431     def __init__(self, typename, val):
432         self.typename = typename
433         self.val = val
434         self.elttype = val.type.template_argument(0)
435         size = self.elttype.sizeof
436         if size < 512:
437             self.buffer_size = int (512 / size)
438         else:
439             self.buffer_size = 1
440
441     def to_string(self):
442         start = self.val['_M_impl']['_M_start']
443         end = self.val['_M_impl']['_M_finish']
444
445         delta_n = end['_M_node'] - start['_M_node'] - 1
446         delta_s = start['_M_last'] - start['_M_cur']
447         delta_e = end['_M_cur'] - end['_M_first']
448
449         size = self.buffer_size * delta_n + delta_s + delta_e
450
451         return '%s with %d elements' % (self.typename, long (size))
452
453     def children(self):
454         start = self.val['_M_impl']['_M_start']
455         end = self.val['_M_impl']['_M_finish']
456         return self._iter(start['_M_node'], start['_M_cur'], start['_M_last'],
457                           end['_M_cur'], self.buffer_size)
458
459     def display_hint (self):
460         return 'array'
461
462 class StdDequeIteratorPrinter:
463     "Print std::deque::iterator"
464
465     def __init__(self, val):
466         self.val = val
467
468     def to_string(self):
469         return self.val['_M_cur'].dereference()
470
471 class StdStringPrinter:
472     "Print a std::basic_string of some kind"
473
474     def __init__(self, encoding, val):
475         self.encoding = encoding
476         self.val = val
477
478     def to_string(self):
479         # Look up the target encoding as late as possible.
480         encoding = self.encoding
481         if encoding == 0:
482             encoding = gdb.parameter('target-charset')
483         elif encoding == 1:
484             encoding = gdb.parameter('target-wide-charset')
485
486         # Make sure &string works, too.
487         type = self.val.type
488         if type.code == gdb.TYPE_CODE_REF:
489             type = type.target ()
490
491         # Calculate the length of the string so that to_string returns
492         # the string according to length, not according to first null
493         # encountered.
494         ptr = self.val ['_M_dataplus']['_M_p']
495         realtype = type.unqualified ().strip_typedefs ()
496         reptype = gdb.lookup_type (str (realtype) + '::_Rep').pointer ()
497         header = ptr.cast(reptype) - 1
498         len = header.dereference ()['_M_length']
499         return self.val['_M_dataplus']['_M_p'].string (encoding, length = len)
500
501     def display_hint (self):
502         return 'string'
503
504 class Tr1HashtableIterator:
505     def __init__ (self, hash):
506         self.count = 0
507         self.n_buckets = hash['_M_element_count']
508         if self.n_buckets == 0:
509             self.node = False
510         else:
511             self.bucket = hash['_M_buckets']
512             self.node = self.bucket[0]
513             self.update ()
514
515     def __iter__ (self):
516         return self
517
518     def update (self):
519         # If we advanced off the end of the chain, move to the next
520         # bucket.
521         while self.node == 0:
522             self.bucket = self.bucket + 1
523             self.node = self.bucket[0]
524
525        # If we advanced off the end of the bucket array, then
526        # we're done.
527         if self.count == self.n_buckets:
528             self.node = False
529         else:
530             self.count = self.count + 1
531
532     def next (self):
533         if not self.node:
534             raise StopIteration
535         result = self.node.dereference()['_M_v']
536         self.node = self.node.dereference()['_M_next']
537         self.update ()
538         return result
539
540 class Tr1UnorderedSetPrinter:
541     "Print a tr1::unordered_set"
542
543     def __init__ (self, typename, val):
544         self.typename = typename
545         self.val = val
546
547     def to_string (self):
548         return '%s with %d elements' % (self.typename, self.val['_M_element_count'])
549
550     @staticmethod
551     def format_count (i):
552         return '[%d]' % i
553
554     def children (self):
555         counter = itertools.imap (self.format_count, itertools.count())
556         return itertools.izip (counter, Tr1HashtableIterator (self.val))
557
558 class Tr1UnorderedMapPrinter:
559     "Print a tr1::unordered_map"
560
561     def __init__ (self, typename, val):
562         self.typename = typename
563         self.val = val
564
565     def to_string (self):
566         return '%s with %d elements' % (self.typename, self.val['_M_element_count'])
567
568     @staticmethod
569     def flatten (list):
570         for elt in list:
571             for i in elt:
572                 yield i
573
574     @staticmethod
575     def format_one (elt):
576         return (elt['first'], elt['second'])
577
578     @staticmethod
579     def format_count (i):
580         return '[%d]' % i
581
582     def children (self):
583         counter = itertools.imap (self.format_count, itertools.count())
584         # Map over the hash table and flatten the result.
585         data = self.flatten (itertools.imap (self.format_one, Tr1HashtableIterator (self.val)))
586         # Zip the two iterators together.
587         return itertools.izip (counter, data)
588
589     def display_hint (self):
590         return 'map'
591
592 def register_libstdcxx_printers (obj):
593     "Register libstdc++ pretty-printers with objfile Obj."
594
595     if obj == None:
596         obj = gdb
597
598     obj.pretty_printers.append (lookup_function)
599
600 def lookup_function (val):
601     "Look-up and return a pretty-printer that can print val."
602
603     # Get the type.
604     type = val.type
605
606     # If it points to a reference, get the reference.
607     if type.code == gdb.TYPE_CODE_REF:
608         type = type.target ()
609
610     # Get the unqualified type, stripped of typedefs.
611     type = type.unqualified ().strip_typedefs ()
612
613     # Get the type name.    
614     typename = type.tag
615     if typename == None:
616         return None
617
618     # Iterate over local dictionary of types to determine
619     # if a printer is registered for that type.  Return an
620     # instantiation of the printer if found.
621     for function in pretty_printers_dict:
622         if function.search (typename):
623             return pretty_printers_dict[function] (val)
624         
625     # Cannot find a pretty printer.  Return None.
626     return None
627
628 def build_libstdcxx_dictionary ():
629     # libstdc++ objects requiring pretty-printing.
630     # In order from:
631     # http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01847.html
632     pretty_printers_dict[re.compile('^std::basic_string<char(,.*)?>$')] = lambda val: StdStringPrinter(0, val)
633     pretty_printers_dict[re.compile('^std::basic_string<wchar_t(,.*)?>$')] = lambda val: StdStringPrinter(1, val)
634     pretty_printers_dict[re.compile('^std::basic_string<char16_t(,.*)?>$')] = lambda val: StdStringPrinter('UTF-16', val)
635     pretty_printers_dict[re.compile('^std::basic_string<char32_t(,.*)?>$')] = lambda val: StdStringPrinter('UTF-32', val)
636     pretty_printers_dict[re.compile('^std::bitset<.*>$')] = lambda val: StdBitsetPrinter("std::bitset", val)
637     pretty_printers_dict[re.compile('^std::deque<.*>$')] = lambda val: StdDequePrinter("std::deque", val)
638     pretty_printers_dict[re.compile('^std::list<.*>$')] = lambda val: StdListPrinter("std::list", val)
639     pretty_printers_dict[re.compile('^std::map<.*>$')] = lambda val: StdMapPrinter("std::map", val)
640     pretty_printers_dict[re.compile('^std::multimap<.*>$')] = lambda val: StdMapPrinter("std::multimap", val)
641     pretty_printers_dict[re.compile('^std::multiset<.*>$')] = lambda val: StdSetPrinter("std::multiset", val)
642     pretty_printers_dict[re.compile('^std::priority_queue<.*>$')] = lambda val: StdStackOrQueuePrinter("std::priority_queue", val)
643     pretty_printers_dict[re.compile('^std::queue<.*>$')] = lambda val: StdStackOrQueuePrinter("std::queue", val)
644     pretty_printers_dict[re.compile('^std::set<.*>$')] = lambda val: StdSetPrinter("std::set", val)
645     pretty_printers_dict[re.compile('^std::stack<.*>$')] = lambda val: StdStackOrQueuePrinter("std::stack", val)
646     pretty_printers_dict[re.compile('^std::unique_ptr<.*>$')] = UniquePointerPrinter
647     pretty_printers_dict[re.compile('^std::vector<.*>$')] = lambda val: StdVectorPrinter("std::vector", val)
648     # vector<bool>
649
650     # Printer registrations for classes compiled with -D_GLIBCXX_DEBUG.
651     pretty_printers_dict[re.compile('^std::__debug::bitset<.*>$')] = lambda val: StdBitsetPrinter("std::__debug::bitset", val)
652     pretty_printers_dict[re.compile('^std::__debug::deque<.*>$')] = lambda val: StdDequePrinter("std::__debug::deque", val)
653     pretty_printers_dict[re.compile('^std::__debug::list<.*>$')] = lambda val: StdListPrinter("std::__debug::list", val)
654     pretty_printers_dict[re.compile('^std::__debug::map<.*>$')] = lambda val: StdMapPrinter("std::__debug::map", val)
655     pretty_printers_dict[re.compile('^std::__debug::multimap<.*>$')] = lambda val: StdMapPrinter("std::__debug::multimap", val)
656     pretty_printers_dict[re.compile('^std::__debug::multiset<.*>$')] = lambda val: StdSetPrinter("std::__debug::multiset", val)
657     pretty_printers_dict[re.compile('^std::__debug::priority_queue<.*>$')] = lambda val: StdStackOrQueuePrinter("std::__debug::priority_queue", val)
658     pretty_printers_dict[re.compile('^std::__debug::queue<.*>$')] = lambda val: StdStackOrQueuePrinter("std::__debug::queue", val)
659     pretty_printers_dict[re.compile('^std::__debug::set<.*>$')] = lambda val: StdSetPrinter("std::__debug::set", val)
660     pretty_printers_dict[re.compile('^std::__debug::stack<.*>$')] = lambda val: StdStackOrQueuePrinter("std::__debug::stack", val)
661     pretty_printers_dict[re.compile('^std::__debug::unique_ptr<.*>$')] = UniquePointerPrinter
662     pretty_printers_dict[re.compile('^std::__debug::vector<.*>$')] = lambda val: StdVectorPrinter("std::__debug::vector", val)
663
664     # These are the TR1 and C++0x printers.
665     # For array - the default GDB pretty-printer seems reasonable.
666     pretty_printers_dict[re.compile('^std::shared_ptr<.*>$')] = lambda val: StdPointerPrinter ('std::shared_ptr', val)
667     pretty_printers_dict[re.compile('^std::weak_ptr<.*>$')] = lambda val: StdPointerPrinter ('std::weak_ptr', val)
668     pretty_printers_dict[re.compile('^std::unordered_map<.*>$')] = lambda val: Tr1UnorderedMapPrinter ('std::unordered_map', val)
669     pretty_printers_dict[re.compile('^std::unordered_set<.*>$')] = lambda val: Tr1UnorderedSetPrinter ('std::unordered_set', val)
670     pretty_printers_dict[re.compile('^std::unordered_multimap<.*>$')] = lambda val: Tr1UnorderedMapPrinter ('std::unordered_multimap', val)
671     pretty_printers_dict[re.compile('^std::unordered_multiset<.*>$')] = lambda val: Tr1UnorderedSetPrinter ('std::unordered_multiset', val)
672
673     pretty_printers_dict[re.compile('^std::tr1::shared_ptr<.*>$')] = lambda val: StdPointerPrinter ('std::tr1::shared_ptr', val)
674     pretty_printers_dict[re.compile('^std::tr1::weak_ptr<.*>$')] = lambda val: StdPointerPrinter ('std::tr1::weak_ptr', val)
675     pretty_printers_dict[re.compile('^std::tr1::unordered_map<.*>$')] = lambda val: Tr1UnorderedMapPrinter ('std::tr1::unordered_map', val)
676     pretty_printers_dict[re.compile('^std::tr1::unordered_set<.*>$')] = lambda val: Tr1UnorderedSetPrinter ('std::tr1::unordered_set', val)
677     pretty_printers_dict[re.compile('^std::tr1::unordered_multimap<.*>$')] = lambda val: Tr1UnorderedMapPrinter ('std::tr1::unordered_multimap', val)
678     pretty_printers_dict[re.compile('^std::tr1::unordered_multiset<.*>$')] = lambda val: Tr1UnorderedSetPrinter ('std::tr1::unordered_multiset', val)
679
680     # These are the C++0x printer registrations for -D_GLIBCXX_DEBUG cases.
681     # The tr1 namespace printers do not seem to have any debug
682     # equivalents, so do no register them.
683     pretty_printers_dict[re.compile('^std::__debug::unordered_map<.*>$')] = lambda val: Tr1UnorderedMapPrinter ('std::__debug::unordered_map', val)
684     pretty_printers_dict[re.compile('^std::__debug::unordered_set<.*>$')] = lambda val: Tr1UnorderedSetPrinter ('std::__debug::unordered_set', val)
685     pretty_printers_dict[re.compile('^std::__debug::unordered_multimap<.*>$')] = lambda val: Tr1UnorderedMapPrinter ('std::__debug::unordered_multimap',  val)
686     pretty_printers_dict[re.compile('^std::__debug::unordered_multiset<.*>$')] = lambda val: Tr1UnorderedSetPrinter ('std::__debug:unordered_multiset', val)
687
688
689     # Extensions.
690     pretty_printers_dict[re.compile('^__gnu_cxx::slist<.*>$')] = StdSlistPrinter
691
692     if True:
693         # These shouldn't be necessary, if GDB "print *i" worked.
694         # But it often doesn't, so here they are.
695         pretty_printers_dict[re.compile('^std::_List_iterator<.*>$')] = lambda val: StdListIteratorPrinter("std::_List_iterator",val)
696         pretty_printers_dict[re.compile('^std::_List_const_iterator<.*>$')] = lambda val: StdListIteratorPrinter("std::_List_const_iterator",val)
697         pretty_printers_dict[re.compile('^std::_Rb_tree_iterator<.*>$')] = lambda val: StdRbtreeIteratorPrinter(val)
698         pretty_printers_dict[re.compile('^std::_Rb_tree_const_iterator<.*>$')] = lambda val: StdRbtreeIteratorPrinter(val)
699         pretty_printers_dict[re.compile('^std::_Deque_iterator<.*>$')] = lambda val: StdDequeIteratorPrinter(val)
700         pretty_printers_dict[re.compile('^std::_Deque_const_iterator<.*>$')] = lambda val: StdDequeIteratorPrinter(val)
701         pretty_printers_dict[re.compile('^__gnu_cxx::__normal_iterator<.*>$')] = lambda val: StdVectorIteratorPrinter(val)
702         pretty_printers_dict[re.compile('^__gnu_cxx::_Slist_iterator<.*>$')] = lambda val: StdSlistIteratorPrinter(val)
703
704         # Debug (compiled with -D_GLIBCXX_DEBUG) printer registrations.
705         # The Rb_tree debug iterator when unwrapped from the encapsulating __gnu_debug::_Safe_iterator
706         # does not have the __norm namespace. Just use the existing printer registration for that.
707         pretty_printers_dict[re.compile('^__gnu_debug::_Safe_iterator<.*>$')] = lambda val: StdDebugIteratorPrinter(val)
708         pretty_printers_dict[re.compile('^std::__norm::_List_iterator<.*>$')] = lambda val: StdListIteratorPrinter ("std::__norm::_List_iterator",val)
709         pretty_printers_dict[re.compile('^std::__norm::_List_const_iterator<.*>$')] = lambda val: StdListIteratorPrinter ("std::__norm::_List_const_iterator",val)
710         pretty_printers_dict[re.compile('^std::__norm::_Deque_const_iterator<.*>$')] = lambda val: StdDequeIteratorPrinter(val)
711         pretty_printers_dict[re.compile('^std::__norm::_Deque_iterator<.*>$')] = lambda val: StdDequeIteratorPrinter(val)
712
713 pretty_printers_dict = {}
714
715 build_libstdcxx_dictionary ()