libcruft-util/debug/gdb/printers.py

65 lines
1.6 KiB
Python
Raw Normal View History

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 ()