-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gdbinit.py
96 lines (79 loc) · 2.14 KB
/
.gdbinit.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import gdb.printing
def kind_to_str(kind):
kind = int(kind)
switch = {
0: "UECALL",
1: "RETURN",
2: "SECALL",
3: "TIMESTAMP",
4: "EXCEPTION",
5: "PCHI"
}
return switch.get(kind, "invalid")
def kind_to_field(kind):
kind = int(kind)
switch = {
0: "ecall",
1: "ret",
2: "ecall",
3: "timestamp",
4: "exception",
5: "pchi"
}
return switch.get(kind, "val")
class owl_trace_field_printer:
"""Print an owl_trace union field."""
def __init__(self, val):
self.val = val
def to_string(self):
return None
def children(self):
kind = self.val["kind"]
for field in self.val.type.fields():
key = field.name
val = self.val[key]
if key == "kind":
yield key, "<" + kind_to_str(val) + ">"
elif key == "pc":
yield key, hex(val)
elif key == "priv":
yield key, hex(val)
else: yield key, val
class owl_trace_printer:
"""Print an owl_trace union."""
def __init__(self, val):
self.val = val
def to_string(self):
return None
def children(self):
kind = self.val["kind"]
yield kind_to_field(kind), self.val[kind_to_field(kind)]
class callstack_printer:
"""Print a callstack struct."""
def __init__(self, val):
self.val = val
def to_string(self):
return None
def children(self):
yield "frameno", self.val["frameno"]
for field in self.val.type.fields():
key = field.name
val = self.val[key]
if key == "frameno": continue
# elif key == "frames":
# if not val: yield key, "NULL"
# else:
# yield key + "[0]", (val+0).dereference()
# yield key + "[1]", (val+1).dereference()
# yield key + "[2]", (val+2).dereference()
else:
yield key, val
def build_pretty_printer():
pp = gdb.printing.RegexpCollectionPrettyPrinter("owl")
pp.add_printer('owl_trace', '^owl_trace$', owl_trace_printer)
pp.add_printer('owl_.*_trace', '^owl_.*_trace$', owl_trace_field_printer)
pp.add_printer('callstack', '^callstack$', callstack_printer)
return pp
gdb.printing.register_pretty_printer(
gdb.current_objfile(),
build_pretty_printer())