mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
contrib/gdb.py: add a pretty-printer for ptrlen.
I mostly really like the use of 'ptrlen' in place of zero-terminated strings in PuTTY, but one place it's awkward is when debuggging through string-handling code, because gdb won't automatically show me exactly what a ptrlen points to. Now it does.
This commit is contained in:
parent
8d2c643fcb
commit
619bb441ec
@ -30,12 +30,29 @@ class PuTTYMpintPrettyPrinter(gdb.printing.PrettyPrinter):
|
|||||||
return "mp_int(NULL)".format(address)
|
return "mp_int(NULL)".format(address)
|
||||||
return "mp_int(invalid @ {:#x})".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):
|
class PuTTYPrinterSelector(gdb.printing.PrettyPrinter):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(PuTTYPrinterSelector, self).__init__("PuTTY")
|
super(PuTTYPrinterSelector, self).__init__("PuTTY")
|
||||||
def __call__(self, val):
|
def __call__(self, val):
|
||||||
if str(val.type) == "mp_int *":
|
if str(val.type) == "mp_int *":
|
||||||
return PuTTYMpintPrettyPrinter(val)
|
return PuTTYMpintPrettyPrinter(val)
|
||||||
|
if str(val.type) == "ptrlen":
|
||||||
|
return PuTTYPtrlenPrettyPrinter(val)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
gdb.printing.register_pretty_printer(None, PuTTYPrinterSelector())
|
gdb.printing.register_pretty_printer(None, PuTTYPrinterSelector())
|
||||||
|
Loading…
Reference in New Issue
Block a user