OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [libstdc++-v3/] [python/] [libstdcxx/] [v6/] [printers.py] - Blame information for rev 424

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
# Pretty-printers for libstc++.
2
 
3
# Copyright (C) 2008, 2009, 2010 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 ValueError, "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 ValueError, "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 StdTuplePrinter:
201
    "Print a std::tuple"
202
 
203
    class _iterator:
204
        def __init__ (self, head):
205
            self.head = head
206
 
207
            # Set the base class as the initial head of the
208
            # tuple.
209
            nodes = self.head.type.fields ()
210
            if len (nodes) != 1:
211
                raise ValueError, "Top of tuple tree does not consist of a single node."
212
 
213
            # Set the actual head to the first pair.
214
            self.head  = self.head.cast (nodes[0].type)
215
            self.count = 0
216
 
217
        def __iter__ (self):
218
            return self
219
 
220
        def next (self):
221
            nodes = self.head.type.fields ()
222
            # Check for further recursions in the inheritance tree.
223
            if len (nodes) == 0:
224
                raise StopIteration
225
            # Check that this iteration has an expected structure.
226
            if len (nodes) != 2:
227
                raise ValueError, "Cannot parse more than 2 nodes in a tuple tree."
228
 
229
            # - Left node is the next recursion parent.
230
            # - Right node is the actual class contained in the tuple.
231
 
232
            # Process right node.
233
            impl = self.head.cast (nodes[1].type)
234
 
235
            # Process left node and set it as head.
236
            self.head  = self.head.cast (nodes[0].type)
237
            self.count = self.count + 1
238
 
239
            # Finally, check the implementation.  If it is
240
            # wrapped in _M_head_impl return that, otherwise return
241
            # the value "as is".
242
            fields = impl.type.fields ()
243
            if len (fields) < 1 or fields[0].name != "_M_head_impl":
244
                return ('[%d]' % self.count, impl)
245
            else:
246
                return ('[%d]' % self.count, impl['_M_head_impl'])
247
 
248
    def __init__ (self, typename, val):
249
        self.typename = typename
250
        self.val = val;
251
 
252
    def children (self):
253
        return self._iterator (self.val)
254
 
255
    def to_string (self):
256
        return '%s containing' % (self.typename)
257
 
258
class StdStackOrQueuePrinter:
259
    "Print a std::stack or std::queue"
260
 
261
    def __init__ (self, typename, val):
262
        self.typename = typename
263
        self.visualizer = gdb.default_visualizer(val['c'])
264
 
265
    def children (self):
266
        return self.visualizer.children()
267
 
268
    def to_string (self):
269
        return '%s wrapping: %s' % (self.typename,
270
                                    self.visualizer.to_string())
271
 
272
    def display_hint (self):
273
        if hasattr (self.visualizer, 'display_hint'):
274
            return self.visualizer.display_hint ()
275
        return None
276
 
277
class RbtreeIterator:
278
    def __init__(self, rbtree):
279
        self.size = rbtree['_M_t']['_M_impl']['_M_node_count']
280
        self.node = rbtree['_M_t']['_M_impl']['_M_header']['_M_left']
281
        self.count = 0
282
 
283
    def __iter__(self):
284
        return self
285
 
286
    def __len__(self):
287
        return int (self.size)
288
 
289
    def next(self):
290
        if self.count == self.size:
291
            raise StopIteration
292
        result = self.node
293
        self.count = self.count + 1
294
        if self.count < self.size:
295
            # Compute the next node.
296
            node = self.node
297
            if node.dereference()['_M_right']:
298
                node = node.dereference()['_M_right']
299
                while node.dereference()['_M_left']:
300
                    node = node.dereference()['_M_left']
301
            else:
302
                parent = node.dereference()['_M_parent']
303
                while node == parent.dereference()['_M_right']:
304
                    node = parent
305
                    parent = parent.dereference()['_M_parent']
306
                if node.dereference()['_M_right'] != parent:
307
                    node = parent
308
            self.node = node
309
        return result
310
 
311
# This is a pretty printer for std::_Rb_tree_iterator (which is
312
# std::map::iterator), and has nothing to do with the RbtreeIterator
313
# class above.
314
class StdRbtreeIteratorPrinter:
315
    "Print std::map::iterator"
316
 
317
    def __init__ (self, val):
318
        self.val = val
319
 
320
    def to_string (self):
321
        valuetype = self.val.type.template_argument(0)
