File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ python
2+
3+ import gdb
4+ import re
5+
6+
7+ class BetypePrinter:
8+ PATTERN = re.compile(" ^betype<.*>$" )
9+
10+ def __init__(self, obj):
11+ self._obj = obj
12+
13+ def to_string(self):
14+ underlying = self._obj[" m_value" ]
15+ reversed_bytes = bytes(reversed(underlying.bytes))
16+ return gdb.Value(reversed_bytes, underlying.type)
17+
18+ class MemptrPrinter:
19+ PATTERN = re.compile(" ^MEMPTR<.*>$" )
20+
21+ def __init__(self, obj):
22+ self._ptr_type = obj.type.strip_typedefs().unqualified().template_argument(0 ).pointer()
23+ self._guest_address = obj[" m_value" ].cast(gdb.lookup_type(" uint32" ))
24+
25+ def ptr(self):
26+ if self._guest_address == 0 :
27+ return gdb.Value(0 , self._ptr_type)
28+ base_addr = gdb.parse_and_eval(' memory_base' , global_context=True)
29+ return (self._guest_address + base_addr).reinterpret_cast(self._ptr_type)
30+
31+ def children(self):
32+ return [(" raw" , self.ptr())]
33+
34+ def to_string(self):
35+ return self._guest_address.format_string(format=" x" )
36+
37+ def lookup(val):
38+ tag = val.type.strip_typedefs().unqualified().tag
39+ if tag is None:
40+ return None
41+ printers = [BetypePrinter, MemptrPrinter]
42+ for printer in printers:
43+ if printer.PATTERN.match(tag):
44+ return printer(val)
45+ return None
46+
47+ gdb.pretty_printers.append(lookup)
You can’t perform that action at this time.
0 commit comments