llvm.org GIT mirror llvm / 94363b3
[gdb] Fix SmallVector pretty printer after r337514 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337747 91177308-0d34-0410-b5e6-96231b3b80d8 Fangrui Song 2 years ago
1 changed file(s) with 18 addition(s) and 38 deletion(s). Raw diff Collapse all Expand all
2121
2222 def to_string(self):
2323 begin = self.val['BeginX']
24 end = self.val['EndX']
25 return escape_bytes(begin.cast(gdb.lookup_type('char').pointer()), end - begin)
24 return escape_bytes(begin.cast(gdb.lookup_type('char').pointer()), self.val['Size'])
2625
2726 class StringRefPrinter:
2827 """Print an llvm::StringRef object."""
3332 def to_string(self):
3433 return escape_bytes(self.val['Data'], self.val['Length'])
3534
36 class SmallVectorPrinter:
35 class SmallVectorPrinter(Iterator):
3736 """Print an llvm::SmallVector object."""
3837
39 class _iterator:
40 def __init__(self, begin, end):
41 self.cur = begin
42 self.end = end
43 self.count = 0
44
45 def __iter__(self):
46 return self
47
48 def next(self):
49 if self.cur == self.end:
50 raise StopIteration
51 count = self.count
52 self.count = self.count + 1
53 cur = self.cur
54 self.cur = self.cur + 1
55 return '[%d]' % count, cur.dereference()
56
57 __next__ = next
58
59 def __init__(self, val):
60 self.val = val
61
62 def children(self):
63 t = self.val.type.template_argument(0).pointer()
64 begin = self.val['BeginX'].cast(t)
65 end = self.val['EndX'].cast(t)
66 return self._iterator(begin, end)
67
68 def to_string(self):
69 t = self.val.type.template_argument(0).pointer()
70 begin = self.val['BeginX'].cast(t)
71 end = self.val['EndX'].cast(t)
72 capacity = self.val['CapacityX'].cast(t)
73 return 'llvm::SmallVector of length %d, capacity %d' % (end - begin, capacity - begin)
38 def __init__(self, val):
39 self.val = val
40 t = val.type.template_argument(0).pointer()
41 self.begin = val['BeginX'].cast(t)
42 self.size = val['Size']
43 self.i = 0
44
45 def __next__(self):
46 if self.i == self.size:
47 raise StopIteration
48 ret = '[{}]'.format(self.i), (self.begin+self.i).dereference()
49 self.i += 1
50 return ret
51
52 def to_string(self):
53 return 'llvm::SmallVector of Size {}, Capacity {}'.format(self.size, self.val['Capacity'])
7454
7555 def display_hint (self):
7656 return 'array'