blob: f11e064cfbf332d83b5faa2c487866203257cc8b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
import gdb
class KstdVectorPrinter(gdb.ValuePrinter):
class Iterator:
def __init__(self, begin: gdb.Value, end: gdb.Value):
self._item = begin
self._end = end
self._count = 0
def __iter__(self):
return self
def __next__(self):
count = self._count
self._count = count + 1
if self._item == self._end:
raise StopIteration
element = self._item.dereference()
self._item = self._item + 1
return (f"[{count}]", element)
def __init__(self, val: gdb.Value):
self.__val = val
self.__size = int(val["m_size"])
self.__capacity = int(val["m_capacity"])
self.__data = val["m_data"]
def to_string(self):
return f"vector of length {self.__size}, capacity {self.__capacity}"
def children(self):
return self.Iterator(self.__data, self.__data + self.__size)
def display_hint(self):
return "array"
def num_children(self):
return self.__size
|