forked from ton-blockchain/ton
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlldb_addons.py
More file actions
91 lines (78 loc) · 4.05 KB
/
lldb_addons.py
File metadata and controls
91 lines (78 loc) · 4.05 KB
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
# noinspection PyUnresolvedReferences
import lldb
def call_cpp_debug_print(valobj, arg_type: str):
type = valobj.GetType()
if type.is_reference or type.is_pointer:
addr = valobj.Dereference().GetAddress()
else:
addr = valobj.GetAddress()
if not addr.IsValid():
return "nullptr"
s = valobj.GetFrame().EvaluateExpression('debug_print(({}*){})'.format(arg_type, addr)).GetSummary()
s = str(s)[1:-1] # trim quotes
if "{enum.Op.cl}" in s:
s = s.replace("{enum.Op.cl}", valobj.GetChildMemberWithName("cl").GetValue())
if "{enum.AsmOp.t}" in s:
s = s.replace("{enum.AsmOp.t}", valobj.GetChildMemberWithName("t").GetValue())
return s
def print_td_RefInt256(valobj, internal_dict, options):
n = valobj.EvaluateExpression("ptr.value.n").GetValueAsUnsigned()
if n == 0:
return "0"
if n == 1:
return valobj.EvaluateExpression("ptr.value.digits[0]").GetValueAsUnsigned()
return "n=" + str(n)
def print_ast_vertex(valobj, internal_dict, options):
type = valobj.GetType()
if type.is_reference or type.is_pointer:
addr = valobj.Dereference().GetAddress()
else:
addr = valobj.GetAddress()
if not addr.IsValid():
return "nullptr"
s = valobj.GetFrame().EvaluateExpression('debug_print((tolk::ASTNodeBase*){})'.format(addr)).GetSummary()
s = str(s)[1:-1] # trim quotes
return s
def __lldb_init_module(debugger, _):
types_with_debug_print = [
'tolk::Op',
'tolk::TypeData',
'tolk::VarDescr',
'tolk::TmpVar',
'tolk::VarDescrList',
'tolk::AsmOp',
'tolk::AsmOpList',
'tolk::Stack',
'tolk::SrcRange',
'tolk::LocalVarData',
'tolk::FunctionData',
'tolk::GlobalVarData',
'tolk::GlobalConstData',
'tolk::AliasDeclarationData',
'tolk::StructFieldData',
'tolk::StructData',
'tolk::EnumMemberData',
'tolk::EnumDefData',
'tolk::FlowContext',
'tolk::SinkExpression',
'tolk::InfoAboutExpr',
'tolk::GenericsDeclaration',
'tolk::GenericsSubstitutions',
]
for arg_type in types_with_debug_print:
debugger.HandleCommand('type summary add --python-script "return lldb_addons.call_cpp_debug_print(valobj, \'{}\')" {}'.format(arg_type, arg_type))
debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTNodeBase')
debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTNodeDeclaredTypeBase')
debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTNodeExpressionBase')
debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTNodeStatementBase')
debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTTypeLeaf')
debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTTypeVararg')
debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTExprLeaf')
debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTExprUnary')
debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTExprBinary')
debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTExprVararg')
debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTStatementUnary')
debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTStatementVararg')
debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" -x "^tolk::V<.+>$"')
debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" -x "^tolk::Vertex<.+>$"')
debugger.HandleCommand('type summary add --python-function "lldb_addons.print_td_RefInt256" td::RefInt256')