|
| 1 | +# noinspection PyUnresolvedReferences |
| 2 | +import lldb |
| 3 | + |
| 4 | + |
| 5 | +def call_cpp_debug_print(valobj, arg_type: str): |
| 6 | + type = valobj.GetType() |
| 7 | + if type.is_reference or type.is_pointer: |
| 8 | + addr = valobj.Dereference().GetAddress() |
| 9 | + else: |
| 10 | + addr = valobj.GetAddress() |
| 11 | + if not addr.IsValid(): |
| 12 | + return "nullptr" |
| 13 | + |
| 14 | + s = valobj.GetFrame().EvaluateExpression('debug_print(({}*){})'.format(arg_type, addr)).GetSummary() |
| 15 | + s = str(s)[1:-1] # trim quotes |
| 16 | + |
| 17 | + if "{enum.Op.cl}" in s: |
| 18 | + s = s.replace("{enum.Op.cl}", valobj.GetChildMemberWithName("cl").GetValue()) |
| 19 | + if "{enum.AsmOp.t}" in s: |
| 20 | + s = s.replace("{enum.AsmOp.t}", valobj.GetChildMemberWithName("t").GetValue()) |
| 21 | + return s |
| 22 | + |
| 23 | + |
| 24 | +def print_td_RefInt256(valobj, internal_dict, options): |
| 25 | + n = valobj.EvaluateExpression("ptr.value.n").GetValueAsUnsigned() |
| 26 | + if n == 0: |
| 27 | + return "0" |
| 28 | + if n == 1: |
| 29 | + return valobj.EvaluateExpression("ptr.value.digits[0]").GetValueAsUnsigned() |
| 30 | + return "n=" + str(n) |
| 31 | + |
| 32 | + |
| 33 | +def print_ast_vertex(valobj, internal_dict, options): |
| 34 | + type = valobj.GetType() |
| 35 | + if type.is_reference or type.is_pointer: |
| 36 | + addr = valobj.Dereference().GetAddress() |
| 37 | + else: |
| 38 | + addr = valobj.GetAddress() |
| 39 | + if not addr.IsValid(): |
| 40 | + return "nullptr" |
| 41 | + |
| 42 | + s = valobj.GetFrame().EvaluateExpression('debug_print((tolk::ASTNodeBase*){})'.format(addr)).GetSummary() |
| 43 | + s = str(s)[1:-1] # trim quotes |
| 44 | + |
| 45 | + return s |
| 46 | + |
| 47 | + |
| 48 | +def __lldb_init_module(debugger, _): |
| 49 | + types_with_debug_print = [ |
| 50 | + 'tolk::Op', |
| 51 | + 'tolk::TypeData', |
| 52 | + 'tolk::VarDescr', |
| 53 | + 'tolk::TmpVar', |
| 54 | + 'tolk::VarDescrList', |
| 55 | + 'tolk::AsmOp', |
| 56 | + 'tolk::AsmOpList', |
| 57 | + 'tolk::Stack', |
| 58 | + 'tolk::SrcRange', |
| 59 | + 'tolk::LocalVarData', |
| 60 | + 'tolk::FunctionData', |
| 61 | + 'tolk::GlobalVarData', |
| 62 | + 'tolk::GlobalConstData', |
| 63 | + 'tolk::AliasDeclarationData', |
| 64 | + 'tolk::StructFieldData', |
| 65 | + 'tolk::StructData', |
| 66 | + 'tolk::EnumMemberData', |
| 67 | + 'tolk::EnumDefData', |
| 68 | + 'tolk::FlowContext', |
| 69 | + 'tolk::SinkExpression', |
| 70 | + 'tolk::InfoAboutExpr', |
| 71 | + 'tolk::GenericsDeclaration', |
| 72 | + 'tolk::GenericsSubstitutions', |
| 73 | + ] |
| 74 | + for arg_type in types_with_debug_print: |
| 75 | + debugger.HandleCommand('type summary add --python-script "return lldb_addons.call_cpp_debug_print(valobj, \'{}\')" {}'.format(arg_type, arg_type)) |
| 76 | + |
| 77 | + debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTNodeBase') |
| 78 | + debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTNodeDeclaredTypeBase') |
| 79 | + debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTNodeExpressionBase') |
| 80 | + debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTNodeStatementBase') |
| 81 | + debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTTypeLeaf') |
| 82 | + debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTTypeVararg') |
| 83 | + debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTExprLeaf') |
| 84 | + debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTExprUnary') |
| 85 | + debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTExprBinary') |
| 86 | + debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTExprVararg') |
| 87 | + debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTStatementUnary') |
| 88 | + debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" tolk::ASTStatementVararg') |
| 89 | + debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" -x "^tolk::V<.+>$"') |
| 90 | + debugger.HandleCommand('type summary add --python-function "lldb_addons.print_ast_vertex" -x "^tolk::Vertex<.+>$"') |
| 91 | + debugger.HandleCommand('type summary add --python-function "lldb_addons.print_td_RefInt256" td::RefInt256') |
0 commit comments