322
        nodetype = gdb.lookup_type('std::_Rb_tree_node < %s >' % valuetype)
323
        nodetype = nodetype.pointer()
324
        return self.val.cast(nodetype).dereference()['_M_value_field']
325
 
326
class StdDebugIteratorPrinter:
327
    "Print a debug enabled version of an iterator"
328
 
329
    def __init__ (self, val):
330
        self.val = val
331
 
332
    # Just strip away the encapsulating __gnu_debug::_Safe_iterator
333
    # and return the wrapped iterator value.
334
    def to_string (self):
335
        itype = self.val.type.template_argument(0)
336
        return self.val['_M_current'].cast(itype)
337
 
338
class StdMapPrinter:
339
    "Print a std::map or std::multimap"
340
 
341
    # Turn an RbtreeIterator into a pretty-print iterator.
342
    class _iter:
343
        def __init__(self, rbiter, type):
344
            self.rbiter = rbiter
345
            self.count = 0
346
            self.type = type
347
 
348
        def __iter__(self):
349
            return self
350
 
351
        def next(self):
352
            if self.count % 2 == 0:
353
                n = self.rbiter.next()
354
                n = n.cast(self.type).dereference()['_M_value_field']
355
                self.pair = n
356
                item = n['first']
357
            else:
358
                item = self.pair['second']
359
            result = ('[%d]' % self.count, item)
360
            self.count = self.count + 1
361
            return result
362
 
363
    def __init__ (self, typename, val):
364
        self.typename = typename
365
        self.val = val
366
 
367
    def to_string (self):
368
        return '%s with %d elements' % (self.typename,
369
                                        len (RbtreeIterator (self.val)))
370
 
371
    def children (self):
372
        keytype = self.val.type.template_argument(0).const()
373
        valuetype = self.val.type.template_argument(1)
374
        nodetype = gdb.lookup_type('std::_Rb_tree_node< std::pair< %s, %s > >' % (keytype, valuetype))
375
        nodetype = nodetype.pointer()
376
        return self._iter (RbtreeIterator (self.val), nodetype)
377
 
378
    def display_hint (self):
379
        return 'map'
380
 
381
class StdSetPrinter:
382
    "Print a std::set or std::multiset"
383
 
384
    # Turn an RbtreeIterator into a pretty-print iterator.
385
    class _iter:
386
        def __init__(self, rbiter, type):
387
            self.rbiter = rbiter
388
            self.count = 0
389
            self.type = type
390
 
391
        def __iter__(self):
392
            return self
393
 
394
        def next(self):
395
            item = self.rbiter.next()
396
            item = item.cast(self.type).dereference()['_M_value_field']
397
            # FIXME: this is weird ... what to do?
398
            # Maybe a 'set' display hint?
399
            result = ('[%d]' % self.count, item)
400
            self.count = self.count + 1
401
            return result
402
 
403
    def __init__ (self, typename, val):
404
        self.typename = typename
405
        self.val = val
406
 
407
    def to_string (self):
408
        return '%s with %d elements' % (self.typename,
409
                                        len (RbtreeIterator (self.val)))
410
 
411
    def children (self):
412
        keytype = self.val.type.template_argument(0)
413
        nodetype = gdb.lookup_type('std::_Rb_tree_node< %s >' % keytype).pointer()
414
        return self._iter (RbtreeIterator (self.val), nodetype)
415
 
416
class StdBitsetPrinter:
417
    "Print a std::bitset"
418
 
419
    def __init__(self, typename, val):
420
        self.typename = typename
421
        self.val = val
422
 
423
    def to_string (self):
424
        # If template_argument handled values, we could print the
425
        # size.  Or we could use a regexp on the type.
426
        return '%s' % (self.typename)
427
 
428
    def children (self):
429
        words = self.val['_M_w']
430
        wtype = words.type
431
 
432
        # The _M_w member can be either an unsigned long, or an
433
        # array.  This depends on the template specialization used.
434
        # If it is a single long, convert to a single element list.
435
        if wtype.code == gdb.TYPE_CODE_ARRAY:
436
            tsize = wtype.target ().sizeof
437
        else:
438
            words = [words]
439
            tsize = wtype.sizeof
440
 
441
        nwords = wtype.sizeof / tsize
442
        result = []
443
        byte = 0
444
        while byte < nwords:
445
            w = words[byte]
446
            bit = 0
447
            while w != 0:
448
                if (w & 1) != 0:
