-
Notifications
You must be signed in to change notification settings - Fork 14
/
gdb.py
61 lines (49 loc) · 1.73 KB
/
gdb.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
61
# GDB pretty formatter for the AUI project
#
# To enable, run the following command at the (lldb) prompt:
# source (aui-dir)/gdb.py
#
# This can be automatically enabled at the start of every debugging session by creating a ~/.gdbinit file which
# contains this command.
import re
_aui_disable_formatting = False
def _member_function_call(obj: gdb.Value, call: str):
global _aui_disable_formatting
_aui_disable_formatting = True
out = gdb.parse_and_eval(f'(({obj.type}*){obj.address})->{call}')
_aui_disable_formatting = False
return out
class AOptionalPrinter(gdb.ValuePrinter):
def __init__(self, val):
self._val = val
if val["mInitialized"]:
self._contained_value = _member_function_call(val, "value()")
else:
self._contained_value = None
def to_string(self):
if self._contained_value is None:
return f"[no contained value]"
def display_hint(self):
return 'string'
def children(self):
class Contained:
def __init__(self, val):
self._val = val
def __iter__(self):
return self
def __next__(self):
if self._val is None:
raise StopIteration
retval = self._val
self._val = None
return ('[contained value]', retval)
if self._contained_value is None:
return Contained(None)
return Contained(self._contained_value)
def AOptional_lookup(val):
if _aui_disable_formatting:
return
pattern = re.compile('^AOptional<(.*)>$')
if pattern.match(str(val.type.tag)):
return AOptionalPrinter(val)
gdb.pretty_printers.append(AOptional_lookup)