From 8bc6ed6cbb4e1c19ea7bc85ec2313824b19b1cf2 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 8 Mar 2012 20:32:13 +0000 Subject: [PATCH] add gdb pretty printers for kakoune data structures --- gdb/kakoune.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/.gdbinit | 8 ++++++ 2 files changed, 74 insertions(+) create mode 100644 gdb/kakoune.py create mode 100644 src/.gdbinit diff --git a/gdb/kakoune.py b/gdb/kakoune.py new file mode 100644 index 000000000..f9ef11f3a --- /dev/null +++ b/gdb/kakoune.py @@ -0,0 +1,66 @@ +import gdb.printing + +class ArrayIterator: + def __init__ (self, data, count): + self.data = data + self.count = count + self.index = 0 + + def __iter__ (self): + return self + + def next (self): + if self.index == self.count: + raise StopIteration + + index = self.index + self.index = self.index + 1 + return ('[%d]' % index, (self.data + index).dereference()) + +class MemoryView: + """Print a memoryview""" + + def __init__(self, val): + self.val = val + + def display_hint(self): + return 'array' + + def children(self): + return ArrayIterator(self.val['m_pointer'], self.val['m_size']) + + def to_string(self): + value_type = self.val.type.template_argument(0).unqualified().strip_typedefs() + return "memoryview<%s>" % (value_type) + +class LineAndColumn: + """Print a LineAndColumn""" + + def __init__(self, val): + self.val = val + + def to_string(self): + value_type = self.val.type.unqualified() + return "%s(%d, %d)" % (value_type, self.val['line'], self.val['column']) + +class BufferIterator: + """ Print a BufferIterator""" + + def __init__(self, val): + self.val = val + + def to_string(self): + if self.val['m_buffer'] != 0: + return "buffer<%s>@%d" % (self.val['m_buffer'].dereference()['m_name'], self.val['m_position']) + else: + return "buffer@%s" % (self.val['m_position']) + +def build_pretty_printer(): + pp = gdb.printing.RegexpCollectionPrettyPrinter("kakoune") + pp.add_printer('memoryview', '^Kakoune::memoryview<.*>$', MemoryView) + pp.add_printer('LineAndColumn', '^Kakoune::LineAndColumn<.*>$', LineAndColumn) + pp.add_printer('BufferCoord', '^Kakoune::BufferCoord$', LineAndColumn) + pp.add_printer('DisplayCoord', '^Kakoune::DisplayCoord$', LineAndColumn) + pp.add_printer('BufferIterator', '^Kakoune::BufferIterator$', BufferIterator) + return pp + diff --git a/src/.gdbinit b/src/.gdbinit new file mode 100644 index 000000000..77c560c2f --- /dev/null +++ b/src/.gdbinit @@ -0,0 +1,8 @@ +python +sys.path.insert(0, '../gdb/') +import gdb.printing +import kakoune +gdb.printing.register_pretty_printer( + gdb.current_objfile(), + kakoune.build_pretty_printer()) +end