debug: add gdb pretty printers for coord types
This commit is contained in:
parent
4f10505d09
commit
48e007c545
64
debug/gdb/printers.py
Normal file
64
debug/gdb/printers.py
Normal file
@ -0,0 +1,64 @@
|
||||
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'])
|
||||
|
||||
|
||||
|
||||
def build_cruft_dict():
|
||||
pretty_printers_dict[re.compile('^util::point.*$') ] = lambda title, val: CoordPrinter(title, val)
|
||||
pretty_printers_dict[re.compile('^util::vector.*$')] = lambda title, val: CoordPrinter(title, val)
|
||||
pretty_printers_dict[re.compile('^util::extent.*$')] = lambda title, val: CoordPrinter(title, val)
|
||||
pretty_printers_dict[re.compile('^util::colour.*$')] = lambda title, val: CoordPrinter(title, val)
|
||||
|
||||
|
||||
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 ()
|
||||
|
Loading…
Reference in New Issue
Block a user