diff options
Diffstat (limited to 'CONTRIB/gdb.py')
-rw-r--r-- | CONTRIB/gdb.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/CONTRIB/gdb.py b/CONTRIB/gdb.py index 34bbb0ec..fb7413ec 100644 --- a/CONTRIB/gdb.py +++ b/CONTRIB/gdb.py @@ -30,12 +30,29 @@ class PuTTYMpintPrettyPrinter(gdb.printing.PrettyPrinter): return "mp_int(NULL)".format(address) return "mp_int(invalid @ {:#x})".format(address) +class PuTTYPtrlenPrettyPrinter(gdb.printing.PrettyPrinter): + "Pretty-print strings in PuTTY's ptrlen type." + name = "ptrlen" + + def __init__(self, val): + super(PuTTYPtrlenPrettyPrinter, self).__init__(self.name) + self.val = val + + def to_string(self): + length = int(self.val["len"]) + char_array_ptr_type = gdb.lookup_type( + "char").const().array(length).pointer() + line = self.val["ptr"].cast(char_array_ptr_type).dereference() + return repr(bytes(int(line[i]) for i in range(length))).lstrip('b') + class PuTTYPrinterSelector(gdb.printing.PrettyPrinter): def __init__(self): super(PuTTYPrinterSelector, self).__init__("PuTTY") def __call__(self, val): if str(val.type) == "mp_int *": return PuTTYMpintPrettyPrinter(val) + if str(val.type) == "ptrlen": + return PuTTYPtrlenPrettyPrinter(val) return None gdb.printing.register_pretty_printer(None, PuTTYPrinterSelector()) @@ -203,7 +220,7 @@ class List234(gdb.Function): Arguments are a tree234, and optionally a value type. If no value type is given, the result is a list of the raw void * pointers - stored in the tree. Othewise, each one is cast to a pointer to the + stored in the tree. Otherwise, each one is cast to a pointer to the value type and dereferenced. Due to limitations of GDB's convenience function syntax, the value |