| Sean Callanan | 79763a4 | 2011-05-23 21:40:23 +0000 | [diff] [blame] | 1 | //===-- ClangUserExpression.cpp ---------------------------------*- C++ -*-===// |
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 2 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| Haibo Huang | c6551bf | 2019-08-07 06:15:01 +0000 | [diff] [blame] | 9 | #include "lldb/Host/Config.h" |
| 10 | |
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 11 | #include <stdio.h> |
| 12 | #if HAVE_SYS_TYPES_H |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 13 | #include <sys/types.h> |
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 14 | #endif |
| 15 | |
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 16 | #include <cstdlib> |
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 17 | #include <map> |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 18 | #include <string> |
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 19 | |
| Sean Callanan | 4dbb271 | 2015-09-25 20:35:58 +0000 | [diff] [blame] | 20 | #include "ClangUserExpression.h" |
| 21 | |
| 22 | #include "ASTResultSynthesizer.h" |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | #include "ClangDiagnostic.h" |
| Sean Callanan | 4dbb271 | 2015-09-25 20:35:58 +0000 | [diff] [blame] | 24 | #include "ClangExpressionDeclMap.h" |
| 25 | #include "ClangExpressionParser.h" |
| 26 | #include "ClangModulesDeclVendor.h" |
| 27 | #include "ClangPersistentVariables.h" |
| Raphael Isemann | 9379d19 | 2019-09-24 10:08:18 +0000 | [diff] [blame] | 28 | #include "CppModuleConfiguration.h" |
| Sean Callanan | 4dbb271 | 2015-09-25 20:35:58 +0000 | [diff] [blame] | 29 | |
| Sean Callanan | bda7ef8 | 2016-06-22 17:32:17 +0000 | [diff] [blame] | 30 | #include "lldb/Core/Debugger.h" |
| Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 31 | #include "lldb/Core/Module.h" |
| Greg Clayton | c4e411f | 2011-01-18 19:36:39 +0000 | [diff] [blame] | 32 | #include "lldb/Core/StreamFile.h" |
| Greg Clayton | b71f384 | 2010-10-05 03:13:51 +0000 | [diff] [blame] | 33 | #include "lldb/Core/ValueObjectConstResult.h" |
| Sean Callanan | 9bc8384 | 2011-09-26 18:45:31 +0000 | [diff] [blame] | 34 | #include "lldb/Expression/ExpressionSourceCode.h" |
| Sean Callanan | 14b1bae | 2013-04-16 23:25:35 +0000 | [diff] [blame] | 35 | #include "lldb/Expression/IRExecutionUnit.h" |
| Sean Callanan | 1582ee6 | 2013-04-18 22:06:33 +0000 | [diff] [blame] | 36 | #include "lldb/Expression/IRInterpreter.h" |
| Sean Callanan | 96d2730 | 2013-04-11 00:09:05 +0000 | [diff] [blame] | 37 | #include "lldb/Expression/Materializer.h" |
| Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 38 | #include "lldb/Host/HostInfo.h" |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 39 | #include "lldb/Symbol/Block.h" |
| Jim Ingham | 5fdeed4 | 2012-10-30 23:35:54 +0000 | [diff] [blame] | 40 | #include "lldb/Symbol/ClangASTContext.h" |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 41 | #include "lldb/Symbol/ClangExternalASTSourceCommon.h" |
| Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 42 | #include "lldb/Symbol/CompileUnit.h" |
| Jim Ingham | 5fdeed4 | 2012-10-30 23:35:54 +0000 | [diff] [blame] | 43 | #include "lldb/Symbol/Function.h" |
| Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 44 | #include "lldb/Symbol/ObjectFile.h" |
| 45 | #include "lldb/Symbol/SymbolVendor.h" |
| Jim Ingham | 5fdeed4 | 2012-10-30 23:35:54 +0000 | [diff] [blame] | 46 | #include "lldb/Symbol/Type.h" |
| Sean Callanan | fc55f5d | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 47 | #include "lldb/Symbol/VariableList.h" |
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 48 | #include "lldb/Target/ExecutionContext.h" |
| Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 49 | #include "lldb/Target/Process.h" |
| Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 50 | #include "lldb/Target/StackFrame.h" |
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 51 | #include "lldb/Target/Target.h" |
| Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 52 | #include "lldb/Target/ThreadPlan.h" |
| 53 | #include "lldb/Target/ThreadPlanCallUserExpression.h" |
| Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 54 | #include "lldb/Utility/ConstString.h" |
| Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 55 | #include "lldb/Utility/Log.h" |
| Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 56 | #include "lldb/Utility/StreamString.h" |
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 57 | |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 58 | #include "clang/AST/DeclCXX.h" |
| 59 | #include "clang/AST/DeclObjC.h" |
| 60 | |
| Tatyana Krasnukha | edebf12 | 2019-04-26 16:41:04 +0000 | [diff] [blame] | 61 | #include "llvm/ADT/ScopeExit.h" |
| 62 | |
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 63 | using namespace lldb_private; |
| 64 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 65 | ClangUserExpression::ClangUserExpression( |
| Zachary Turner | c5d7df9 | 2016-11-08 04:52:16 +0000 | [diff] [blame] | 66 | ExecutionContextScope &exe_scope, llvm::StringRef expr, |
| 67 | llvm::StringRef prefix, lldb::LanguageType language, |
| Aleksandr Urakov | 40624a0 | 2019-02-05 09:14:36 +0000 | [diff] [blame] | 68 | ResultType desired_type, const EvaluateExpressionOptions &options, |
| 69 | ValueObject *ctx_obj) |
| Zachary Turner | c5d7df9 | 2016-11-08 04:52:16 +0000 | [diff] [blame] | 70 | : LLVMUserExpression(exe_scope, expr, prefix, language, desired_type, |
| Adrian Prantl | 7e34d78 | 2019-03-13 19:46:30 +0000 | [diff] [blame] | 71 | options, eKindClangUserExpression), |
| Jonas Devlieghere | 70355ac | 2019-02-12 03:47:39 +0000 | [diff] [blame] | 72 | m_type_system_helper(*m_target_wp.lock(), options.GetExecutionPolicy() == |
| 73 | eExecutionPolicyTopLevel), |
| 74 | m_result_delegate(exe_scope.CalculateTarget()), m_ctx_obj(ctx_obj) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 75 | switch (m_language) { |
| 76 | case lldb::eLanguageTypeC_plus_plus: |
| 77 | m_allow_cxx = true; |
| 78 | break; |
| 79 | case lldb::eLanguageTypeObjC: |
| 80 | m_allow_objc = true; |
| 81 | break; |
| 82 | case lldb::eLanguageTypeObjC_plus_plus: |
| 83 | default: |
| 84 | m_allow_cxx = true; |
| 85 | m_allow_objc = true; |
| 86 | break; |
| 87 | } |
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 90 | ClangUserExpression::~ClangUserExpression() {} |
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 91 | |
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 92 | void ClangUserExpression::ScanContext(ExecutionContext &exe_ctx, Status &err) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 93 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); |
| Sean Callanan | 7038508 | 2012-12-01 00:08:33 +0000 | [diff] [blame] | 94 | |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 95 | LLDB_LOGF(log, "ClangUserExpression::ScanContext()"); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 96 | |
| 97 | m_target = exe_ctx.GetTargetPtr(); |
| 98 | |
| 99 | if (!(m_allow_cxx || m_allow_objc)) { |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 100 | LLDB_LOGF(log, " [CUE::SC] Settings inhibit C++ and Objective-C"); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 101 | return; |
| 102 | } |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 103 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 104 | StackFrame *frame = exe_ctx.GetFramePtr(); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 105 | if (frame == nullptr) { |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 106 | LLDB_LOGF(log, " [CUE::SC] Null stack frame"); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 107 | return; |
| 108 | } |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 109 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 110 | SymbolContext sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction | |
| 111 | lldb::eSymbolContextBlock); |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 112 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 113 | if (!sym_ctx.function) { |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 114 | LLDB_LOGF(log, " [CUE::SC] Null function"); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 115 | return; |
| 116 | } |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 117 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 118 | // Find the block that defines the function represented by "sym_ctx" |
| 119 | Block *function_block = sym_ctx.GetFunctionBlock(); |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 120 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 121 | if (!function_block) { |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 122 | LLDB_LOGF(log, " [CUE::SC] Null function block"); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 123 | return; |
| 124 | } |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 125 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 126 | CompilerDeclContext decl_context = function_block->GetDeclContext(); |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 127 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 128 | if (!decl_context) { |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 129 | LLDB_LOGF(log, " [CUE::SC] Null decl context"); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 130 | return; |
| 131 | } |
| Greg Clayton | 685c88c | 2012-07-14 00:53:55 +0000 | [diff] [blame] | 132 | |
| Aleksandr Urakov | 40624a0 | 2019-02-05 09:14:36 +0000 | [diff] [blame] | 133 | if (m_ctx_obj) { |
| 134 | switch (m_ctx_obj->GetObjectRuntimeLanguage()) { |
| 135 | case lldb::eLanguageTypeC: |
| 136 | case lldb::eLanguageTypeC89: |
| 137 | case lldb::eLanguageTypeC99: |
| 138 | case lldb::eLanguageTypeC11: |
| 139 | case lldb::eLanguageTypeC_plus_plus: |
| 140 | case lldb::eLanguageTypeC_plus_plus_03: |
| 141 | case lldb::eLanguageTypeC_plus_plus_11: |
| 142 | case lldb::eLanguageTypeC_plus_plus_14: |
| 143 | m_in_cplusplus_method = true; |
| 144 | break; |
| 145 | case lldb::eLanguageTypeObjC: |
| 146 | case lldb::eLanguageTypeObjC_plus_plus: |
| 147 | m_in_objectivec_method = true; |
| 148 | break; |
| 149 | default: |
| 150 | break; |
| 151 | } |
| 152 | m_needs_object_ptr = true; |
| 153 | } else if (clang::CXXMethodDecl *method_decl = |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 154 | ClangASTContext::DeclContextGetAsCXXMethodDecl(decl_context)) { |
| 155 | if (m_allow_cxx && method_decl->isInstance()) { |
| 156 | if (m_enforce_valid_object) { |
| 157 | lldb::VariableListSP variable_list_sp( |
| 158 | function_block->GetBlockVariableList(true)); |
| Greg Clayton | 685c88c | 2012-07-14 00:53:55 +0000 | [diff] [blame] | 159 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 160 | const char *thisErrorString = "Stopped in a C++ method, but 'this' " |
| 161 | "isn't available; pretending we are in a " |
| 162 | "generic context"; |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 163 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 164 | if (!variable_list_sp) { |
| 165 | err.SetErrorString(thisErrorString); |
| 166 | return; |
| Sean Callanan | 3670ba5 | 2010-12-01 21:35:54 +0000 | [diff] [blame] | 167 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 168 | |
| 169 | lldb::VariableSP this_var_sp( |
| 170 | variable_list_sp->FindVariable(ConstString("this"))); |
| 171 | |
| 172 | if (!this_var_sp || !this_var_sp->IsInScope(frame) || |
| 173 | !this_var_sp->LocationIsValidForFrame(frame)) { |
| 174 | err.SetErrorString(thisErrorString); |
| 175 | return; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | m_in_cplusplus_method = true; |
| 180 | m_needs_object_ptr = true; |
| Sean Callanan | 3670ba5 | 2010-12-01 21:35:54 +0000 | [diff] [blame] | 181 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 182 | } else if (clang::ObjCMethodDecl *method_decl = |
| 183 | ClangASTContext::DeclContextGetAsObjCMethodDecl( |
| 184 | decl_context)) { |
| 185 | if (m_allow_objc) { |
| 186 | if (m_enforce_valid_object) { |
| 187 | lldb::VariableListSP variable_list_sp( |
| 188 | function_block->GetBlockVariableList(true)); |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 189 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 190 | const char *selfErrorString = "Stopped in an Objective-C method, but " |
| 191 | "'self' isn't available; pretending we " |
| 192 | "are in a generic context"; |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 193 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 194 | if (!variable_list_sp) { |
| 195 | err.SetErrorString(selfErrorString); |
| 196 | return; |
| 197 | } |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 198 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 199 | lldb::VariableSP self_variable_sp = |
| 200 | variable_list_sp->FindVariable(ConstString("self")); |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 201 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 202 | if (!self_variable_sp || !self_variable_sp->IsInScope(frame) || |
| 203 | !self_variable_sp->LocationIsValidForFrame(frame)) { |
| 204 | err.SetErrorString(selfErrorString); |
| 205 | return; |
| 206 | } |
| 207 | } |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 208 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 209 | m_in_objectivec_method = true; |
| 210 | m_needs_object_ptr = true; |
| 211 | |
| 212 | if (!method_decl->isInstanceMethod()) |
| 213 | m_in_static_method = true; |
| 214 | } |
| 215 | } else if (clang::FunctionDecl *function_decl = |
| 216 | ClangASTContext::DeclContextGetAsFunctionDecl(decl_context)) { |
| 217 | // We might also have a function that said in the debug information that it |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 218 | // captured an object pointer. The best way to deal with getting to the |
| 219 | // ivars at present is by pretending that this is a method of a class in |
| 220 | // whatever runtime the debug info says the object pointer belongs to. Do |
| 221 | // that here. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 222 | |
| 223 | ClangASTMetadata *metadata = |
| 224 | ClangASTContext::DeclContextGetMetaData(decl_context, function_decl); |
| 225 | if (metadata && metadata->HasObjectPtr()) { |
| 226 | lldb::LanguageType language = metadata->GetObjectPtrLanguage(); |
| 227 | if (language == lldb::eLanguageTypeC_plus_plus) { |
| 228 | if (m_enforce_valid_object) { |
| 229 | lldb::VariableListSP variable_list_sp( |
| 230 | function_block->GetBlockVariableList(true)); |
| 231 | |
| 232 | const char *thisErrorString = "Stopped in a context claiming to " |
| 233 | "capture a C++ object pointer, but " |
| 234 | "'this' isn't available; pretending we " |
| 235 | "are in a generic context"; |
| 236 | |
| 237 | if (!variable_list_sp) { |
| 238 | err.SetErrorString(thisErrorString); |
| 239 | return; |
| 240 | } |
| 241 | |
| 242 | lldb::VariableSP this_var_sp( |
| 243 | variable_list_sp->FindVariable(ConstString("this"))); |
| 244 | |
| 245 | if (!this_var_sp || !this_var_sp->IsInScope(frame) || |
| 246 | !this_var_sp->LocationIsValidForFrame(frame)) { |
| 247 | err.SetErrorString(thisErrorString); |
| 248 | return; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | m_in_cplusplus_method = true; |
| 253 | m_needs_object_ptr = true; |
| 254 | } else if (language == lldb::eLanguageTypeObjC) { |
| 255 | if (m_enforce_valid_object) { |
| 256 | lldb::VariableListSP variable_list_sp( |
| 257 | function_block->GetBlockVariableList(true)); |
| 258 | |
| 259 | const char *selfErrorString = |
| 260 | "Stopped in a context claiming to capture an Objective-C object " |
| 261 | "pointer, but 'self' isn't available; pretending we are in a " |
| 262 | "generic context"; |
| 263 | |
| 264 | if (!variable_list_sp) { |
| 265 | err.SetErrorString(selfErrorString); |
| 266 | return; |
| 267 | } |
| 268 | |
| 269 | lldb::VariableSP self_variable_sp = |
| 270 | variable_list_sp->FindVariable(ConstString("self")); |
| 271 | |
| 272 | if (!self_variable_sp || !self_variable_sp->IsInScope(frame) || |
| 273 | !self_variable_sp->LocationIsValidForFrame(frame)) { |
| 274 | err.SetErrorString(selfErrorString); |
| 275 | return; |
| 276 | } |
| 277 | |
| 278 | Type *self_type = self_variable_sp->GetType(); |
| 279 | |
| 280 | if (!self_type) { |
| 281 | err.SetErrorString(selfErrorString); |
| 282 | return; |
| 283 | } |
| 284 | |
| 285 | CompilerType self_clang_type = self_type->GetForwardCompilerType(); |
| 286 | |
| 287 | if (!self_clang_type) { |
| 288 | err.SetErrorString(selfErrorString); |
| 289 | return; |
| 290 | } |
| 291 | |
| 292 | if (ClangASTContext::IsObjCClassType(self_clang_type)) { |
| 293 | return; |
| 294 | } else if (ClangASTContext::IsObjCObjectPointerType( |
| 295 | self_clang_type)) { |
| Dawn Perchik | 53f34c8 | 2015-07-01 00:54:02 +0000 | [diff] [blame] | 296 | m_in_objectivec_method = true; |
| Sean Callanan | 9bc8384 | 2011-09-26 18:45:31 +0000 | [diff] [blame] | 297 | m_needs_object_ptr = true; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 298 | } else { |
| 299 | err.SetErrorString(selfErrorString); |
| 300 | return; |
| 301 | } |
| 302 | } else { |
| 303 | m_in_objectivec_method = true; |
| 304 | m_needs_object_ptr = true; |
| Sean Callanan | 9bc8384 | 2011-09-26 18:45:31 +0000 | [diff] [blame] | 305 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 306 | } |
| Sean Callanan | 3670ba5 | 2010-12-01 21:35:54 +0000 | [diff] [blame] | 307 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 308 | } |
| Sean Callanan | fc55f5d | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 311 | // This is a really nasty hack, meant to fix Objective-C expressions of the |
| 312 | // form (int)[myArray count]. Right now, because the type information for |
| 313 | // count is not available, [myArray count] returns id, which can't be directly |
| 314 | // cast to int without causing a clang error. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 315 | static void ApplyObjcCastHack(std::string &expr) { |
| Raphael Isemann | 3ee98a1 | 2019-09-17 07:58:01 +0000 | [diff] [blame] | 316 | const std::string from = "(int)["; |
| 317 | const std::string to = "(int)(long long)["; |
| Sean Callanan | cf5498f | 2010-10-22 23:25:16 +0000 | [diff] [blame] | 318 | |
| Raphael Isemann | 3ee98a1 | 2019-09-17 07:58:01 +0000 | [diff] [blame] | 319 | size_t offset; |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 320 | |
| Raphael Isemann | 3ee98a1 | 2019-09-17 07:58:01 +0000 | [diff] [blame] | 321 | while ((offset = expr.find(from)) != expr.npos) |
| 322 | expr.replace(offset, from.size(), to); |
| Sean Callanan | cf5498f | 2010-10-22 23:25:16 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| Raphael Isemann | ba800e7d | 2018-07-10 22:12:39 +0000 | [diff] [blame] | 325 | bool ClangUserExpression::SetupPersistentState(DiagnosticManager &diagnostic_manager, |
| 326 | ExecutionContext &exe_ctx) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 327 | if (Target *target = exe_ctx.GetTargetPtr()) { |
| 328 | if (PersistentExpressionState *persistent_state = |
| 329 | target->GetPersistentExpressionStateForLanguage( |
| 330 | lldb::eLanguageTypeC)) { |
| Raphael Isemann | 1442efe | 2019-09-18 08:53:35 +0000 | [diff] [blame] | 331 | m_clang_state = llvm::cast<ClangPersistentVariables>(persistent_state); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 332 | m_result_delegate.RegisterPersistentState(persistent_state); |
| 333 | } else { |
| Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 334 | diagnostic_manager.PutString( |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 335 | eDiagnosticSeverityError, |
| 336 | "couldn't start parsing (no persistent data)"); |
| 337 | return false; |
| Sean Callanan | 9fda9d2 | 2015-10-03 09:09:01 +0000 | [diff] [blame] | 338 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 339 | } else { |
| Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 340 | diagnostic_manager.PutString(eDiagnosticSeverityError, |
| 341 | "error: couldn't start parsing (no target)"); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 342 | return false; |
| 343 | } |
| Raphael Isemann | ba800e7d | 2018-07-10 22:12:39 +0000 | [diff] [blame] | 344 | return true; |
| 345 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 346 | |
| Raphael Isemann | ba800e7d | 2018-07-10 22:12:39 +0000 | [diff] [blame] | 347 | static void SetupDeclVendor(ExecutionContext &exe_ctx, Target *target) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 348 | if (ClangModulesDeclVendor *decl_vendor = |
| Raphael Isemann | ba800e7d | 2018-07-10 22:12:39 +0000 | [diff] [blame] | 349 | target->GetClangModulesDeclVendor()) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 350 | const ClangModulesDeclVendor::ModuleVector &hand_imported_modules = |
| 351 | llvm::cast<ClangPersistentVariables>( |
| Raphael Isemann | ba800e7d | 2018-07-10 22:12:39 +0000 | [diff] [blame] | 352 | target->GetPersistentExpressionStateForLanguage( |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 353 | lldb::eLanguageTypeC)) |
| 354 | ->GetHandLoadedClangModules(); |
| 355 | ClangModulesDeclVendor::ModuleVector modules_for_macros; |
| 356 | |
| 357 | for (ClangModulesDeclVendor::ModuleID module : hand_imported_modules) { |
| 358 | modules_for_macros.push_back(module); |
| 359 | } |
| 360 | |
| Raphael Isemann | ba800e7d | 2018-07-10 22:12:39 +0000 | [diff] [blame] | 361 | if (target->GetEnableAutoImportClangModules()) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 362 | if (StackFrame *frame = exe_ctx.GetFramePtr()) { |
| 363 | if (Block *block = frame->GetFrameBlock()) { |
| 364 | SymbolContext sc; |
| 365 | |
| 366 | block->CalculateSymbolContext(&sc); |
| 367 | |
| 368 | if (sc.comp_unit) { |
| 369 | StreamString error_stream; |
| 370 | |
| 371 | decl_vendor->AddModulesForCompileUnit( |
| 372 | *sc.comp_unit, modules_for_macros, error_stream); |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | } |
| Raphael Isemann | ba800e7d | 2018-07-10 22:12:39 +0000 | [diff] [blame] | 378 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 379 | |
| Raphael Isemann | 5eb87cf | 2019-08-05 20:31:47 +0000 | [diff] [blame] | 380 | void ClangUserExpression::UpdateLanguageForExpr() { |
| 381 | m_expr_lang = lldb::LanguageType::eLanguageTypeUnknown; |
| 382 | if (m_options.GetExecutionPolicy() == eExecutionPolicyTopLevel) |
| 383 | return; |
| 384 | if (m_in_cplusplus_method) |
| 385 | m_expr_lang = lldb::eLanguageTypeC_plus_plus; |
| 386 | else if (m_in_objectivec_method) |
| 387 | m_expr_lang = lldb::eLanguageTypeObjC; |
| 388 | else |
| 389 | m_expr_lang = lldb::eLanguageTypeC; |
| 390 | } |
| 391 | |
| 392 | void ClangUserExpression::CreateSourceCode( |
| Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 393 | DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, |
| Raphael Isemann | 71569d0 | 2019-05-02 10:12:56 +0000 | [diff] [blame] | 394 | std::vector<std::string> modules_to_import, bool for_completion) { |
| Raphael Isemann | ba800e7d | 2018-07-10 22:12:39 +0000 | [diff] [blame] | 395 | |
| Raphael Isemann | 1442efe | 2019-09-18 08:53:35 +0000 | [diff] [blame] | 396 | m_filename = m_clang_state->GetNextExprFileName(); |
| Raphael Isemann | ba800e7d | 2018-07-10 22:12:39 +0000 | [diff] [blame] | 397 | std::string prefix = m_expr_prefix; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 398 | |
| 399 | if (m_options.GetExecutionPolicy() == eExecutionPolicyTopLevel) { |
| 400 | m_transformed_text = m_expr_text; |
| 401 | } else { |
| Raphael Isemann | 1442efe | 2019-09-18 08:53:35 +0000 | [diff] [blame] | 402 | m_source_code.reset(ClangExpressionSourceCode::CreateWrapped( |
| 403 | m_filename, prefix.c_str(), m_expr_text.c_str())); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 404 | |
| Raphael Isemann | 1442efe | 2019-09-18 08:53:35 +0000 | [diff] [blame] | 405 | if (!m_source_code->GetText(m_transformed_text, m_expr_lang, |
| 406 | m_in_static_method, exe_ctx, !m_ctx_obj, |
| 407 | for_completion, modules_to_import)) { |
| Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 408 | diagnostic_manager.PutString(eDiagnosticSeverityError, |
| 409 | "couldn't construct expression body"); |
| Raphael Isemann | dababf7 | 2018-09-27 10:12:54 +0000 | [diff] [blame] | 410 | return; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 411 | } |
| Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 412 | |
| 413 | // Find and store the start position of the original code inside the |
| 414 | // transformed code. We need this later for the code completion. |
| 415 | std::size_t original_start; |
| 416 | std::size_t original_end; |
| Raphael Isemann | 1442efe | 2019-09-18 08:53:35 +0000 | [diff] [blame] | 417 | bool found_bounds = m_source_code->GetOriginalBodyBounds( |
| Raphael Isemann | dababf7 | 2018-09-27 10:12:54 +0000 | [diff] [blame] | 418 | m_transformed_text, m_expr_lang, original_start, original_end); |
| Raphael Isemann | d59c8d3 | 2019-04-24 12:55:00 +0000 | [diff] [blame] | 419 | if (found_bounds) |
| Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 420 | m_user_expression_start_pos = original_start; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 421 | } |
| Raphael Isemann | ba800e7d | 2018-07-10 22:12:39 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 424 | static bool SupportsCxxModuleImport(lldb::LanguageType language) { |
| 425 | switch (language) { |
| 426 | case lldb::eLanguageTypeC_plus_plus: |
| 427 | case lldb::eLanguageTypeC_plus_plus_03: |
| 428 | case lldb::eLanguageTypeC_plus_plus_11: |
| 429 | case lldb::eLanguageTypeC_plus_plus_14: |
| 430 | case lldb::eLanguageTypeObjC_plus_plus: |
| 431 | return true; |
| 432 | default: |
| 433 | return false; |
| 434 | } |
| 435 | } |
| 436 | |
| Raphael Isemann | 9379d19 | 2019-09-24 10:08:18 +0000 | [diff] [blame] | 437 | /// Utility method that puts a message into the expression log and |
| 438 | /// returns an invalid module configuration. |
| 439 | static CppModuleConfiguration LogConfigError(const std::string &msg) { |
| Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 440 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); |
| Raphael Isemann | 9379d19 | 2019-09-24 10:08:18 +0000 | [diff] [blame] | 441 | LLDB_LOG(log, "[C++ module config] {0}", msg); |
| 442 | return CppModuleConfiguration(); |
| 443 | } |
| Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 444 | |
| Raphael Isemann | 9379d19 | 2019-09-24 10:08:18 +0000 | [diff] [blame] | 445 | CppModuleConfiguration GetModuleConfig(lldb::LanguageType language, |
| 446 | ExecutionContext &exe_ctx) { |
| Raphael Isemann | ccd54a1 | 2019-10-10 13:43:37 +0000 | [diff] [blame] | 447 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); |
| 448 | |
| Raphael Isemann | 9379d19 | 2019-09-24 10:08:18 +0000 | [diff] [blame] | 449 | // Don't do anything if this is not a C++ module configuration. |
| 450 | if (!SupportsCxxModuleImport(language)) |
| 451 | return LogConfigError("Language doesn't support C++ modules"); |
| Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 452 | |
| 453 | Target *target = exe_ctx.GetTargetPtr(); |
| Raphael Isemann | 9379d19 | 2019-09-24 10:08:18 +0000 | [diff] [blame] | 454 | if (!target) |
| 455 | return LogConfigError("No target"); |
| 456 | |
| 457 | if (!target->GetEnableImportStdModule()) |
| 458 | return LogConfigError("Importing std module not enabled in settings"); |
| Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 459 | |
| 460 | StackFrame *frame = exe_ctx.GetFramePtr(); |
| 461 | if (!frame) |
| Raphael Isemann | 9379d19 | 2019-09-24 10:08:18 +0000 | [diff] [blame] | 462 | return LogConfigError("No frame"); |
| Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 463 | |
| 464 | Block *block = frame->GetFrameBlock(); |
| 465 | if (!block) |
| Raphael Isemann | 9379d19 | 2019-09-24 10:08:18 +0000 | [diff] [blame] | 466 | return LogConfigError("No block"); |
| Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 467 | |
| 468 | SymbolContext sc; |
| 469 | block->CalculateSymbolContext(&sc); |
| 470 | if (!sc.comp_unit) |
| Raphael Isemann | 9379d19 | 2019-09-24 10:08:18 +0000 | [diff] [blame] | 471 | return LogConfigError("Couldn't calculate symbol context"); |
| Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 472 | |
| Raphael Isemann | 9379d19 | 2019-09-24 10:08:18 +0000 | [diff] [blame] | 473 | // Build a list of files we need to analyze to build the configuration. |
| 474 | FileSpecList files; |
| 475 | for (const FileSpec &f : sc.comp_unit->GetSupportFiles()) |
| 476 | files.AppendIfUnique(f); |
| 477 | // We also need to look at external modules in the case of -gmodules as they |
| 478 | // contain the support files for libc++ and the C library. |
| 479 | sc.comp_unit->ForEachExternalModule([&files](lldb::ModuleSP module) { |
| 480 | for (std::size_t i = 0; i < module->GetNumCompileUnits(); ++i) { |
| 481 | const FileSpecList &support_files = |
| 482 | module->GetCompileUnitAtIndex(i)->GetSupportFiles(); |
| 483 | for (const FileSpec &f : support_files) { |
| 484 | files.AppendIfUnique(f); |
| 485 | } |
| Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 486 | } |
| Raphael Isemann | 9379d19 | 2019-09-24 10:08:18 +0000 | [diff] [blame] | 487 | }); |
| Raphael Isemann | ccd54a1 | 2019-10-10 13:43:37 +0000 | [diff] [blame] | 488 | |
| 489 | LLDB_LOG(log, "[C++ module config] Found {0} support files to analyze", |
| 490 | files.GetSize()); |
| 491 | if (log && log->GetVerbose()) { |
| 492 | for (const FileSpec &f : files) |
| 493 | LLDB_LOGV(log, "[C++ module config] Analyzing support file: {0}", |
| 494 | f.GetPath()); |
| 495 | } |
| 496 | |
| Raphael Isemann | 9379d19 | 2019-09-24 10:08:18 +0000 | [diff] [blame] | 497 | // Try to create a configuration from the files. If there is no valid |
| 498 | // configuration possible with the files, this just returns an invalid |
| 499 | // configuration. |
| 500 | return CppModuleConfiguration(files); |
| Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 501 | } |
| 502 | |
| Raphael Isemann | ba800e7d | 2018-07-10 22:12:39 +0000 | [diff] [blame] | 503 | bool ClangUserExpression::PrepareForParsing( |
| Raphael Isemann | 71569d0 | 2019-05-02 10:12:56 +0000 | [diff] [blame] | 504 | DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, |
| 505 | bool for_completion) { |
| Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 506 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); |
| 507 | |
| Raphael Isemann | ba800e7d | 2018-07-10 22:12:39 +0000 | [diff] [blame] | 508 | InstallContext(exe_ctx); |
| 509 | |
| 510 | if (!SetupPersistentState(diagnostic_manager, exe_ctx)) |
| 511 | return false; |
| 512 | |
| 513 | Status err; |
| 514 | ScanContext(exe_ctx, err); |
| 515 | |
| 516 | if (!err.Success()) { |
| 517 | diagnostic_manager.PutString(eDiagnosticSeverityWarning, err.AsCString()); |
| 518 | } |
| 519 | |
| 520 | //////////////////////////////////// |
| 521 | // Generate the expression |
| 522 | // |
| 523 | |
| 524 | ApplyObjcCastHack(m_expr_text); |
| 525 | |
| 526 | SetupDeclVendor(exe_ctx, m_target); |
| Raphael Isemann | dababf7 | 2018-09-27 10:12:54 +0000 | [diff] [blame] | 527 | |
| Raphael Isemann | 9379d19 | 2019-09-24 10:08:18 +0000 | [diff] [blame] | 528 | CppModuleConfiguration module_config = GetModuleConfig(m_language, exe_ctx); |
| 529 | llvm::ArrayRef<std::string> imported_modules = |
| 530 | module_config.GetImportedModules(); |
| 531 | m_imported_cpp_modules = !imported_modules.empty(); |
| 532 | m_include_directories = module_config.GetIncludeDirs(); |
| Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 533 | |
| 534 | LLDB_LOG(log, "List of imported modules in expression: {0}", |
| Raphael Isemann | 9379d19 | 2019-09-24 10:08:18 +0000 | [diff] [blame] | 535 | llvm::make_range(imported_modules.begin(), imported_modules.end())); |
| 536 | LLDB_LOG(log, "List of include directories gathered for modules: {0}", |
| 537 | llvm::make_range(m_include_directories.begin(), |
| 538 | m_include_directories.end())); |
| Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 539 | |
| Raphael Isemann | 5eb87cf | 2019-08-05 20:31:47 +0000 | [diff] [blame] | 540 | UpdateLanguageForExpr(); |
| Raphael Isemann | 9379d19 | 2019-09-24 10:08:18 +0000 | [diff] [blame] | 541 | CreateSourceCode(diagnostic_manager, exe_ctx, imported_modules, |
| 542 | for_completion); |
| Raphael Isemann | ba800e7d | 2018-07-10 22:12:39 +0000 | [diff] [blame] | 543 | return true; |
| 544 | } |
| 545 | |
| 546 | bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager, |
| 547 | ExecutionContext &exe_ctx, |
| 548 | lldb_private::ExecutionPolicy execution_policy, |
| 549 | bool keep_result_in_memory, |
| 550 | bool generate_debug_info) { |
| 551 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); |
| 552 | |
| Raphael Isemann | 71569d0 | 2019-05-02 10:12:56 +0000 | [diff] [blame] | 553 | if (!PrepareForParsing(diagnostic_manager, exe_ctx, /*for_completion*/ false)) |
| Raphael Isemann | ba800e7d | 2018-07-10 22:12:39 +0000 | [diff] [blame] | 554 | return false; |
| 555 | |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 556 | LLDB_LOGF(log, "Parsing the following code:\n%s", m_transformed_text.c_str()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 557 | |
| 558 | //////////////////////////////////// |
| 559 | // Set up the target and compiler |
| 560 | // |
| 561 | |
| 562 | Target *target = exe_ctx.GetTargetPtr(); |
| 563 | |
| 564 | if (!target) { |
| Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 565 | diagnostic_manager.PutString(eDiagnosticSeverityError, "invalid target"); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 566 | return false; |
| 567 | } |
| 568 | |
| 569 | ////////////////////////// |
| 570 | // Parse the expression |
| 571 | // |
| 572 | |
| Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 573 | m_materializer_up.reset(new Materializer()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 574 | |
| 575 | ResetDeclMap(exe_ctx, m_result_delegate, keep_result_in_memory); |
| 576 | |
| Tatyana Krasnukha | edebf12 | 2019-04-26 16:41:04 +0000 | [diff] [blame] | 577 | auto on_exit = llvm::make_scope_exit([this]() { ResetDeclMap(); }); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 578 | |
| Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 579 | if (!DeclMap()->WillParse(exe_ctx, m_materializer_up.get())) { |
| Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 580 | diagnostic_manager.PutString( |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 581 | eDiagnosticSeverityError, |
| 582 | "current process state is unsuitable for expression parsing"); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 583 | return false; |
| 584 | } |
| 585 | |
| 586 | if (m_options.GetExecutionPolicy() == eExecutionPolicyTopLevel) { |
| 587 | DeclMap()->SetLookupsEnabled(true); |
| 588 | } |
| 589 | |
| 590 | Process *process = exe_ctx.GetProcessPtr(); |
| 591 | ExecutionContextScope *exe_scope = process; |
| 592 | |
| 593 | if (!exe_scope) |
| 594 | exe_scope = exe_ctx.GetTargetPtr(); |
| 595 | |
| 596 | // We use a shared pointer here so we can use the original parser - if it |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 597 | // succeeds or the rewrite parser we might make if it fails. But the |
| 598 | // parser_sp will never be empty. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 599 | |
| Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 600 | ClangExpressionParser parser(exe_scope, *this, generate_debug_info, |
| Raphael Isemann | 1442efe | 2019-09-18 08:53:35 +0000 | [diff] [blame] | 601 | m_include_directories, m_filename); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 602 | |
| 603 | unsigned num_errors = parser.Parse(diagnostic_manager); |
| 604 | |
| 605 | // Check here for FixItHints. If there are any try to apply the fixits and |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 606 | // set the fixed text in m_fixed_text before returning an error. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 607 | if (num_errors) { |
| 608 | if (diagnostic_manager.HasFixIts()) { |
| 609 | if (parser.RewriteExpression(diagnostic_manager)) { |
| 610 | size_t fixed_start; |
| 611 | size_t fixed_end; |
| 612 | const std::string &fixed_expression = |
| 613 | diagnostic_manager.GetFixedExpression(); |
| Raphael Isemann | 06e98a8 | 2019-09-25 07:34:56 +0000 | [diff] [blame] | 614 | // Retrieve the original expression in case we don't have a top level |
| 615 | // expression (which has no surrounding source code). |
| 616 | if (m_source_code && |
| 617 | m_source_code->GetOriginalBodyBounds(fixed_expression, m_expr_lang, |
| Raphael Isemann | 1442efe | 2019-09-18 08:53:35 +0000 | [diff] [blame] | 618 | fixed_start, fixed_end)) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 619 | m_fixed_text = |
| 620 | fixed_expression.substr(fixed_start, fixed_end - fixed_start); |
| 621 | } |
| Sean Callanan | 9fda9d2 | 2015-10-03 09:09:01 +0000 | [diff] [blame] | 622 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 623 | return false; |
| 624 | } |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 625 | |
| Raphael Isemann | 54d99bf | 2019-04-24 12:21:03 +0000 | [diff] [blame] | 626 | ////////////////////////////////////////////////////////////////////////////// |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 627 | // Prepare the output of the parser for execution, evaluating it statically |
| 628 | // if possible |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 629 | // |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 630 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 631 | { |
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 632 | Status jit_error = parser.PrepareForExecution( |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 633 | m_jit_start_addr, m_jit_end_addr, m_execution_unit_sp, exe_ctx, |
| 634 | m_can_interpret, execution_policy); |
| Sean Callanan | fc55f5d | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 635 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 636 | if (!jit_error.Success()) { |
| 637 | const char *error_cstr = jit_error.AsCString(); |
| 638 | if (error_cstr && error_cstr[0]) |
| Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 639 | diagnostic_manager.PutString(eDiagnosticSeverityError, error_cstr); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 640 | else |
| Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 641 | diagnostic_manager.PutString(eDiagnosticSeverityError, |
| 642 | "expression can't be interpreted or run"); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 643 | return false; |
| 644 | } |
| 645 | } |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 646 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 647 | if (exe_ctx.GetProcessPtr() && execution_policy == eExecutionPolicyTopLevel) { |
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 648 | Status static_init_error = |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 649 | parser.RunStaticInitializers(m_execution_unit_sp, exe_ctx); |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 650 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 651 | if (!static_init_error.Success()) { |
| 652 | const char *error_cstr = static_init_error.AsCString(); |
| 653 | if (error_cstr && error_cstr[0]) |
| 654 | diagnostic_manager.Printf(eDiagnosticSeverityError, |
| 655 | "couldn't run static initializers: %s\n", |
| 656 | error_cstr); |
| 657 | else |
| Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 658 | diagnostic_manager.PutString(eDiagnosticSeverityError, |
| 659 | "couldn't run static initializers\n"); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 660 | return false; |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | if (m_execution_unit_sp) { |
| 665 | bool register_execution_unit = false; |
| 666 | |
| 667 | if (m_options.GetExecutionPolicy() == eExecutionPolicyTopLevel) { |
| 668 | register_execution_unit = true; |
| Sean Callanan | b995119 | 2011-08-01 18:18:33 +0000 | [diff] [blame] | 669 | } |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 670 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 671 | // If there is more than one external function in the execution unit, it |
| 672 | // needs to keep living even if it's not top level, because the result |
| 673 | // could refer to that function. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 674 | |
| 675 | if (m_execution_unit_sp->GetJittedFunctions().size() > 1) { |
| 676 | register_execution_unit = true; |
| Sean Callanan | 00294b3 | 2016-03-22 21:05:51 +0000 | [diff] [blame] | 677 | } |
| 678 | |
| Raphael Isemann | efe5fd1 | 2019-08-06 08:07:45 +0000 | [diff] [blame] | 679 | if (register_execution_unit) |
| 680 | exe_ctx.GetTargetPtr() |
| 681 | ->GetPersistentExpressionStateForLanguage(m_language) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 682 | ->RegisterExecutionUnit(m_execution_unit_sp); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 683 | } |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 684 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 685 | if (generate_debug_info) { |
| 686 | lldb::ModuleSP jit_module_sp(m_execution_unit_sp->GetJITModule()); |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 687 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 688 | if (jit_module_sp) { |
| 689 | ConstString const_func_name(FunctionName()); |
| 690 | FileSpec jit_file; |
| 691 | jit_file.GetFilename() = const_func_name; |
| 692 | jit_module_sp->SetFileSpecAndObjectName(jit_file, ConstString()); |
| 693 | m_jit_module_wp = jit_module_sp; |
| 694 | target->GetImages().Append(jit_module_sp); |
| Sean Callanan | 00294b3 | 2016-03-22 21:05:51 +0000 | [diff] [blame] | 695 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 696 | } |
| Sean Callanan | 00294b3 | 2016-03-22 21:05:51 +0000 | [diff] [blame] | 697 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 698 | if (process && m_jit_start_addr != LLDB_INVALID_ADDRESS) |
| 699 | m_jit_process_wp = lldb::ProcessWP(process->shared_from_this()); |
| 700 | return true; |
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 703 | /// Converts an absolute position inside a given code string into |
| 704 | /// a column/line pair. |
| 705 | /// |
| Adrian Prantl | f05b42e | 2019-03-11 17:09:29 +0000 | [diff] [blame] | 706 | /// \param[in] abs_pos |
| Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 707 | /// A absolute position in the code string that we want to convert |
| 708 | /// to a column/line pair. |
| 709 | /// |
| Adrian Prantl | f05b42e | 2019-03-11 17:09:29 +0000 | [diff] [blame] | 710 | /// \param[in] code |
| Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 711 | /// A multi-line string usually representing source code. |
| 712 | /// |
| Adrian Prantl | f05b42e | 2019-03-11 17:09:29 +0000 | [diff] [blame] | 713 | /// \param[out] line |
| Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 714 | /// The line in the code that contains the given absolute position. |
| 715 | /// The first line in the string is indexed as 1. |
| 716 | /// |
| Adrian Prantl | f05b42e | 2019-03-11 17:09:29 +0000 | [diff] [blame] | 717 | /// \param[out] column |
| Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 718 | /// The column in the line that contains the absolute position. |
| 719 | /// The first character in a line is indexed as 0. |
| Raphael Isemann | bfc5ef6 | 2018-09-22 13:33:08 +0000 | [diff] [blame] | 720 | static void AbsPosToLineColumnPos(size_t abs_pos, llvm::StringRef code, |
| Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 721 | unsigned &line, unsigned &column) { |
| 722 | // Reset to code position to beginning of the file. |
| 723 | line = 0; |
| 724 | column = 0; |
| 725 | |
| 726 | assert(abs_pos <= code.size() && "Absolute position outside code string?"); |
| 727 | |
| 728 | // We have to walk up to the position and count lines/columns. |
| 729 | for (std::size_t i = 0; i < abs_pos; ++i) { |
| 730 | // If we hit a line break, we go back to column 0 and enter a new line. |
| 731 | // We only handle \n because that's what we internally use to make new |
| 732 | // lines for our temporary code strings. |
| 733 | if (code[i] == '\n') { |
| 734 | ++line; |
| 735 | column = 0; |
| 736 | continue; |
| 737 | } |
| 738 | ++column; |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | bool ClangUserExpression::Complete(ExecutionContext &exe_ctx, |
| Raphael Isemann | c11a780 | 2018-08-30 21:26:32 +0000 | [diff] [blame] | 743 | CompletionRequest &request, |
| 744 | unsigned complete_pos) { |
| Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 745 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); |
| 746 | |
| 747 | // We don't want any visible feedback when completing an expression. Mostly |
| 748 | // because the results we get from an incomplete invocation are probably not |
| 749 | // correct. |
| 750 | DiagnosticManager diagnostic_manager; |
| 751 | |
| Raphael Isemann | 71569d0 | 2019-05-02 10:12:56 +0000 | [diff] [blame] | 752 | if (!PrepareForParsing(diagnostic_manager, exe_ctx, /*for_completion*/ true)) |
| Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 753 | return false; |
| 754 | |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 755 | LLDB_LOGF(log, "Parsing the following code:\n%s", m_transformed_text.c_str()); |
| Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 756 | |
| 757 | ////////////////////////// |
| 758 | // Parse the expression |
| 759 | // |
| 760 | |
| Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 761 | m_materializer_up.reset(new Materializer()); |
| Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 762 | |
| 763 | ResetDeclMap(exe_ctx, m_result_delegate, /*keep result in memory*/ true); |
| 764 | |
| Tatyana Krasnukha | edebf12 | 2019-04-26 16:41:04 +0000 | [diff] [blame] | 765 | auto on_exit = llvm::make_scope_exit([this]() { ResetDeclMap(); }); |
| Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 766 | |
| Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 767 | if (!DeclMap()->WillParse(exe_ctx, m_materializer_up.get())) { |
| Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 768 | diagnostic_manager.PutString( |
| 769 | eDiagnosticSeverityError, |
| 770 | "current process state is unsuitable for expression parsing"); |
| 771 | |
| 772 | return false; |
| 773 | } |
| 774 | |
| 775 | if (m_options.GetExecutionPolicy() == eExecutionPolicyTopLevel) { |
| 776 | DeclMap()->SetLookupsEnabled(true); |
| 777 | } |
| 778 | |
| 779 | Process *process = exe_ctx.GetProcessPtr(); |
| 780 | ExecutionContextScope *exe_scope = process; |
| 781 | |
| 782 | if (!exe_scope) |
| 783 | exe_scope = exe_ctx.GetTargetPtr(); |
| 784 | |
| 785 | ClangExpressionParser parser(exe_scope, *this, false); |
| 786 | |
| 787 | // We have to find the source code location where the user text is inside |
| 788 | // the transformed expression code. When creating the transformed text, we |
| 789 | // already stored the absolute position in the m_transformed_text string. The |
| 790 | // only thing left to do is to transform it into the line:column format that |
| 791 | // Clang expects. |
| 792 | |
| 793 | // The line and column of the user expression inside the transformed source |
| 794 | // code. |
| 795 | unsigned user_expr_line, user_expr_column; |
| 796 | if (m_user_expression_start_pos.hasValue()) |
| 797 | AbsPosToLineColumnPos(*m_user_expression_start_pos, m_transformed_text, |
| 798 | user_expr_line, user_expr_column); |
| 799 | else |
| 800 | return false; |
| 801 | |
| 802 | // The actual column where we have to complete is the start column of the |
| 803 | // user expression + the offset inside the user code that we were given. |
| 804 | const unsigned completion_column = user_expr_column + complete_pos; |
| Raphael Isemann | c11a780 | 2018-08-30 21:26:32 +0000 | [diff] [blame] | 805 | parser.Complete(request, user_expr_line, completion_column, complete_pos); |
| Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 806 | |
| 807 | return true; |
| 808 | } |
| 809 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 810 | bool ClangUserExpression::AddArguments(ExecutionContext &exe_ctx, |
| 811 | std::vector<lldb::addr_t> &args, |
| 812 | lldb::addr_t struct_address, |
| 813 | DiagnosticManager &diagnostic_manager) { |
| 814 | lldb::addr_t object_ptr = LLDB_INVALID_ADDRESS; |
| 815 | lldb::addr_t cmd_ptr = LLDB_INVALID_ADDRESS; |
| Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 816 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 817 | if (m_needs_object_ptr) { |
| 818 | lldb::StackFrameSP frame_sp = exe_ctx.GetFrameSP(); |
| 819 | if (!frame_sp) |
| 820 | return true; |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 821 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 822 | ConstString object_name; |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 823 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 824 | if (m_in_cplusplus_method) { |
| 825 | object_name.SetCString("this"); |
| 826 | } else if (m_in_objectivec_method) { |
| 827 | object_name.SetCString("self"); |
| 828 | } else { |
| Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 829 | diagnostic_manager.PutString( |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 830 | eDiagnosticSeverityError, |
| 831 | "need object pointer but don't know the language"); |
| 832 | return false; |
| Jim Ingham | 51148e9 | 2015-11-05 00:24:18 +0000 | [diff] [blame] | 833 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 834 | |
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 835 | Status object_ptr_error; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 836 | |
| Aleksandr Urakov | 40624a0 | 2019-02-05 09:14:36 +0000 | [diff] [blame] | 837 | if (m_ctx_obj) { |
| 838 | AddressType address_type; |
| 839 | object_ptr = m_ctx_obj->GetAddressOf(false, &address_type); |
| 840 | if (object_ptr == LLDB_INVALID_ADDRESS || |
| 841 | address_type != eAddressTypeLoad) |
| 842 | object_ptr_error.SetErrorString("Can't get context object's " |
| 843 | "debuggee address"); |
| 844 | } else |
| 845 | object_ptr = GetObjectPointer(frame_sp, object_name, object_ptr_error); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 846 | |
| 847 | if (!object_ptr_error.Success()) { |
| 848 | exe_ctx.GetTargetRef().GetDebugger().GetAsyncOutputStream()->Printf( |
| Jason Molenda | 599558e | 2017-02-21 05:09:26 +0000 | [diff] [blame] | 849 | "warning: `%s' is not accessible (substituting 0)\n", |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 850 | object_name.AsCString()); |
| 851 | object_ptr = 0; |
| Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 852 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 853 | |
| 854 | if (m_in_objectivec_method) { |
| 855 | ConstString cmd_name("_cmd"); |
| 856 | |
| 857 | cmd_ptr = GetObjectPointer(frame_sp, cmd_name, object_ptr_error); |
| 858 | |
| 859 | if (!object_ptr_error.Success()) { |
| 860 | diagnostic_manager.Printf( |
| 861 | eDiagnosticSeverityWarning, |
| 862 | "couldn't get cmd pointer (substituting NULL): %s", |
| 863 | object_ptr_error.AsCString()); |
| 864 | cmd_ptr = 0; |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | args.push_back(object_ptr); |
| 869 | |
| 870 | if (m_in_objectivec_method) |
| 871 | args.push_back(cmd_ptr); |
| 872 | |
| 873 | args.push_back(struct_address); |
| 874 | } else { |
| 875 | args.push_back(struct_address); |
| 876 | } |
| 877 | return true; |
| Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 878 | } |
| 879 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 880 | lldb::ExpressionVariableSP ClangUserExpression::GetResultAfterDematerialization( |
| 881 | ExecutionContextScope *exe_scope) { |
| 882 | return m_result_delegate.GetVariable(); |
| Sean Callanan | 9fda9d2 | 2015-10-03 09:09:01 +0000 | [diff] [blame] | 883 | } |
| 884 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 885 | void ClangUserExpression::ClangUserExpressionHelper::ResetDeclMap( |
| 886 | ExecutionContext &exe_ctx, |
| 887 | Materializer::PersistentVariableDelegate &delegate, |
| Aleksandr Urakov | 40624a0 | 2019-02-05 09:14:36 +0000 | [diff] [blame] | 888 | bool keep_result_in_memory, |
| 889 | ValueObject *ctx_obj) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 890 | m_expr_decl_map_up.reset( |
| Aleksandr Urakov | 40624a0 | 2019-02-05 09:14:36 +0000 | [diff] [blame] | 891 | new ClangExpressionDeclMap(keep_result_in_memory, &delegate, exe_ctx, |
| 892 | ctx_obj)); |
| Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 893 | } |
| Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 894 | |
| Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 895 | clang::ASTConsumer * |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 896 | ClangUserExpression::ClangUserExpressionHelper::ASTTransformer( |
| 897 | clang::ASTConsumer *passthrough) { |
| 898 | m_result_synthesizer_up.reset( |
| 899 | new ASTResultSynthesizer(passthrough, m_top_level, m_target)); |
| Sean Callanan | c673a6e | 2010-12-07 10:00:20 +0000 | [diff] [blame] | 900 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 901 | return m_result_synthesizer_up.get(); |
| Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 902 | } |
| 903 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 904 | void ClangUserExpression::ClangUserExpressionHelper::CommitPersistentDecls() { |
| Jonas Devlieghere | 70355ac | 2019-02-12 03:47:39 +0000 | [diff] [blame] | 905 | if (m_result_synthesizer_up) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 906 | m_result_synthesizer_up->CommitPersistentDecls(); |
| 907 | } |
| Sean Callanan | 00294b3 | 2016-03-22 21:05:51 +0000 | [diff] [blame] | 908 | } |
| 909 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 910 | ConstString ClangUserExpression::ResultDelegate::GetName() { |
| Adrian Prantl | 03219f7 | 2018-04-30 23:59:17 +0000 | [diff] [blame] | 911 | auto prefix = m_persistent_state->GetPersistentVariablePrefix(); |
| 912 | return m_persistent_state->GetNextPersistentVariableName(*m_target_sp, |
| 913 | prefix); |
| Sean Callanan | 9fda9d2 | 2015-10-03 09:09:01 +0000 | [diff] [blame] | 914 | } |
| 915 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 916 | void ClangUserExpression::ResultDelegate::DidDematerialize( |
| 917 | lldb::ExpressionVariableSP &variable) { |
| 918 | m_variable = variable; |
| Sean Callanan | 9fda9d2 | 2015-10-03 09:09:01 +0000 | [diff] [blame] | 919 | } |
| 920 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 921 | void ClangUserExpression::ResultDelegate::RegisterPersistentState( |
| 922 | PersistentExpressionState *persistent_state) { |
| 923 | m_persistent_state = persistent_state; |
| Sean Callanan | 9fda9d2 | 2015-10-03 09:09:01 +0000 | [diff] [blame] | 924 | } |
| 925 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 926 | lldb::ExpressionVariableSP &ClangUserExpression::ResultDelegate::GetVariable() { |
| 927 | return m_variable; |
| Sean Callanan | 9fda9d2 | 2015-10-03 09:09:01 +0000 | [diff] [blame] | 928 | } |