2012-03-08 21:32:13 +01:00
|
|
|
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())
|
|
|
|
|
2015-01-23 14:53:20 +01:00
|
|
|
class ArrayView:
|
|
|
|
"""Print a ArrayView"""
|
2012-03-08 21:32:13 +01:00
|
|
|
|
|
|
|
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()
|
2015-01-23 14:53:20 +01:00
|
|
|
return "ArrayView<%s>" % (value_type)
|
2012-03-08 21:32:13 +01:00
|
|
|
|
|
|
|
class LineAndColumn:
|
|
|
|
"""Print a LineAndColumn"""
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
value_type = self.val.type.unqualified()
|
2012-09-05 19:20:13 +02:00
|
|
|
return "%s(%s, %s)" % (value_type, self.val['line'], self.val['column'])
|
2012-03-08 21:32:13 +01:00
|
|
|
|
|
|
|
class BufferIterator:
|
|
|
|
""" Print a BufferIterator"""
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
2012-11-26 18:50:09 +01:00
|
|
|
if self.val['m_buffer']['m_ptr'] != 0:
|
|
|
|
return "buffer<%s>@(%s, %s)" % (self.val['m_buffer']['m_ptr'].dereference()['m_name'], self.val['m_coord']['line'], self.val['m_coord']['column'])
|
2012-03-08 21:32:13 +01:00
|
|
|
else:
|
2012-09-05 19:20:13 +02:00
|
|
|
return "buffer<none>@(%s, %s)" % (self.val['m_coord']['line'], self.val['m_coord']['column'])
|
2012-03-08 21:32:13 +01:00
|
|
|
|
2012-06-14 14:58:24 +02:00
|
|
|
class String:
|
|
|
|
""" Print a String"""
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
2015-03-24 14:40:34 +01:00
|
|
|
return "%s" % (self.val['m_data'])
|
2012-06-14 14:58:24 +02:00
|
|
|
|
2015-01-23 14:53:20 +01:00
|
|
|
class StringView:
|
|
|
|
""" Print a StringView"""
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
return "\"%s\"" % (self.val['m_data'].string("utf-8", "ignore", self.val['m_length']['m_value']))
|
|
|
|
|
2015-05-13 14:28:23 +02:00
|
|
|
class StringDataPtr:
|
|
|
|
""" Print a RefPtr<StringData>"""
|
2015-01-27 15:01:32 +01:00
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
ptr = self.val['m_ptr']
|
|
|
|
str_type = gdb.lookup_type("char").pointer()
|
|
|
|
content = (ptr + 1).cast(str_type).string("utf-8", "ignore", ptr.dereference()['length'])
|
|
|
|
return "\"%s\" (ref:%d)" % (content.replace("\n", "\\n"), ptr.dereference()['refcount'])
|
|
|
|
|
2015-05-13 14:28:23 +02:00
|
|
|
class RefPtr:
|
|
|
|
""" Print a RefPtr"""
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
ptr = self.val['m_ptr']
|
|
|
|
return "\"refptr %s\"" % (ptr)
|
|
|
|
|
2012-06-14 14:58:24 +02:00
|
|
|
class Option:
|
|
|
|
""" Print a Option"""
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
return self.val["m_value"]
|
|
|
|
|
2012-09-05 19:20:13 +02:00
|
|
|
class CharCount:
|
|
|
|
"""Print a CharCount"""
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
return self.val["m_value"]
|
|
|
|
|
2012-10-22 13:13:18 +02:00
|
|
|
class ByteCount:
|
|
|
|
"""Print a ByteCount"""
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
return self.val["m_value"]
|
|
|
|
|
2012-09-05 19:20:13 +02:00
|
|
|
class LineCount:
|
|
|
|
"""Print a LineCount"""
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
return self.val["m_value"]
|
|
|
|
|
2016-01-24 08:11:52 +01:00
|
|
|
class Color:
|
|
|
|
"""Print a Color"""
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
if self.val["color"] == gdb.lookup_type("Kakoune::Color::NamedColor")["Kakoune::Color::RGB"].enumval:
|
|
|
|
return "%s #%02x%02x%02x" % (self.val["color"], self.val["r"], self.val["g"], self.val["b"])
|
|
|
|
else:
|
|
|
|
return self.val["color"]
|
|
|
|
|
2012-03-08 21:32:13 +01:00
|
|
|
def build_pretty_printer():
|
|
|
|
pp = gdb.printing.RegexpCollectionPrettyPrinter("kakoune")
|
2015-01-23 14:53:20 +01:00
|
|
|
pp.add_printer('ArrayView', '^Kakoune::ArrayView<.*>$', ArrayView)
|
2012-03-08 21:32:13 +01:00
|
|
|
pp.add_printer('LineAndColumn', '^Kakoune::LineAndColumn<.*>$', LineAndColumn)
|
2014-05-14 23:16:51 +02:00
|
|
|
pp.add_printer('ByteCoord', '^Kakoune::ByteCoord$', LineAndColumn)
|
|
|
|
pp.add_printer('CharCoord', '^Kakoune::CharCoord$', LineAndColumn)
|
2012-03-08 21:32:13 +01:00
|
|
|
pp.add_printer('BufferIterator', '^Kakoune::BufferIterator$', BufferIterator)
|
2012-06-14 14:58:24 +02:00
|
|
|
pp.add_printer('String', '^Kakoune::String$', String)
|
2015-01-23 14:53:20 +01:00
|
|
|
pp.add_printer('StringView', '^Kakoune::StringView$', StringView)
|
|
|
|
pp.add_printer('SharedString', '^Kakoune::SharedString$', StringView)
|
2015-05-13 14:28:23 +02:00
|
|
|
pp.add_printer('StringDataPtr', '^Kakoune::RefPtr<Kakoune::StringData,.*>$', StringDataPtr)
|
|
|
|
pp.add_printer('RefPtr', '^Kakoune::RefPtr<.*>$', RefPtr)
|
2012-06-14 14:58:24 +02:00
|
|
|
pp.add_printer('Option', '^Kakoune::Option$', Option)
|
2012-09-05 19:20:13 +02:00
|
|
|
pp.add_printer('LineCount', '^Kakoune::LineCount$', LineCount)
|
|
|
|
pp.add_printer('CharCount', '^Kakoune::CharCount$', CharCount)
|
2012-10-22 13:13:18 +02:00
|
|
|
pp.add_printer('ByteCount', '^Kakoune::ByteCount$', ByteCount)
|
2016-01-24 08:11:52 +01:00
|
|
|
pp.add_printer('Color', '^Kakoune::Color$', Color)
|
2012-03-08 21:32:13 +01:00
|
|
|
return pp
|
|
|
|
|