449
                    # Another spot where we could use 'set'?
450
                    result.append(('[%d]' % (byte * tsize * 8 + bit), 1))
451
                bit = bit + 1
452
                w = w >> 1
453
            byte = byte + 1
454
        return result
455
 
456
class StdDequePrinter:
457
    "Print a std::deque"
458
 
459
    class _iter:
460
        def __init__(self, node, start, end, last, buffer_size):
461
            self.node = node
462
            self.p = start
463
            self.end = end
464
            self.last = last
465
            self.buffer_size = buffer_size
466
            self.count = 0
467
 
468
        def __iter__(self):
469
            return self
470
 
471
        def next(self):
472
            if self.p == self.last:
473
                raise StopIteration
474
 
475
            result = ('[%d]' % self.count, self.p.dereference())
476
            self.count = self.count + 1
477
 
478
            # Advance the 'cur' pointer.
479
            self.p = self.p + 1
480
            if self.p == self.end:
481
                # If we got to the end of this bucket, move to the
482
                # next bucket.
483
                self.node = self.node + 1
484
                self.p = self.node[0]
485
                self.end = self.p + self.buffer_size
486
 
487
            return result
488
 
489
    def __init__(self, typename, val):
490
        self.typename = typename
491
        self.val = val
492
        self.elttype = val.type.template_argument(0)
493
        size = self.elttype.sizeof
494
        if size < 512:
495
            self.buffer_size = int (512 / size)
496
        else:
497
            self.buffer_size = 1
498
 
499
    def to_string(self):
500
        start = self.val['_M_impl']['_M_start']
501
        end = self.val['_M_impl']['_M_finish']
502
 
503
        delta_n = end['_M_node'] - start['_M_node'] - 1
504
        delta_s = start['_M_last'] - start['_M_cur']
505
        delta_e = end['_M_cur'] - end['_M_first']
506
 
507
        size = self.buffer_size * delta_n + delta_s + delta_e
508
 
509
        return '%s with %d elements' % (self.typename, long (size))
510
 
511
    def children(self):
512
        start = self.val['_M_impl']['_M_start']
513
        end = self.val['_M_impl']['_M_finish']
514
        return self._iter(start['_M_node'], start['_M_cur'], start['_M_last'],
515
                          end['_M_cur'], self.buffer_size)
516
 
517
    def display_hint (self):
518
        return 'array'
519
 
520
class StdDequeIteratorPrinter:
521
    "Print std::deque::iterator"
522
 
523
    def __init__(self, val):
524
        self.val = val
525
 
526
    def to_string(self):
527
        return self.val['_M_cur'].dereference()
528
 
529
class StdStringPrinter:
530
    "Print a std::basic_string of some kind"
531
 
532
    def __init__(self, val):
533
        self.val = val
534
 
535
    def to_string(self):
536
        # Make sure &string works, too.
537
        type = self.val.type
538
        if type.code == gdb.TYPE_CODE_REF:
539
            type = type.target ()
540
 
541
        # Calculate the length of the string so that to_string returns
542
        # the string according to length, not according to first null
543
        # encountered.
544
        ptr = self.val ['_M_dataplus']['_M_p']
545
        realtype = type.unqualified ().strip_typedefs ()
546
        reptype = gdb.lookup_type (str (realtype) + '::_Rep').pointer ()
547
        header = ptr.cast(reptype) - 1
548
        len = header.dereference ()['_M_length']
549
        return self.val['_M_dataplus']['_M_p'].lazy_string (length = len)
550
 
551
    def display_hint (self):
552
        return 'string'
553
 
554
class Tr1HashtableIterator:
555
    def __init__ (self, hash):
556
        self.count = 0
557
        self.n_buckets = hash['_M_element_count']
558
        if self.n_buckets == 0:
559
            self.node = False
560
        else:
561
            self.bucket = hash['_M_buckets']
562
            self.node = self.bucket[0]
563
            self.update ()
564
 
565
    def __iter__ (self):
566
        return self
567
 
568
    def update (self):
569
        # If we advanced off the end of the chain, move to the next
570
        # bucket.
571
        while self.node == 0:
572
            self.bucket = self.bucket + 1
573
            self.node = self.bucket[0]
574
 
575
       # If we advanced off the end of the bucket array, then
576
       # we're done.
577
        if self.count == self.n_buckets:
578
            self.node = False
579
        else:
580
            self.count = self.count + 1
