2018-03-28 14:55:54 +11:00
|
|
|
import re
|
|
|
|
import gdb
|
|
|
|
|
|
|
|
class CoordPrinter(object):
|
|
|
|
def __init__(self, title, val):
|
|
|
|
self.title = title
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
def display_hint(self):
|
|
|
|
return 'array'
|
|
|
|
|
|
|
|
class _iterator(object):
|
|
|
|
def __init__(self, data):
|
|
|
|
self.data = data
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
indices = self.data.type.range()
|
|
|
|
for i in range(indices[0], indices[1] + 1):
|
|
|
|
res = (str(i), self.data[i])
|
|
|
|
yield res
|
|
|
|
raise StopIteration()
|
|
|
|
|
|
|
|
|
|
|
|
def children(self):
|
|
|
|
return self._iterator(self.val['data'])
|
|
|
|
|
|
|
|
|
2018-08-03 16:49:47 +10:00
|
|
|
class ViewPrinter(object):
|
|
|
|
def __init__(self, title, val):
|
|
|
|
self.title = title
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
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()
|
|
|
|
self.cursor = self.cursor + 1
|
|
|
|
self.index = self.index + 1
|
|
|
|
|
|
|
|
return ("[%d]" % self.index, val)
|
|
|
|
|
|
|
|
def children(self):
|
|
|
|
return self._iterator(
|
|
|
|
self.val["m_begin"],
|
|
|
|
self.val["m_end"]
|
|
|
|
)
|
2018-03-28 14:55:54 +11:00
|
|
|
|
|
|
|
def build_cruft_dict():
|
2018-08-05 14:42:02 +10:00
|
|
|
pretty_printers_dict[re.compile('^cruft::point.*$') ] = lambda title, val: CoordPrinter(title, val)
|
|
|
|
pretty_printers_dict[re.compile('^cruft::vector.*$')] = lambda title, val: CoordPrinter(title, val)
|
|
|
|
pretty_printers_dict[re.compile('^cruft::extent.*$')] = lambda title, val: CoordPrinter(title, val)
|
|
|
|
pretty_printers_dict[re.compile('^cruft::colour.*$')] = lambda title, val: CoordPrinter(title, val)
|
2018-03-28 14:55:54 +11:00
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
pretty_printers_dict[re.compile('^cruft::view')] = lambda title, val: ViewPrinter(title, val)
|
2018-08-03 16:49:47 +10:00
|
|
|
|
2018-03-28 14:55:54 +11:00
|
|
|
|
|
|
|
def lookup(val):
|
|
|
|
type = val.type
|
|
|
|
|
|
|
|
if type.code == gdb.TYPE_CODE_REF:
|
|
|
|
type = type.target()
|
|
|
|
|
|
|
|
type = type.unqualified().strip_typedefs()
|
|
|
|
|
|
|
|
typename = type.tag
|
|
|
|
if typename == None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
for function in pretty_printers_dict:
|
|
|
|
if function.search(typename):
|
|
|
|
return pretty_printers_dict[function](typename, val)
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def register_cruft_printers():
|
|
|
|
gdb.pretty_printers.append(lookup)
|
|
|
|
|
|
|
|
|
|
|
|
pretty_printers_dict = {}
|
|
|
|
build_cruft_dict ()
|
|
|
|
|