-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprinters.py
66 lines (41 loc) · 1.52 KB
/
printers.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
import gdb.printing
class PrinterBase(object):
@classmethod
def matches(cls, val):
try:
return val.type.target().name == cls.typeName
except RuntimeError:
return False
class GlobalDataPrinter(PrinterBase):
typeName = 'interpreter__eval_contexts__global_data'
def __init__(self, val):
self.val = val
def children(self):
return [("Ast_Root", self.val["ast_root"]),
("Last_Error", self.val["last_error"])]
def to_string(self):
return "Kernel"
class EnvironmentPrinter(PrinterBase):
typeName = 'interpreter__eval_contexts__environment'
def __init__(self, val):
self.val = val
def children(self):
return [("Bindings", self.val["local_bindings"]),
("Parent", self.val["parent"].dereference())]
def to_string(self):
return "Environment"
class EvalContextPrinter(PrinterBase):
typeName = 'interpreter__eval_contexts__eval_context'
def __init__(self, val):
self.val = val
def children(self):
return [("kernel", self.val["kernel"].dereference()),
("frames", self.val["frames"].dereference())]
def to_string(self):
return "Evaluation context"
printer_types = [EvalContextPrinter, GlobalDataPrinter, EnvironmentPrinter]
def eval_context_lookup(val):
for printer_type in printer_types:
if printer_type.matches(val):
return printer_type(val)
gdb.current_objfile().pretty_printers.append(eval_context_lookup)