581
 
582
    def next (self):
583
        if not self.node:
584
            raise StopIteration
585
        result = self.node.dereference()['_M_v']
586
        self.node = self.node.dereference()['_M_next']
587
        self.update ()
588
        return result
589
 
590
class Tr1UnorderedSetPrinter:
591
    "Print a tr1::unordered_set"
592
 
593
    def __init__ (self, typename, val):
594
        self.typename = typename
595
        self.val = val
596
 
597
    def to_string (self):
598
        return '%s with %d elements' % (self.typename, self.val['_M_element_count'])
599
 
600
    @staticmethod
601
    def format_count (i):
602
        return '[%d]' % i
603
 
604
    def children (self):
605
        counter = itertools.imap (self.format_count, itertools.count())
606
        return itertools.izip (counter, Tr1HashtableIterator (self.val))
607
 
608
class Tr1UnorderedMapPrinter:
609
    "Print a tr1::unordered_map"
610
 
611
    def __init__ (self, typename, val):
612
        self.typename = typename
613
        self.val = val
614
 
615
    def to_string (self):
616
        return '%s with %d elements' % (self.typename, self.val['_M_element_count'])
617
 
618
    @staticmethod
619
    def flatten (list):
620
        for elt in list:
621
            for i in elt:
622
                yield i
623
 
624
    @staticmethod
625
    def format_one (elt):
626
        return (elt['first'], elt['second'])
627
 
628
    @staticmethod
629
    def format_count (i):
630
        return '[%d]' % i
631
 
632
    def children (self):
633
        counter = itertools.imap (self.format_count, itertools.count())
634
        # Map over the hash table and flatten the result.
635
        data = self.flatten (itertools.imap (self.format_one, Tr1HashtableIterator (self.val)))
636
        # Zip the two iterators together.
637
        return itertools.izip (counter, data)
638
 
639
    def display_hint (self):
640
        return 'map'
641
 
642
def register_libstdcxx_printers (obj):
643
    "Register libstdc++ pretty-printers with objfile Obj."
644
 
645
    if obj == None:
646
        obj = gdb
647
 
648
    obj.pretty_printers.append (lookup_function)
649
 
650
def lookup_function (val):
651
    "Look-up and return a pretty-printer that can print val."
652
 
653
    # Get the type.
654
    type = val.type
655
 
656
    # If it points to a reference, get the reference.
657
    if type.code == gdb.TYPE_CODE_REF:
658
        type = type.target ()
659
 
660
    # Get the unqualified type, stripped of typedefs.
661
    type = type.unqualified ().strip_typedefs ()
662
 
663
    # Get the type name.    
664
    typename = type.tag
665
    if typename == None:
666
        return None
667
 
668
    # Iterate over local dictionary of types to determine
669
    # if a printer is registered for that type.  Return an
670
    # instantiation of the printer if found.
671
    for function in pretty_printers_dict:
672
        if function.search (typename):
673
            return pretty_printers_dict[function] (val)
674
 
675
    # Cannot find a pretty printer.  Return None.
676
    return None
677
 
678
def build_libstdcxx_dictionary ():
679
    # libstdc++ objects requiring pretty-printing.
680
    # In order from:
681
    # http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01847.html
682
    pretty_printers_dict[re.compile('^std::basic_string<.*>$')] = lambda val: StdStringPrinter(val)
683
    pretty_printers_dict[re.compile('^std::bitset<.*>$')] = lambda val: StdBitsetPrinter("std::bitset", val)
684
    pretty_printers_dict[re.compile('^std::deque<.*>$')] = lambda val: StdDequePrinter("std::deque", val)
685
    pretty_printers_dict[re.compile('^std::list<.*>$')] = lambda val: StdListPrinter("std::list", val)
686
    pretty_printers_dict[re.compile('^std::map<.*>$')] = lambda val: StdMapPrinter("std::map", val)
687
    pretty_printers_dict[re.compile('^std::multimap<.*>$')] = lambda val: StdMapPrinter("std::multimap", val)
688
    pretty_printers_dict[re.compile('^std::multiset<.*>$')] = lambda val: StdSetPrinter("std::multiset", val)
689
    pretty_printers_dict[re.compile('^std::priority_queue<.*>$')] = lambda val: StdStackOrQueuePrinter("std::priority_queue", val)
690
    pretty_printers_dict[re.compile('^std::queue<.*>$')] = lambda val: StdStackOrQueuePrinter("std::queue", val)
