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