debug/gdb/printers: prefer yield over custom iterators
This commit is contained in:
parent
24e3d749e7
commit
d455e820d8
@ -25,7 +25,6 @@ class CoordPrinter(object):
|
||||
yield res
|
||||
raise StopIteration()
|
||||
|
||||
|
||||
def children(self):
|
||||
return self._iterator(self.val['data'])
|
||||
|
||||
@ -35,37 +34,28 @@ class ViewPrinter(object):
|
||||
self.val = val
|
||||
|
||||
def to_string(self):
|
||||
return self.val
|
||||
end = int(self.val["m_end"])
|
||||
begin = int(self.val["m_begin"])
|
||||
size = end - begin
|
||||
return f"{size} elements"
|
||||
|
||||
def display_hint(self):
|
||||
return 'array'
|
||||
|
||||
class _iterator(object):
|
||||
def __init__(self, first, last):
|
||||
self.cursor = first
|
||||
self.last = last
|
||||
self.index = 0
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
if self.cursor == self.last:
|
||||
raise StopIteration
|
||||
|
||||
val = self.cursor.dereference()
|
||||
res = ("[%d]" % self.index, val)
|
||||
|
||||
self.cursor = self.cursor + 1
|
||||
self.index = self.index + 1
|
||||
|
||||
return res
|
||||
|
||||
def children(self):
|
||||
return self._iterator(
|
||||
self.val["m_begin"],
|
||||
self.val["m_end"]
|
||||
)
|
||||
cursor = self.val["m_begin"]
|
||||
last = self.val["m_end"]
|
||||
index = 0
|
||||
|
||||
while cursor != last:
|
||||
val = cursor.dereference()
|
||||
res = ("[%d]" % index, val)
|
||||
|
||||
cursor = cursor + 1
|
||||
index = index + 1
|
||||
|
||||
val = cursor.dereference()
|
||||
yield res
|
||||
|
||||
class EndianValuePrinter(object):
|
||||
val: gdb.Type
|
||||
|
Loading…
Reference in New Issue
Block a user