691
    pretty_printers_dict[re.compile('^std::tuple<.*>$')] = lambda val: StdTuplePrinter("std::tuple", val)
692
    pretty_printers_dict[re.compile('^std::set<.*>$')] = lambda val: StdSetPrinter("std::set", val)
693
    pretty_printers_dict[re.compile('^std::stack<.*>$')] = lambda val: StdStackOrQueuePrinter("std::stack", val)
694
    pretty_printers_dict[re.compile('^std::unique_ptr<.*>$')] = UniquePointerPrinter
695
    pretty_printers_dict[re.compile('^std::vector<.*>$')] = lambda val: StdVectorPrinter("std::vector", val)
696
    # vector<bool>
697
 
698
    # Printer registrations for classes compiled with -D_GLIBCXX_DEBUG.
699
    pretty_printers_dict[re.compile('^std::__debug::bitset<.*>$')] = lambda val: StdBitsetPrinter("std::__debug::bitset", val)
700
    pretty_printers_dict[re.compile('^std::__debug::deque<.*>$')] = lambda val: StdDequePrinter("std::__debug::deque", val)
701
    pretty_printers_dict[re.compile('^std::__debug::list<.*>$')] = lambda val: StdListPrinter("std::__debug::list", val)
702
    pretty_printers_dict[re.compile('^std::__debug::map<.*>$')] = lambda val: StdMapPrinter("std::__debug::map", val)
703
    pretty_printers_dict[re.compile('^std::__debug::multimap<.*>$')] = lambda val: StdMapPrinter("std::__debug::multimap", val)
704
    pretty_printers_dict[re.compile('^std::__debug::multiset<.*>$')] = lambda val: StdSetPrinter("std::__debug::multiset", val)
705
    pretty_printers_dict[re.compile('^std::__debug::priority_queue<.*>$')] = lambda val: StdStackOrQueuePrinter("std::__debug::priority_queue", val)
706
    pretty_printers_dict[re.compile('^std::__debug::queue<.*>$')] = lambda val: StdStackOrQueuePrinter("std::__debug::queue", val)
707
    pretty_printers_dict[re.compile('^std::__debug::set<.*>$')] = lambda val: StdSetPrinter("std::__debug::set", val)
708
    pretty_printers_dict[re.compile('^std::__debug::stack<.*>$')] = lambda val: StdStackOrQueuePrinter("std::__debug::stack", val)
709
    pretty_printers_dict[re.compile('^std::__debug::unique_ptr<.*>$')] = UniquePointerPrinter
710
    pretty_printers_dict[re.compile('^std::__debug::vector<.*>$')] = lambda val: StdVectorPrinter("std::__debug::vector", val)
711
 
712
    # These are the TR1 and C++0x printers.
713
    # For array - the default GDB pretty-printer seems reasonable.
714
    pretty_printers_dict[re.compile('^std::shared_ptr<.*>$')] = lambda val: StdPointerPrinter ('std::shared_ptr', val)
715
    pretty_printers_dict[re.compile('^std::weak_ptr<.*>$')] = lambda val: StdPointerPrinter ('std::weak_ptr', val)
716
    pretty_printers_dict[re.compile('^std::unordered_map<.*>$')] = lambda val: Tr1UnorderedMapPrinter ('std::unordered_map', val)
717
    pretty_printers_dict[re.compile('^std::unordered_set<.*>$')] = lambda val: Tr1UnorderedSetPrinter ('std::unordered_set', val)
718
    pretty_printers_dict[re.compile('^std::unordered_multimap<.*>$')] = lambda val: Tr1UnorderedMapPrinter ('std::unordered_multimap', val)
719
    pretty_printers_dict[re.compile('^std::unordered_multiset<.*>$')] = lambda val: Tr1UnorderedSetPrinter ('std::unordered_multiset', val)
720
 
721
    pretty_printers_dict[re.compile('^std::tr1::shared_ptr<.*>$')] = lambda val: StdPointerPrinter ('std::tr1::shared_ptr', val)
722
    pretty_printers_dict[re.compile('^std::tr1::weak_ptr<.*>$')] = lambda val: StdPointerPrinter ('std::tr1::weak_ptr', val)
723
    pretty_printers_dict[re.compile('^std::tr1::unordered_map<.*>$')] = lambda val: Tr1UnorderedMapPrinter ('std::tr1::unordered_map', val)
