-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvss_pp.py
60 lines (43 loc) · 1.65 KB
/
vss_pp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import gdb
import gdb.printing
from gnatdbg.tagged import reinterpret_tagged
# Use the tag class if it is available.
if hasattr(gdb, "ValuePrinter"):
base = gdb.ValuePrinter
else:
base = object
class Virtual_String_Printer(base):
def __init__(self, val):
self._val = val
def to_string(self):
text_type = gdb.lookup_type(
"vss.implementation.text_handlers.abstract_text_handler"
)
utf8static_type = gdb.lookup_type(
"vss.implementation.text_handlers.utf8.variable.static.static_utf8_handler"
)
utf8dynamic_type = gdb.lookup_type(
"vss.implementation.text_handlers.utf8.variable.dynamic.dynamic_utf8_handler"
)
storage = self._val["data"]["storage"]
if all(byte == 0 for byte in storage.bytes):
# "null" string
return ""
text = reinterpret_tagged(storage.cast(text_type))
if text.type == utf8static_type:
return text["storage"].lazy_string(encoding="utf-8", length=text["size"])
elif text.type == utf8dynamic_type:
data = text["pointer"].dereference()
return data["storage"].lazy_string(encoding="utf-8", length=data["size"])
else:
raise TypeError("<UNKNOWN TYPE>")
def display_hint(self):
return "string"
class VSSPrinter(gdb.printing.PrettyPrinter):
"""Pretty-print VSS strings."""
def __init__(self):
super().__init__("VSS")
def __call__(self, val):
if str(val.type) == "vss.strings.virtual_string":
return Virtual_String_Printer(val)
gdb.printing.register_pretty_printer(None, VSSPrinter())