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 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 10 | #include <stdio.h> |
| 11 | #if HAVE_SYS_TYPES_H |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 12 | #include <sys/types.h> |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 13 | #endif |
| 14 | |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 15 | #include <cstdlib> |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 16 | #include <map> |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 17 | #include <string> |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 18 | |
Sean Callanan | 4dbb271 | 2015-09-25 20:35:58 +0000 | [diff] [blame] | 19 | #include "ClangUserExpression.h" |
| 20 | |
| 21 | #include "ASTResultSynthesizer.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 22 | #include "ClangDiagnostic.h" |
Sean Callanan | 4dbb271 | 2015-09-25 20:35:58 +0000 | [diff] [blame] | 23 | #include "ClangExpressionDeclMap.h" |
| 24 | #include "ClangExpressionParser.h" |
| 25 | #include "ClangModulesDeclVendor.h" |
| 26 | #include "ClangPersistentVariables.h" |
| 27 | |
Sean Callanan | bda7ef8 | 2016-06-22 17:32:17 +0000 | [diff] [blame] | 28 | #include "lldb/Core/Debugger.h" |
Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 29 | #include "lldb/Core/Module.h" |
Greg Clayton | c4e411f | 2011-01-18 19:36:39 +0000 | [diff] [blame] | 30 | #include "lldb/Core/StreamFile.h" |
Greg Clayton | b71f384 | 2010-10-05 03:13:51 +0000 | [diff] [blame] | 31 | #include "lldb/Core/ValueObjectConstResult.h" |
Sean Callanan | 9bc8384 | 2011-09-26 18:45:31 +0000 | [diff] [blame] | 32 | #include "lldb/Expression/ExpressionSourceCode.h" |
Sean Callanan | 14b1bae | 2013-04-16 23:25:35 +0000 | [diff] [blame] | 33 | #include "lldb/Expression/IRExecutionUnit.h" |
Sean Callanan | 1582ee6 | 2013-04-18 22:06:33 +0000 | [diff] [blame] | 34 | #include "lldb/Expression/IRInterpreter.h" |
Sean Callanan | 96d2730 | 2013-04-11 00:09:05 +0000 | [diff] [blame] | 35 | #include "lldb/Expression/Materializer.h" |
Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 36 | #include "lldb/Host/HostInfo.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 37 | #include "lldb/Symbol/Block.h" |
Jim Ingham | 5fdeed4 | 2012-10-30 23:35:54 +0000 | [diff] [blame] | 38 | #include "lldb/Symbol/ClangASTContext.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 39 | #include "lldb/Symbol/ClangExternalASTSourceCommon.h" |
Jim Ingham | 5fdeed4 | 2012-10-30 23:35:54 +0000 | [diff] [blame] | 40 | #include "lldb/Symbol/Function.h" |
Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 41 | #include "lldb/Symbol/ObjectFile.h" |
| 42 | #include "lldb/Symbol/SymbolVendor.h" |
Jim Ingham | 5fdeed4 | 2012-10-30 23:35:54 +0000 | [diff] [blame] | 43 | #include "lldb/Symbol/Type.h" |
Sean Callanan | fc55f5d | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 44 | #include "lldb/Symbol/VariableList.h" |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 45 | #include "lldb/Target/ExecutionContext.h" |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 46 | #include "lldb/Target/Process.h" |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 47 | #include "lldb/Target/StackFrame.h" |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 48 | #include "lldb/Target/Target.h" |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 49 | #include "lldb/Target/ThreadPlan.h" |
| 50 | #include "lldb/Target/ThreadPlanCallUserExpression.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 51 | #include "lldb/Utility/ConstString.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 52 | #include "lldb/Utility/Log.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 53 | #include "lldb/Utility/StreamString.h" |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 54 | |
Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 55 | #include "clang/AST/DeclCXX.h" |
| 56 | #include "clang/AST/DeclObjC.h" |
| 57 | |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 58 | using namespace lldb_private; |
| 59 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 60 | ClangUserExpression::ClangUserExpression( |
Zachary Turner | c5d7df9 | 2016-11-08 04:52:16 +0000 | [diff] [blame] | 61 | ExecutionContextScope &exe_scope, llvm::StringRef expr, |
| 62 | llvm::StringRef prefix, lldb::LanguageType language, |
| 63 | ResultType desired_type, const EvaluateExpressionOptions &options) |
| 64 | : LLVMUserExpression(exe_scope, expr, prefix, language, desired_type, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 65 | options), |
| 66 | m_type_system_helper(*m_target_wp.lock().get(), |
| 67 | options.GetExecutionPolicy() == |
Adrian Prantl | 5435f78 | 2018-04-30 23:59:15 +0000 | [diff] [blame^] | 68 | eExecutionPolicyTopLevel), |
| 69 | m_result_delegate(exe_scope.CalculateTarget()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 70 | switch (m_language) { |
| 71 | case lldb::eLanguageTypeC_plus_plus: |
| 72 | m_allow_cxx = true; |
| 73 | break; |
| 74 | case lldb::eLanguageTypeObjC: |
| 75 | m_allow_objc = true; |
| 76 | break; |
| 77 | case lldb::eLanguageTypeObjC_plus_plus: |
| 78 | default: |
| 79 | m_allow_cxx = true; |
| 80 | m_allow_objc = true; |
| 81 | break; |
| 82 | } |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 85 | ClangUserExpression::~ClangUserExpression() {} |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 86 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 87 | void ClangUserExpression::ScanContext(ExecutionContext &exe_ctx, Status &err) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 88 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | 7038508 | 2012-12-01 00:08:33 +0000 | [diff] [blame] | 89 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 90 | if (log) |
| 91 | log->Printf("ClangUserExpression::ScanContext()"); |
| 92 | |
| 93 | m_target = exe_ctx.GetTargetPtr(); |
| 94 | |
| 95 | if (!(m_allow_cxx || m_allow_objc)) { |
Sean Callanan | 7038508 | 2012-12-01 00:08:33 +0000 | [diff] [blame] | 96 | if (log) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 97 | log->Printf(" [CUE::SC] Settings inhibit C++ and Objective-C"); |
| 98 | return; |
| 99 | } |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 100 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 101 | StackFrame *frame = exe_ctx.GetFramePtr(); |
| 102 | if (frame == NULL) { |
| 103 | if (log) |
| 104 | log->Printf(" [CUE::SC] Null stack frame"); |
| 105 | return; |
| 106 | } |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 107 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 108 | SymbolContext sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction | |
| 109 | lldb::eSymbolContextBlock); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 110 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 111 | if (!sym_ctx.function) { |
| 112 | if (log) |
| 113 | log->Printf(" [CUE::SC] Null function"); |
| 114 | return; |
| 115 | } |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 116 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 117 | // Find the block that defines the function represented by "sym_ctx" |
| 118 | Block *function_block = sym_ctx.GetFunctionBlock(); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 119 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 120 | if (!function_block) { |
| 121 | if (log) |
| 122 | log->Printf(" [CUE::SC] Null function block"); |
| 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) { |
| 129 | if (log) |
| 130 | log->Printf(" [CUE::SC] Null decl context"); |
| 131 | return; |
| 132 | } |
Greg Clayton | 685c88c | 2012-07-14 00:53:55 +0000 | [diff] [blame] | 133 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 134 | if (clang::CXXMethodDecl *method_decl = |
| 135 | ClangASTContext::DeclContextGetAsCXXMethodDecl(decl_context)) { |
| 136 | if (m_allow_cxx && method_decl->isInstance()) { |
| 137 | if (m_enforce_valid_object) { |
| 138 | lldb::VariableListSP variable_list_sp( |
| 139 | function_block->GetBlockVariableList(true)); |
Greg Clayton | 685c88c | 2012-07-14 00:53:55 +0000 | [diff] [blame] | 140 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 141 | const char *thisErrorString = "Stopped in a C++ method, but 'this' " |
| 142 | "isn't available; pretending we are in a " |
| 143 | "generic context"; |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 144 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 145 | if (!variable_list_sp) { |
| 146 | err.SetErrorString(thisErrorString); |
| 147 | return; |
Sean Callanan | 3670ba5 | 2010-12-01 21:35:54 +0000 | [diff] [blame] | 148 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 149 | |
| 150 | lldb::VariableSP this_var_sp( |
| 151 | variable_list_sp->FindVariable(ConstString("this"))); |
| 152 | |
| 153 | if (!this_var_sp || !this_var_sp->IsInScope(frame) || |
| 154 | !this_var_sp->LocationIsValidForFrame(frame)) { |
| 155 | err.SetErrorString(thisErrorString); |
| 156 | return; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | m_in_cplusplus_method = true; |
| 161 | m_needs_object_ptr = true; |
Sean Callanan | 3670ba5 | 2010-12-01 21:35:54 +0000 | [diff] [blame] | 162 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 163 | } else if (clang::ObjCMethodDecl *method_decl = |
| 164 | ClangASTContext::DeclContextGetAsObjCMethodDecl( |
| 165 | decl_context)) { |
| 166 | if (m_allow_objc) { |
| 167 | if (m_enforce_valid_object) { |
| 168 | lldb::VariableListSP variable_list_sp( |
| 169 | function_block->GetBlockVariableList(true)); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 170 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 171 | const char *selfErrorString = "Stopped in an Objective-C method, but " |
| 172 | "'self' isn't available; pretending we " |
| 173 | "are in a generic context"; |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 174 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 175 | if (!variable_list_sp) { |
| 176 | err.SetErrorString(selfErrorString); |
| 177 | return; |
| 178 | } |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 179 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 180 | lldb::VariableSP self_variable_sp = |
| 181 | variable_list_sp->FindVariable(ConstString("self")); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 182 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 183 | if (!self_variable_sp || !self_variable_sp->IsInScope(frame) || |
| 184 | !self_variable_sp->LocationIsValidForFrame(frame)) { |
| 185 | err.SetErrorString(selfErrorString); |
| 186 | return; |
| 187 | } |
| 188 | } |
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 | m_in_objectivec_method = true; |
| 191 | m_needs_object_ptr = true; |
| 192 | |
| 193 | if (!method_decl->isInstanceMethod()) |
| 194 | m_in_static_method = true; |
| 195 | } |
| 196 | } else if (clang::FunctionDecl *function_decl = |
| 197 | ClangASTContext::DeclContextGetAsFunctionDecl(decl_context)) { |
| 198 | // 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] | 199 | // captured an object pointer. The best way to deal with getting to the |
| 200 | // ivars at present is by pretending that this is a method of a class in |
| 201 | // whatever runtime the debug info says the object pointer belongs to. Do |
| 202 | // that here. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 203 | |
| 204 | ClangASTMetadata *metadata = |
| 205 | ClangASTContext::DeclContextGetMetaData(decl_context, function_decl); |
| 206 | if (metadata && metadata->HasObjectPtr()) { |
| 207 | lldb::LanguageType language = metadata->GetObjectPtrLanguage(); |
| 208 | if (language == lldb::eLanguageTypeC_plus_plus) { |
| 209 | if (m_enforce_valid_object) { |
| 210 | lldb::VariableListSP variable_list_sp( |
| 211 | function_block->GetBlockVariableList(true)); |
| 212 | |
| 213 | const char *thisErrorString = "Stopped in a context claiming to " |
| 214 | "capture a C++ object pointer, but " |
| 215 | "'this' isn't available; pretending we " |
| 216 | "are in a generic context"; |
| 217 | |
| 218 | if (!variable_list_sp) { |
| 219 | err.SetErrorString(thisErrorString); |
| 220 | return; |
| 221 | } |
| 222 | |
| 223 | lldb::VariableSP this_var_sp( |
| 224 | variable_list_sp->FindVariable(ConstString("this"))); |
| 225 | |
| 226 | if (!this_var_sp || !this_var_sp->IsInScope(frame) || |
| 227 | !this_var_sp->LocationIsValidForFrame(frame)) { |
| 228 | err.SetErrorString(thisErrorString); |
| 229 | return; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | m_in_cplusplus_method = true; |
| 234 | m_needs_object_ptr = true; |
| 235 | } else if (language == lldb::eLanguageTypeObjC) { |
| 236 | if (m_enforce_valid_object) { |
| 237 | lldb::VariableListSP variable_list_sp( |
| 238 | function_block->GetBlockVariableList(true)); |
| 239 | |
| 240 | const char *selfErrorString = |
| 241 | "Stopped in a context claiming to capture an Objective-C object " |
| 242 | "pointer, but 'self' isn't available; pretending we are in a " |
| 243 | "generic context"; |
| 244 | |
| 245 | if (!variable_list_sp) { |
| 246 | err.SetErrorString(selfErrorString); |
| 247 | return; |
| 248 | } |
| 249 | |
| 250 | lldb::VariableSP self_variable_sp = |
| 251 | variable_list_sp->FindVariable(ConstString("self")); |
| 252 | |
| 253 | if (!self_variable_sp || !self_variable_sp->IsInScope(frame) || |
| 254 | !self_variable_sp->LocationIsValidForFrame(frame)) { |
| 255 | err.SetErrorString(selfErrorString); |
| 256 | return; |
| 257 | } |
| 258 | |
| 259 | Type *self_type = self_variable_sp->GetType(); |
| 260 | |
| 261 | if (!self_type) { |
| 262 | err.SetErrorString(selfErrorString); |
| 263 | return; |
| 264 | } |
| 265 | |
| 266 | CompilerType self_clang_type = self_type->GetForwardCompilerType(); |
| 267 | |
| 268 | if (!self_clang_type) { |
| 269 | err.SetErrorString(selfErrorString); |
| 270 | return; |
| 271 | } |
| 272 | |
| 273 | if (ClangASTContext::IsObjCClassType(self_clang_type)) { |
| 274 | return; |
| 275 | } else if (ClangASTContext::IsObjCObjectPointerType( |
| 276 | self_clang_type)) { |
Dawn Perchik | 53f34c8 | 2015-07-01 00:54:02 +0000 | [diff] [blame] | 277 | m_in_objectivec_method = true; |
Sean Callanan | 9bc8384 | 2011-09-26 18:45:31 +0000 | [diff] [blame] | 278 | m_needs_object_ptr = true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 279 | } else { |
| 280 | err.SetErrorString(selfErrorString); |
| 281 | return; |
| 282 | } |
| 283 | } else { |
| 284 | m_in_objectivec_method = true; |
| 285 | m_needs_object_ptr = true; |
Sean Callanan | 9bc8384 | 2011-09-26 18:45:31 +0000 | [diff] [blame] | 286 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 287 | } |
Sean Callanan | 3670ba5 | 2010-12-01 21:35:54 +0000 | [diff] [blame] | 288 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 289 | } |
Sean Callanan | fc55f5d | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 292 | // This is a really nasty hack, meant to fix Objective-C expressions of the |
| 293 | // form (int)[myArray count]. Right now, because the type information for |
| 294 | // count is not available, [myArray count] returns id, which can't be directly |
| 295 | // cast to int without causing a clang error. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 296 | static void ApplyObjcCastHack(std::string &expr) { |
Sean Callanan | cf5498f | 2010-10-22 23:25:16 +0000 | [diff] [blame] | 297 | #define OBJC_CAST_HACK_FROM "(int)[" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 298 | #define OBJC_CAST_HACK_TO "(int)(long long)[" |
Sean Callanan | cf5498f | 2010-10-22 23:25:16 +0000 | [diff] [blame] | 299 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 300 | size_t from_offset; |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 301 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 302 | while ((from_offset = expr.find(OBJC_CAST_HACK_FROM)) != expr.npos) |
| 303 | expr.replace(from_offset, sizeof(OBJC_CAST_HACK_FROM) - 1, |
| 304 | OBJC_CAST_HACK_TO); |
Sean Callanan | cf5498f | 2010-10-22 23:25:16 +0000 | [diff] [blame] | 305 | |
| 306 | #undef OBJC_CAST_HACK_TO |
| 307 | #undef OBJC_CAST_HACK_FROM |
| 308 | } |
| 309 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 310 | bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager, |
| 311 | ExecutionContext &exe_ctx, |
| 312 | lldb_private::ExecutionPolicy execution_policy, |
| 313 | bool keep_result_in_memory, |
| 314 | bool generate_debug_info) { |
| 315 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 316 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 317 | Status err; |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 318 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 319 | InstallContext(exe_ctx); |
| 320 | |
| 321 | if (Target *target = exe_ctx.GetTargetPtr()) { |
| 322 | if (PersistentExpressionState *persistent_state = |
| 323 | target->GetPersistentExpressionStateForLanguage( |
| 324 | lldb::eLanguageTypeC)) { |
| 325 | m_result_delegate.RegisterPersistentState(persistent_state); |
| 326 | } else { |
Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 327 | diagnostic_manager.PutString( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 328 | eDiagnosticSeverityError, |
| 329 | "couldn't start parsing (no persistent data)"); |
| 330 | return false; |
Sean Callanan | 9fda9d2 | 2015-10-03 09:09:01 +0000 | [diff] [blame] | 331 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 332 | } else { |
Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 333 | diagnostic_manager.PutString(eDiagnosticSeverityError, |
| 334 | "error: couldn't start parsing (no target)"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 335 | return false; |
| 336 | } |
| 337 | |
| 338 | ScanContext(exe_ctx, err); |
| 339 | |
| 340 | if (!err.Success()) { |
Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 341 | diagnostic_manager.PutString(eDiagnosticSeverityWarning, err.AsCString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | //////////////////////////////////// |
| 345 | // Generate the expression |
| 346 | // |
| 347 | |
| 348 | ApplyObjcCastHack(m_expr_text); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 349 | |
| 350 | std::string prefix = m_expr_prefix; |
| 351 | |
| 352 | if (ClangModulesDeclVendor *decl_vendor = |
| 353 | m_target->GetClangModulesDeclVendor()) { |
| 354 | const ClangModulesDeclVendor::ModuleVector &hand_imported_modules = |
| 355 | llvm::cast<ClangPersistentVariables>( |
| 356 | m_target->GetPersistentExpressionStateForLanguage( |
| 357 | lldb::eLanguageTypeC)) |
| 358 | ->GetHandLoadedClangModules(); |
| 359 | ClangModulesDeclVendor::ModuleVector modules_for_macros; |
| 360 | |
| 361 | for (ClangModulesDeclVendor::ModuleID module : hand_imported_modules) { |
| 362 | modules_for_macros.push_back(module); |
| 363 | } |
| 364 | |
| 365 | if (m_target->GetEnableAutoImportClangModules()) { |
| 366 | if (StackFrame *frame = exe_ctx.GetFramePtr()) { |
| 367 | if (Block *block = frame->GetFrameBlock()) { |
| 368 | SymbolContext sc; |
| 369 | |
| 370 | block->CalculateSymbolContext(&sc); |
| 371 | |
| 372 | if (sc.comp_unit) { |
| 373 | StreamString error_stream; |
| 374 | |
| 375 | decl_vendor->AddModulesForCompileUnit( |
| 376 | *sc.comp_unit, modules_for_macros, error_stream); |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | lldb::LanguageType lang_type = lldb::eLanguageTypeUnknown; |
| 384 | |
| 385 | if (m_options.GetExecutionPolicy() == eExecutionPolicyTopLevel) { |
| 386 | m_transformed_text = m_expr_text; |
| 387 | } else { |
| 388 | std::unique_ptr<ExpressionSourceCode> source_code( |
| 389 | ExpressionSourceCode::CreateWrapped(prefix.c_str(), |
| 390 | m_expr_text.c_str())); |
| 391 | |
| 392 | if (m_in_cplusplus_method) |
| 393 | lang_type = lldb::eLanguageTypeC_plus_plus; |
| 394 | else if (m_in_objectivec_method) |
| 395 | lang_type = lldb::eLanguageTypeObjC; |
Sean Callanan | 9fda9d2 | 2015-10-03 09:09:01 +0000 | [diff] [blame] | 396 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 397 | lang_type = lldb::eLanguageTypeC; |
| 398 | |
| 399 | if (!source_code->GetText(m_transformed_text, lang_type, m_in_static_method, |
| 400 | exe_ctx)) { |
Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 401 | diagnostic_manager.PutString(eDiagnosticSeverityError, |
| 402 | "couldn't construct expression body"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 403 | return false; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | if (log) |
| 408 | log->Printf("Parsing the following code:\n%s", m_transformed_text.c_str()); |
| 409 | |
| 410 | //////////////////////////////////// |
| 411 | // Set up the target and compiler |
| 412 | // |
| 413 | |
| 414 | Target *target = exe_ctx.GetTargetPtr(); |
| 415 | |
| 416 | if (!target) { |
Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 417 | diagnostic_manager.PutString(eDiagnosticSeverityError, "invalid target"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 418 | return false; |
| 419 | } |
| 420 | |
| 421 | ////////////////////////// |
| 422 | // Parse the expression |
| 423 | // |
| 424 | |
| 425 | m_materializer_ap.reset(new Materializer()); |
| 426 | |
| 427 | ResetDeclMap(exe_ctx, m_result_delegate, keep_result_in_memory); |
| 428 | |
| 429 | class OnExit { |
| 430 | public: |
| 431 | typedef std::function<void(void)> Callback; |
| 432 | |
| 433 | OnExit(Callback const &callback) : m_callback(callback) {} |
| 434 | |
| 435 | ~OnExit() { m_callback(); } |
| 436 | |
| 437 | private: |
| 438 | Callback m_callback; |
| 439 | }; |
| 440 | |
| 441 | OnExit on_exit([this]() { ResetDeclMap(); }); |
| 442 | |
| 443 | if (!DeclMap()->WillParse(exe_ctx, m_materializer_ap.get())) { |
Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 444 | diagnostic_manager.PutString( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 445 | eDiagnosticSeverityError, |
| 446 | "current process state is unsuitable for expression parsing"); |
| 447 | |
| 448 | ResetDeclMap(); // We are being careful here in the case of breakpoint |
| 449 | // conditions. |
| 450 | |
| 451 | return false; |
| 452 | } |
| 453 | |
| 454 | if (m_options.GetExecutionPolicy() == eExecutionPolicyTopLevel) { |
| 455 | DeclMap()->SetLookupsEnabled(true); |
| 456 | } |
| 457 | |
| 458 | Process *process = exe_ctx.GetProcessPtr(); |
| 459 | ExecutionContextScope *exe_scope = process; |
| 460 | |
| 461 | if (!exe_scope) |
| 462 | exe_scope = exe_ctx.GetTargetPtr(); |
| 463 | |
| 464 | // 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] | 465 | // succeeds or the rewrite parser we might make if it fails. But the |
| 466 | // parser_sp will never be empty. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 467 | |
| 468 | ClangExpressionParser parser(exe_scope, *this, generate_debug_info); |
| 469 | |
| 470 | unsigned num_errors = parser.Parse(diagnostic_manager); |
| 471 | |
| 472 | // 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] | 473 | // set the fixed text in m_fixed_text before returning an error. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 474 | if (num_errors) { |
| 475 | if (diagnostic_manager.HasFixIts()) { |
| 476 | if (parser.RewriteExpression(diagnostic_manager)) { |
| 477 | size_t fixed_start; |
| 478 | size_t fixed_end; |
| 479 | const std::string &fixed_expression = |
| 480 | diagnostic_manager.GetFixedExpression(); |
| 481 | if (ExpressionSourceCode::GetOriginalBodyBounds( |
| 482 | fixed_expression, lang_type, fixed_start, fixed_end)) |
| 483 | m_fixed_text = |
| 484 | fixed_expression.substr(fixed_start, fixed_end - fixed_start); |
| 485 | } |
Sean Callanan | 9fda9d2 | 2015-10-03 09:09:01 +0000 | [diff] [blame] | 486 | } |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 487 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 488 | ResetDeclMap(); // We are being careful here in the case of breakpoint |
| 489 | // conditions. |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 490 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 491 | return false; |
| 492 | } |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 493 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 494 | ////////////////////////////////////////////////////////////////////////////////////////// |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 495 | // Prepare the output of the parser for execution, evaluating it statically |
| 496 | // if possible |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 497 | // |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 498 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 499 | { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 500 | Status jit_error = parser.PrepareForExecution( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 501 | m_jit_start_addr, m_jit_end_addr, m_execution_unit_sp, exe_ctx, |
| 502 | m_can_interpret, execution_policy); |
Sean Callanan | fc55f5d | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 503 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 504 | if (!jit_error.Success()) { |
| 505 | const char *error_cstr = jit_error.AsCString(); |
| 506 | if (error_cstr && error_cstr[0]) |
Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 507 | diagnostic_manager.PutString(eDiagnosticSeverityError, error_cstr); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 508 | else |
Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 509 | diagnostic_manager.PutString(eDiagnosticSeverityError, |
| 510 | "expression can't be interpreted or run"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 511 | return false; |
| 512 | } |
| 513 | } |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 514 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 515 | if (exe_ctx.GetProcessPtr() && execution_policy == eExecutionPolicyTopLevel) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 516 | Status static_init_error = |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 517 | parser.RunStaticInitializers(m_execution_unit_sp, exe_ctx); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 518 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 519 | if (!static_init_error.Success()) { |
| 520 | const char *error_cstr = static_init_error.AsCString(); |
| 521 | if (error_cstr && error_cstr[0]) |
| 522 | diagnostic_manager.Printf(eDiagnosticSeverityError, |
| 523 | "couldn't run static initializers: %s\n", |
| 524 | error_cstr); |
| 525 | else |
Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 526 | diagnostic_manager.PutString(eDiagnosticSeverityError, |
| 527 | "couldn't run static initializers\n"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 528 | return false; |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | if (m_execution_unit_sp) { |
| 533 | bool register_execution_unit = false; |
| 534 | |
| 535 | if (m_options.GetExecutionPolicy() == eExecutionPolicyTopLevel) { |
| 536 | register_execution_unit = true; |
Sean Callanan | b995119 | 2011-08-01 18:18:33 +0000 | [diff] [blame] | 537 | } |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 538 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 539 | // If there is more than one external function in the execution unit, it |
| 540 | // needs to keep living even if it's not top level, because the result |
| 541 | // could refer to that function. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 542 | |
| 543 | if (m_execution_unit_sp->GetJittedFunctions().size() > 1) { |
| 544 | register_execution_unit = true; |
Sean Callanan | 00294b3 | 2016-03-22 21:05:51 +0000 | [diff] [blame] | 545 | } |
| 546 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 547 | if (register_execution_unit) { |
| 548 | llvm::cast<PersistentExpressionState>( |
| 549 | exe_ctx.GetTargetPtr()->GetPersistentExpressionStateForLanguage( |
| 550 | m_language)) |
| 551 | ->RegisterExecutionUnit(m_execution_unit_sp); |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 552 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 553 | } |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 554 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 555 | if (generate_debug_info) { |
| 556 | lldb::ModuleSP jit_module_sp(m_execution_unit_sp->GetJITModule()); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 557 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 558 | if (jit_module_sp) { |
| 559 | ConstString const_func_name(FunctionName()); |
| 560 | FileSpec jit_file; |
| 561 | jit_file.GetFilename() = const_func_name; |
| 562 | jit_module_sp->SetFileSpecAndObjectName(jit_file, ConstString()); |
| 563 | m_jit_module_wp = jit_module_sp; |
| 564 | target->GetImages().Append(jit_module_sp); |
Sean Callanan | 00294b3 | 2016-03-22 21:05:51 +0000 | [diff] [blame] | 565 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 566 | } |
Sean Callanan | 00294b3 | 2016-03-22 21:05:51 +0000 | [diff] [blame] | 567 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 568 | ResetDeclMap(); // Make this go away since we don't need any of its state |
| 569 | // after parsing. This also gets rid of any |
| 570 | // ClangASTImporter::Minions. |
Sean Callanan | 00294b3 | 2016-03-22 21:05:51 +0000 | [diff] [blame] | 571 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 572 | if (process && m_jit_start_addr != LLDB_INVALID_ADDRESS) |
| 573 | m_jit_process_wp = lldb::ProcessWP(process->shared_from_this()); |
| 574 | return true; |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 577 | bool ClangUserExpression::AddArguments(ExecutionContext &exe_ctx, |
| 578 | std::vector<lldb::addr_t> &args, |
| 579 | lldb::addr_t struct_address, |
| 580 | DiagnosticManager &diagnostic_manager) { |
| 581 | lldb::addr_t object_ptr = LLDB_INVALID_ADDRESS; |
| 582 | lldb::addr_t cmd_ptr = LLDB_INVALID_ADDRESS; |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 583 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 584 | if (m_needs_object_ptr) { |
| 585 | lldb::StackFrameSP frame_sp = exe_ctx.GetFrameSP(); |
| 586 | if (!frame_sp) |
| 587 | return true; |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 588 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 589 | ConstString object_name; |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 590 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 591 | if (m_in_cplusplus_method) { |
| 592 | object_name.SetCString("this"); |
| 593 | } else if (m_in_objectivec_method) { |
| 594 | object_name.SetCString("self"); |
| 595 | } else { |
Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 596 | diagnostic_manager.PutString( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 597 | eDiagnosticSeverityError, |
| 598 | "need object pointer but don't know the language"); |
| 599 | return false; |
Jim Ingham | 51148e9 | 2015-11-05 00:24:18 +0000 | [diff] [blame] | 600 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 601 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 602 | Status object_ptr_error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 603 | |
| 604 | object_ptr = GetObjectPointer(frame_sp, object_name, object_ptr_error); |
| 605 | |
| 606 | if (!object_ptr_error.Success()) { |
| 607 | exe_ctx.GetTargetRef().GetDebugger().GetAsyncOutputStream()->Printf( |
Jason Molenda | 599558e | 2017-02-21 05:09:26 +0000 | [diff] [blame] | 608 | "warning: `%s' is not accessible (substituting 0)\n", |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 609 | object_name.AsCString()); |
| 610 | object_ptr = 0; |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 611 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 612 | |
| 613 | if (m_in_objectivec_method) { |
| 614 | ConstString cmd_name("_cmd"); |
| 615 | |
| 616 | cmd_ptr = GetObjectPointer(frame_sp, cmd_name, object_ptr_error); |
| 617 | |
| 618 | if (!object_ptr_error.Success()) { |
| 619 | diagnostic_manager.Printf( |
| 620 | eDiagnosticSeverityWarning, |
| 621 | "couldn't get cmd pointer (substituting NULL): %s", |
| 622 | object_ptr_error.AsCString()); |
| 623 | cmd_ptr = 0; |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | args.push_back(object_ptr); |
| 628 | |
| 629 | if (m_in_objectivec_method) |
| 630 | args.push_back(cmd_ptr); |
| 631 | |
| 632 | args.push_back(struct_address); |
| 633 | } else { |
| 634 | args.push_back(struct_address); |
| 635 | } |
| 636 | return true; |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 637 | } |
| 638 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 639 | lldb::ExpressionVariableSP ClangUserExpression::GetResultAfterDematerialization( |
| 640 | ExecutionContextScope *exe_scope) { |
| 641 | return m_result_delegate.GetVariable(); |
Sean Callanan | 9fda9d2 | 2015-10-03 09:09:01 +0000 | [diff] [blame] | 642 | } |
| 643 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 644 | void ClangUserExpression::ClangUserExpressionHelper::ResetDeclMap( |
| 645 | ExecutionContext &exe_ctx, |
| 646 | Materializer::PersistentVariableDelegate &delegate, |
| 647 | bool keep_result_in_memory) { |
| 648 | m_expr_decl_map_up.reset( |
| 649 | new ClangExpressionDeclMap(keep_result_in_memory, &delegate, exe_ctx)); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 650 | } |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 651 | |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 652 | clang::ASTConsumer * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 653 | ClangUserExpression::ClangUserExpressionHelper::ASTTransformer( |
| 654 | clang::ASTConsumer *passthrough) { |
| 655 | m_result_synthesizer_up.reset( |
| 656 | new ASTResultSynthesizer(passthrough, m_top_level, m_target)); |
Sean Callanan | c673a6e | 2010-12-07 10:00:20 +0000 | [diff] [blame] | 657 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 658 | return m_result_synthesizer_up.get(); |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 659 | } |
| 660 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 661 | void ClangUserExpression::ClangUserExpressionHelper::CommitPersistentDecls() { |
| 662 | if (m_result_synthesizer_up.get()) { |
| 663 | m_result_synthesizer_up->CommitPersistentDecls(); |
| 664 | } |
Sean Callanan | 00294b3 | 2016-03-22 21:05:51 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 667 | ConstString ClangUserExpression::ResultDelegate::GetName() { |
Adrian Prantl | 5435f78 | 2018-04-30 23:59:15 +0000 | [diff] [blame^] | 668 | return m_persistent_state->GetNextPersistentVariableName(*m_target_sp); |
Sean Callanan | 9fda9d2 | 2015-10-03 09:09:01 +0000 | [diff] [blame] | 669 | } |
| 670 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 671 | void ClangUserExpression::ResultDelegate::DidDematerialize( |
| 672 | lldb::ExpressionVariableSP &variable) { |
| 673 | m_variable = variable; |
Sean Callanan | 9fda9d2 | 2015-10-03 09:09:01 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 676 | void ClangUserExpression::ResultDelegate::RegisterPersistentState( |
| 677 | PersistentExpressionState *persistent_state) { |
| 678 | m_persistent_state = persistent_state; |
Sean Callanan | 9fda9d2 | 2015-10-03 09:09:01 +0000 | [diff] [blame] | 679 | } |
| 680 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 681 | lldb::ExpressionVariableSP &ClangUserExpression::ResultDelegate::GetVariable() { |
| 682 | return m_variable; |
Sean Callanan | 9fda9d2 | 2015-10-03 09:09:01 +0000 | [diff] [blame] | 683 | } |