724
    pretty_printers_dict[re.compile('^std::tr1::unordered_set<.*>$')] = lambda val: Tr1UnorderedSetPrinter ('std::tr1::unordered_set', val)
725
    pretty_printers_dict[re.compile('^std::tr1::unordered_multimap<.*>$')] = lambda val: Tr1UnorderedMapPrinter ('std::tr1::unordered_multimap', val)
726
    pretty_printers_dict[re.compile('^std::tr1::unordered_multiset<.*>$')] = lambda val: Tr1UnorderedSetPrinter ('std::tr1::unordered_multiset', val)
727
 
728
    # These are the C++0x printer registrations for -D_GLIBCXX_DEBUG cases.
729
    # The tr1 namespace printers do not seem to have any debug
730
    # equivalents, so do no register them.
731
    pretty_printers_dict[re.compile('^std::__debug::unordered_map<.*>$')] = lambda val: Tr1UnorderedMapPrinter ('std::__debug::unordered_map', val)
732
    pretty_printers_dict[re.compile('^std::__debug::unordered_set<.*>$')] = lambda val: Tr1UnorderedSetPrinter ('std::__debug::unordered_set', val)
733
    pretty_printers_dict[re.compile('^std::__debug::unordered_multimap<.*>$')] = lambda val: Tr1UnorderedMapPrinter ('std::__debug::unordered_multimap',  val)
734
    pretty_printers_dict[re.compile('^std::__debug::unordered_multiset<.*>$')] = lambda val: Tr1UnorderedSetPrinter ('std::__debug:unordered_multiset', val)
735
 
736
 
737
    # Extensions.
738
    pretty_printers_dict[re.compile('^__gnu_cxx::slist<.*>$')] = StdSlistPrinter
739
 
740
    if True:
741
        # These shouldn't be necessary, if GDB "print *i" worked.
742
        # But it often doesn't, so here they are.
743
        pretty_printers_dict[re.compile('^std::_List_iterator<.*>$')] = lambda val: StdListIteratorPrinter("std::_List_iterator",val)
744
        pretty_printers_dict[re.compile('^std::_List_const_iterator<.*>$')] = lambda val: StdListIteratorPrinter("std::_List_const_iterator",val)
745
        pretty_printers_dict[re.compile('^std::_Rb_tree_iterator<.*>$')] = lambda val: StdRbtreeIteratorPrinter(val)
746
        pretty_printers_dict[re.compile('^std::_Rb_tree_const_iterator<.*>$')] = lambda val: StdRbtreeIteratorPrinter(val)
747
        pretty_printers_dict[re.compile('^std::_Deque_iterator<.*>$')] = lambda val: StdDequeIteratorPrinter(val)
748
        pretty_printers_dict[re.compile('^std::_Deque_const_iterator<.*>$')] = lambda val: StdDequeIteratorPrinter(val)
749
        pretty_printers_dict[re.compile('^__gnu_cxx::__normal_iterator<.*>$')] = lambda val: StdVectorIteratorPrinter(val)
750
        pretty_printers_dict[re.compile('^__gnu_cxx::_Slist_iterator<.*>$')] = lambda val: StdSlistIteratorPrinter(val)
751
 
752
        # Debug (compiled with -D_GLIBCXX_DEBUG) printer registrations.
753
        # The Rb_tree debug iterator when unwrapped from the encapsulating __gnu_debug::_Safe_iterator
754
        # does not have the __norm namespace. Just use the existing printer registration for that.
755
        pretty_printers_dict[re.compile('^__gnu_debug::_Safe_iterator<.*>$')] = lambda val: StdDebugIteratorPrinter(val)
756
        pretty_printers_dict[re.compile('^std::__norm::_List_iterator<.*>$')] = lambda val: StdListIteratorPrinter ("std::__norm::_List_iterator",val)
757
        pretty_printers_dict[re.compile('^std::__norm::_List_const_iterator<.*>$')] = lambda val: StdListIteratorPrinter ("std::__norm::_List_const_iterator",val)
758
        pretty_printers_dict[re.compile('^std::__norm::_Deque_const_iterator<.*>$')] = lambda val: StdDequeIteratorPrinter(val)
759
        pretty_printers_dict[re.compile('^std::__norm::_Deque_iterator<.*>$')] = lambda val: StdDequeIteratorPrinter(val)
760
 
761
pretty_printers_dict = {}
762
 
763
build_libstdcxx_dictionary ()

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.