From 6843740840db1c8d126df0f81fb62ac07601f6ba Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 27 Jan 2015 14:01:32 +0000 Subject: [PATCH] Add pretty printer for ref_ptr --- gdb/kakoune.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gdb/kakoune.py b/gdb/kakoune.py index c64a343a2..d77a6f9e9 100644 --- a/gdb/kakoune.py +++ b/gdb/kakoune.py @@ -74,6 +74,18 @@ class StringView: def to_string(self): return "\"%s\"" % (self.val['m_data'].string("utf-8", "ignore", self.val['m_length']['m_value'])) +class StringStoragePtr: + """ Print a ref_ptr""" + + 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']) + class Option: """ Print a Option""" @@ -120,6 +132,7 @@ def build_pretty_printer(): pp.add_printer('String', '^Kakoune::String$', String) pp.add_printer('StringView', '^Kakoune::StringView$', StringView) pp.add_printer('SharedString', '^Kakoune::SharedString$', StringView) + pp.add_printer('StringStoragePtr', '^Kakoune::ref_ptr$', StringStoragePtr) pp.add_printer('Option', '^Kakoune::Option$', Option) pp.add_printer('LineCount', '^Kakoune::LineCount$', LineCount) pp.add_printer('CharCount', '^Kakoune::CharCount$', CharCount)