1 //===-- ClangExpressionParser.cpp -------------------------------*- C++ -*-===// 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 10 #include "ClangExpressionParser.h" 11 12 #include "ClangASTSource.h" 13 #include "ClangExpressionHelper.h" 14 #include "ClangExpressionDeclMap.h" 15 #include "ClangModulesDeclVendor.h" 16 #include "ClangPersistentVariables.h" 17 #include "IRForTarget.h" 18 19 #include "lldb/Core/ArchSpec.h" 20 #include "lldb/Core/DataBufferHeap.h" 21 #include "lldb/Core/Debugger.h" 22 #include "lldb/Core/Disassembler.h" 23 #include "lldb/Core/Log.h" 24 #include "lldb/Core/Module.h" 25 #include "lldb/Core/Stream.h" 26 #include "lldb/Core/StreamFile.h" 27 #include "lldb/Core/StreamString.h" 28 #include "lldb/Expression/IRExecutionUnit.h" 29 #include "lldb/Expression/IRDynamicChecks.h" 30 #include "lldb/Expression/IRInterpreter.h" 31 #include "lldb/Host/File.h" 32 #include "lldb/Host/HostInfo.h" 33 #include "lldb/Symbol/ClangASTContext.h" 34 #include "lldb/Symbol/SymbolVendor.h" 35 #include "lldb/Target/ExecutionContext.h" 36 #include "lldb/Target/ObjCLanguageRuntime.h" 37 #include "lldb/Target/Process.h" 38 #include "lldb/Target/Target.h" 39 40 #include "clang/AST/ASTContext.h" 41 #include "clang/AST/ExternalASTSource.h" 42 #include "clang/Basic/FileManager.h" 43 #include "clang/Basic/SourceLocation.h" 44 #include "clang/Basic/TargetInfo.h" 45 #include "clang/Basic/Version.h" 46 #include "clang/CodeGen/CodeGenAction.h" 47 #include "clang/CodeGen/ModuleBuilder.h" 48 #include "clang/Frontend/CompilerInstance.h" 49 #include "clang/Frontend/CompilerInvocation.h" 50 #include "clang/Frontend/FrontendActions.h" 51 #include "clang/Frontend/FrontendDiagnostic.h" 52 #include "clang/Frontend/FrontendPluginRegistry.h" 53 #include "clang/Frontend/TextDiagnosticBuffer.h" 54 #include "clang/Frontend/TextDiagnosticPrinter.h" 55 #include "clang/Lex/Preprocessor.h" 56 #include "clang/Parse/ParseAST.h" 57 #include "clang/Rewrite/Frontend/FrontendActions.h" 58 #include "clang/Sema/SemaConsumer.h" 59 #include "clang/StaticAnalyzer/Frontend/FrontendActions.h" 60 61 #include "llvm/ADT/StringRef.h" 62 #include "llvm/ExecutionEngine/ExecutionEngine.h" 63 #include "llvm/Support/Debug.h" 64 #include "llvm/Support/FileSystem.h" 65 #include "llvm/Support/TargetSelect.h" 66 67 #include "llvm/ExecutionEngine/MCJIT.h" 68 #include "llvm/IR/LLVMContext.h" 69 #include "llvm/IR/Module.h" 70 #include "llvm/Support/ErrorHandling.h" 71 #include "llvm/Support/MemoryBuffer.h" 72 #include "llvm/Support/DynamicLibrary.h" 73 #include "llvm/Support/Host.h" 74 #include "llvm/Support/Signals.h" 75 76 using namespace clang; 77 using namespace llvm; 78 using namespace lldb_private; 79 80 //===----------------------------------------------------------------------===// 81 // Utility Methods for Clang 82 //===----------------------------------------------------------------------===// 83 84 std::string GetBuiltinIncludePath(const char *Argv0) { 85 SmallString<128> P(llvm::sys::fs::getMainExecutable( 86 Argv0, (void *)(intptr_t) GetBuiltinIncludePath)); 87 88 if (!P.empty()) { 89 llvm::sys::path::remove_filename(P); // Remove /clang from foo/bin/clang 90 llvm::sys::path::remove_filename(P); // Remove /bin from foo/bin 91 92 // Get foo/lib/clang/<version>/include 93 llvm::sys::path::append(P, "lib", "clang", CLANG_VERSION_STRING, 94 "include"); 95 } 96 97 return P.str(); 98 } 99 100 class ClangExpressionParser::LLDBPreprocessorCallbacks : public PPCallbacks 101 { 102 ClangModulesDeclVendor &m_decl_vendor; 103 ClangPersistentVariables &m_persistent_vars; 104 StreamString m_error_stream; 105 bool m_has_errors = false; 106 public: 107 LLDBPreprocessorCallbacks(ClangModulesDeclVendor &decl_vendor, 108 ClangPersistentVariables &persistent_vars) : 109 m_decl_vendor(decl_vendor), 110 m_persistent_vars(persistent_vars) 111 { 112 } 113 114 virtual void moduleImport(SourceLocation import_location, 115 clang::ModuleIdPath path, 116 const clang::Module * /*null*/) 117 { 118 std::vector<ConstString> string_path; 119 120 for (const std::pair<IdentifierInfo *, SourceLocation> &component : path) 121 { 122 string_path.push_back(ConstString(component.first->getName())); 123 } 124 125 StreamString error_stream; 126 127 ClangModulesDeclVendor::ModuleVector exported_modules; 128 129 if (!m_decl_vendor.AddModule(string_path, &exported_modules, m_error_stream)) 130 { 131 m_has_errors = true; 132 } 133 134 for (ClangModulesDeclVendor::ModuleID module : exported_modules) 135 { 136 m_persistent_vars.AddHandLoadedClangModule(module); 137 } 138 } 139 140 bool hasErrors() 141 { 142 return m_has_errors; 143 } 144 145 const std::string &getErrorString() 146 { 147 return m_error_stream.GetString(); 148 } 149 }; 150 151 //===----------------------------------------------------------------------===// 152 // Implementation of ClangExpressionParser 153 //===----------------------------------------------------------------------===// 154 155 ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope, 156 Expression &expr, 157 bool generate_debug_info) : 158 ExpressionParser (exe_scope, expr, generate_debug_info), 159 m_compiler (), 160 m_code_generator (), 161 m_pp_callbacks(nullptr) 162 { 163 // 1. Create a new compiler instance. 164 m_compiler.reset(new CompilerInstance()); 165 166 // 2. Install the target. 167 168 lldb::TargetSP target_sp; 169 if (exe_scope) 170 target_sp = exe_scope->CalculateTarget(); 171 172 // TODO: figure out what to really do when we don't have a valid target. 173 // Sometimes this will be ok to just use the host target triple (when we 174 // evaluate say "2+3", but other expressions like breakpoint conditions 175 // and other things that _are_ target specific really shouldn't just be 176 // using the host triple. This needs to be fixed in a better way. 177 if (target_sp && target_sp->GetArchitecture().IsValid()) 178 { 179 std::string triple = target_sp->GetArchitecture().GetTriple().str(); 180 m_compiler->getTargetOpts().Triple = triple; 181 } 182 else 183 { 184 m_compiler->getTargetOpts().Triple = llvm::sys::getDefaultTargetTriple(); 185 } 186 187 if (target_sp->GetArchitecture().GetMachine() == llvm::Triple::x86 || 188 target_sp->GetArchitecture().GetMachine() == llvm::Triple::x86_64) 189 { 190 m_compiler->getTargetOpts().Features.push_back("+sse"); 191 m_compiler->getTargetOpts().Features.push_back("+sse2"); 192 } 193 194 // Any arm32 iOS environment, but not on arm64 195 if (m_compiler->getTargetOpts().Triple.find("arm64") == std::string::npos && 196 m_compiler->getTargetOpts().Triple.find("arm") != std::string::npos && 197 m_compiler->getTargetOpts().Triple.find("ios") != std::string::npos) 198 { 199 m_compiler->getTargetOpts().ABI = "apcs-gnu"; 200 } 201 202 m_compiler->createDiagnostics(); 203 204 // Create the target instance. 205 m_compiler->setTarget(TargetInfo::CreateTargetInfo( 206 m_compiler->getDiagnostics(), m_compiler->getInvocation().TargetOpts)); 207 208 assert (m_compiler->hasTarget()); 209 210 // 3. Set options. 211 212 lldb::LanguageType language = expr.Language(); 213 214 switch (language) 215 { 216 case lldb::eLanguageTypeC: 217 case lldb::eLanguageTypeC89: 218 case lldb::eLanguageTypeC99: 219 case lldb::eLanguageTypeC11: 220 // FIXME: the following language option is a temporary workaround, 221 // to "ask for C, get C++." 222 // For now, the expression parser must use C++ anytime the 223 // language is a C family language, because the expression parser 224 // uses features of C++ to capture values. 225 m_compiler->getLangOpts().CPlusPlus = true; 226 break; 227 case lldb::eLanguageTypeObjC: 228 m_compiler->getLangOpts().ObjC1 = true; 229 m_compiler->getLangOpts().ObjC2 = true; 230 // FIXME: the following language option is a temporary workaround, 231 // to "ask for ObjC, get ObjC++" (see comment above). 232 m_compiler->getLangOpts().CPlusPlus = true; 233 break; 234 case lldb::eLanguageTypeC_plus_plus: 235 case lldb::eLanguageTypeC_plus_plus_11: 236 case lldb::eLanguageTypeC_plus_plus_14: 237 m_compiler->getLangOpts().CPlusPlus11 = true; 238 m_compiler->getHeaderSearchOpts().UseLibcxx = true; 239 // fall thru ... 240 case lldb::eLanguageTypeC_plus_plus_03: 241 m_compiler->getLangOpts().CPlusPlus = true; 242 // FIXME: the following language option is a temporary workaround, 243 // to "ask for C++, get ObjC++". Apple hopes to remove this requirement 244 // on non-Apple platforms, but for now it is needed. 245 m_compiler->getLangOpts().ObjC1 = true; 246 break; 247 case lldb::eLanguageTypeObjC_plus_plus: 248 case lldb::eLanguageTypeUnknown: 249 default: 250 m_compiler->getLangOpts().ObjC1 = true; 251 m_compiler->getLangOpts().ObjC2 = true; 252 m_compiler->getLangOpts().CPlusPlus = true; 253 m_compiler->getLangOpts().CPlusPlus11 = true; 254 m_compiler->getHeaderSearchOpts().UseLibcxx = true; 255 break; 256 } 257 258 m_compiler->getLangOpts().Bool = true; 259 m_compiler->getLangOpts().WChar = true; 260 m_compiler->getLangOpts().Blocks = true; 261 m_compiler->getLangOpts().DebuggerSupport = true; // Features specifically for debugger clients 262 if (expr.DesiredResultType() == Expression::eResultTypeId) 263 m_compiler->getLangOpts().DebuggerCastResultToId = true; 264 265 m_compiler->getLangOpts().CharIsSigned = 266 ArchSpec(m_compiler->getTargetOpts().Triple.c_str()).CharIsSignedByDefault(); 267 268 // Spell checking is a nice feature, but it ends up completing a 269 // lot of types that we didn't strictly speaking need to complete. 270 // As a result, we spend a long time parsing and importing debug 271 // information. 272 m_compiler->getLangOpts().SpellChecking = false; 273 274 lldb::ProcessSP process_sp; 275 if (exe_scope) 276 process_sp = exe_scope->CalculateProcess(); 277 278 if (process_sp && m_compiler->getLangOpts().ObjC1) 279 { 280 if (process_sp->GetObjCLanguageRuntime()) 281 { 282 if (process_sp->GetObjCLanguageRuntime()->GetRuntimeVersion() == ObjCLanguageRuntime::ObjCRuntimeVersions::eAppleObjC_V2) 283 m_compiler->getLangOpts().ObjCRuntime.set(ObjCRuntime::MacOSX, VersionTuple(10, 7)); 284 else 285 m_compiler->getLangOpts().ObjCRuntime.set(ObjCRuntime::FragileMacOSX, VersionTuple(10, 7)); 286 287 if (process_sp->GetObjCLanguageRuntime()->HasNewLiteralsAndIndexing()) 288 m_compiler->getLangOpts().DebuggerObjCLiteral = true; 289 } 290 } 291 292 m_compiler->getLangOpts().ThreadsafeStatics = false; 293 m_compiler->getLangOpts().AccessControl = false; // Debuggers get universal access 294 m_compiler->getLangOpts().DollarIdents = true; // $ indicates a persistent variable name 295 296 // Set CodeGen options 297 m_compiler->getCodeGenOpts().EmitDeclMetadata = true; 298 m_compiler->getCodeGenOpts().InstrumentFunctions = false; 299 m_compiler->getCodeGenOpts().DisableFPElim = true; 300 m_compiler->getCodeGenOpts().OmitLeafFramePointer = false; 301 if (generate_debug_info) 302 m_compiler->getCodeGenOpts().setDebugInfo(CodeGenOptions::FullDebugInfo); 303 else 304 m_compiler->getCodeGenOpts().setDebugInfo(CodeGenOptions::NoDebugInfo); 305 306 // Disable some warnings. 307 m_compiler->getDiagnostics().setSeverityForGroup(clang::diag::Flavor::WarningOrError, 308 "unused-value", clang::diag::Severity::Ignored, SourceLocation()); 309 m_compiler->getDiagnostics().setSeverityForGroup(clang::diag::Flavor::WarningOrError, 310 "odr", clang::diag::Severity::Ignored, SourceLocation()); 311 312 // Inform the target of the language options 313 // 314 // FIXME: We shouldn't need to do this, the target should be immutable once 315 // created. This complexity should be lifted elsewhere. 316 m_compiler->getTarget().adjust(m_compiler->getLangOpts()); 317 318 // 4. Set up the diagnostic buffer for reporting errors 319 320 m_compiler->getDiagnostics().setClient(new clang::TextDiagnosticBuffer); 321 322 // 5. Set up the source management objects inside the compiler 323 324 clang::FileSystemOptions file_system_options; 325 m_file_manager.reset(new clang::FileManager(file_system_options)); 326 327 if (!m_compiler->hasSourceManager()) 328 m_compiler->createSourceManager(*m_file_manager.get()); 329 330 m_compiler->createFileManager(); 331 m_compiler->createPreprocessor(TU_Complete); 332 333 if (ClangModulesDeclVendor *decl_vendor = target_sp->GetClangModulesDeclVendor()) 334 { 335 ClangPersistentVariables *clang_persistent_vars = llvm::cast<ClangPersistentVariables>(target_sp->GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC)); 336 std::unique_ptr<PPCallbacks> pp_callbacks(new LLDBPreprocessorCallbacks(*decl_vendor, *clang_persistent_vars)); 337 m_pp_callbacks = static_cast<LLDBPreprocessorCallbacks*>(pp_callbacks.get()); 338 m_compiler->getPreprocessor().addPPCallbacks(std::move(pp_callbacks)); 339 } 340 341 // 6. Most of this we get from the CompilerInstance, but we 342 // also want to give the context an ExternalASTSource. 343 m_selector_table.reset(new SelectorTable()); 344 m_builtin_context.reset(new Builtin::Context()); 345 346 std::unique_ptr<clang::ASTContext> ast_context(new ASTContext(m_compiler->getLangOpts(), 347 m_compiler->getSourceManager(), 348 m_compiler->getPreprocessor().getIdentifierTable(), 349 *m_selector_table.get(), 350 *m_builtin_context.get())); 351 352 ast_context->InitBuiltinTypes(m_compiler->getTarget()); 353 354 ClangExpressionHelper *type_system_helper = dyn_cast<ClangExpressionHelper>(m_expr.GetTypeSystemHelper()); 355 ClangExpressionDeclMap *decl_map = type_system_helper->DeclMap(); 356 357 if (decl_map) 358 { 359 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source(decl_map->CreateProxy()); 360 decl_map->InstallASTContext(ast_context.get()); 361 ast_context->setExternalSource(ast_source); 362 } 363 364 m_ast_context.reset(new ClangASTContext(m_compiler->getTargetOpts().Triple.c_str())); 365 m_ast_context->setASTContext(ast_context.get()); 366 m_compiler->setASTContext(ast_context.release()); 367 368 std::string module_name("$__lldb_module"); 369 370 m_llvm_context.reset(new LLVMContext()); 371 m_code_generator.reset(CreateLLVMCodeGen(m_compiler->getDiagnostics(), 372 module_name, 373 m_compiler->getHeaderSearchOpts(), 374 m_compiler->getPreprocessorOpts(), 375 m_compiler->getCodeGenOpts(), 376 *m_llvm_context)); 377 } 378 379 ClangExpressionParser::~ClangExpressionParser() 380 { 381 } 382 383 unsigned 384 ClangExpressionParser::Parse (Stream &stream) 385 { 386 TextDiagnosticBuffer *diag_buf = static_cast<TextDiagnosticBuffer*>(m_compiler->getDiagnostics().getClient()); 387 388 diag_buf->FlushDiagnostics (m_compiler->getDiagnostics()); 389 390 const char *expr_text = m_expr.Text(); 391 392 clang::SourceManager &SourceMgr = m_compiler->getSourceManager(); 393 bool created_main_file = false; 394 if (m_compiler->getCodeGenOpts().getDebugInfo() == CodeGenOptions::FullDebugInfo) 395 { 396 std::string temp_source_path; 397 398 int temp_fd = -1; 399 llvm::SmallString<PATH_MAX> result_path; 400 FileSpec tmpdir_file_spec; 401 if (HostInfo::GetLLDBPath(lldb::ePathTypeLLDBTempSystemDir, tmpdir_file_spec)) 402 { 403 tmpdir_file_spec.AppendPathComponent("lldb-%%%%%%.expr"); 404 temp_source_path = tmpdir_file_spec.GetPath(); 405 llvm::sys::fs::createUniqueFile(temp_source_path, temp_fd, result_path); 406 } 407 else 408 { 409 llvm::sys::fs::createTemporaryFile("lldb", "expr", temp_fd, result_path); 410 } 411 412 if (temp_fd != -1) 413 { 414 lldb_private::File file (temp_fd, true); 415 const size_t expr_text_len = strlen(expr_text); 416 size_t bytes_written = expr_text_len; 417 if (file.Write(expr_text, bytes_written).Success()) 418 { 419 if (bytes_written == expr_text_len) 420 { 421 file.Close(); 422 SourceMgr.setMainFileID(SourceMgr.createFileID( 423 m_file_manager->getFile(result_path), 424 SourceLocation(), SrcMgr::C_User)); 425 created_main_file = true; 426 } 427 } 428 } 429 } 430 431 if (!created_main_file) 432 { 433 std::unique_ptr<MemoryBuffer> memory_buffer = MemoryBuffer::getMemBufferCopy(expr_text, __FUNCTION__); 434 SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(memory_buffer))); 435 } 436 437 diag_buf->BeginSourceFile(m_compiler->getLangOpts(), &m_compiler->getPreprocessor()); 438 439 ClangExpressionHelper *type_system_helper = dyn_cast<ClangExpressionHelper>(m_expr.GetTypeSystemHelper()); 440 441 ASTConsumer *ast_transformer = type_system_helper->ASTTransformer(m_code_generator.get()); 442 443 if (ClangExpressionDeclMap *decl_map = type_system_helper->DeclMap()) 444 decl_map->InstallCodeGenerator(m_code_generator.get()); 445 446 if (ast_transformer) 447 { 448 ast_transformer->Initialize(m_compiler->getASTContext()); 449 ParseAST(m_compiler->getPreprocessor(), ast_transformer, m_compiler->getASTContext()); 450 } 451 else 452 { 453 m_code_generator->Initialize(m_compiler->getASTContext()); 454 ParseAST(m_compiler->getPreprocessor(), m_code_generator.get(), m_compiler->getASTContext()); 455 } 456 457 diag_buf->EndSourceFile(); 458 459 TextDiagnosticBuffer::const_iterator diag_iterator; 460 461 int num_errors = 0; 462 463 if (m_pp_callbacks && m_pp_callbacks->hasErrors()) 464 { 465 num_errors++; 466 467 stream.PutCString(m_pp_callbacks->getErrorString().c_str()); 468 } 469 470 for (diag_iterator = diag_buf->warn_begin(); 471 diag_iterator != diag_buf->warn_end(); 472 ++diag_iterator) 473 stream.Printf("warning: %s\n", (*diag_iterator).second.c_str()); 474 475 for (diag_iterator = diag_buf->err_begin(); 476 diag_iterator != diag_buf->err_end(); 477 ++diag_iterator) 478 { 479 num_errors++; 480 stream.Printf("error: %s\n", (*diag_iterator).second.c_str()); 481 } 482 483 for (diag_iterator = diag_buf->note_begin(); 484 diag_iterator != diag_buf->note_end(); 485 ++diag_iterator) 486 stream.Printf("note: %s\n", (*diag_iterator).second.c_str()); 487 488 if (!num_errors) 489 { 490 if (type_system_helper->DeclMap() && !type_system_helper->DeclMap()->ResolveUnknownTypes()) 491 { 492 stream.Printf("error: Couldn't infer the type of a variable\n"); 493 num_errors++; 494 } 495 } 496 497 return num_errors; 498 } 499 500 static bool FindFunctionInModule (ConstString &mangled_name, 501 llvm::Module *module, 502 const char *orig_name) 503 { 504 for (llvm::Module::iterator fi = module->getFunctionList().begin(), fe = module->getFunctionList().end(); 505 fi != fe; 506 ++fi) 507 { 508 if (fi->getName().str().find(orig_name) != std::string::npos) 509 { 510 mangled_name.SetCString(fi->getName().str().c_str()); 511 return true; 512 } 513 } 514 515 return false; 516 } 517 518 Error 519 ClangExpressionParser::PrepareForExecution (lldb::addr_t &func_addr, 520 lldb::addr_t &func_end, 521 std::shared_ptr<IRExecutionUnit> &execution_unit_sp, 522 ExecutionContext &exe_ctx, 523 bool &can_interpret, 524 ExecutionPolicy execution_policy) 525 { 526 func_addr = LLDB_INVALID_ADDRESS; 527 func_end = LLDB_INVALID_ADDRESS; 528 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); 529 530 Error err; 531 532 std::unique_ptr<llvm::Module> llvm_module_ap (m_code_generator->ReleaseModule()); 533 534 if (!llvm_module_ap.get()) 535 { 536 err.SetErrorToGenericError(); 537 err.SetErrorString("IR doesn't contain a module"); 538 return err; 539 } 540 541 // Find the actual name of the function (it's often mangled somehow) 542 543 ConstString function_name; 544 545 if (!FindFunctionInModule(function_name, llvm_module_ap.get(), m_expr.FunctionName())) 546 { 547 err.SetErrorToGenericError(); 548 err.SetErrorStringWithFormat("Couldn't find %s() in the module", m_expr.FunctionName()); 549 return err; 550 } 551 else 552 { 553 if (log) 554 log->Printf("Found function %s for %s", function_name.AsCString(), m_expr.FunctionName()); 555 } 556 557 execution_unit_sp.reset(new IRExecutionUnit (m_llvm_context, // handed off here 558 llvm_module_ap, // handed off here 559 function_name, 560 exe_ctx.GetTargetSP(), 561 m_compiler->getTargetOpts().Features)); 562 563 ClangExpressionHelper *type_system_helper = dyn_cast<ClangExpressionHelper>(m_expr.GetTypeSystemHelper()); 564 ClangExpressionDeclMap *decl_map = type_system_helper->DeclMap(); // result can be NULL 565 566 if (decl_map) 567 { 568 Stream *error_stream = NULL; 569 Target *target = exe_ctx.GetTargetPtr(); 570 if (target) 571 error_stream = target->GetDebugger().GetErrorFile().get(); 572 573 IRForTarget ir_for_target(decl_map, 574 m_expr.NeedsVariableResolution(), 575 *execution_unit_sp, 576 error_stream, 577 function_name.AsCString()); 578 579 bool ir_can_run = ir_for_target.runOnModule(*execution_unit_sp->GetModule()); 580 581 Error interpret_error; 582 Process *process = exe_ctx.GetProcessPtr(); 583 584 bool interpret_function_calls = !process ? false : process->CanInterpretFunctionCalls(); 585 can_interpret = IRInterpreter::CanInterpret(*execution_unit_sp->GetModule(), *execution_unit_sp->GetFunction(), interpret_error, interpret_function_calls); 586 587 588 if (!ir_can_run) 589 { 590 err.SetErrorString("The expression could not be prepared to run in the target"); 591 return err; 592 } 593 594 if (!can_interpret && execution_policy == eExecutionPolicyNever) 595 { 596 err.SetErrorStringWithFormat("Can't run the expression locally: %s", interpret_error.AsCString()); 597 return err; 598 } 599 600 if (!process && execution_policy == eExecutionPolicyAlways) 601 { 602 err.SetErrorString("Expression needed to run in the target, but the target can't be run"); 603 return err; 604 } 605 606 if (execution_policy == eExecutionPolicyAlways || !can_interpret) 607 { 608 if (m_expr.NeedsValidation() && process) 609 { 610 if (!process->GetDynamicCheckers()) 611 { 612 DynamicCheckerFunctions *dynamic_checkers = new DynamicCheckerFunctions(); 613 614 StreamString install_errors; 615 616 if (!dynamic_checkers->Install(install_errors, exe_ctx)) 617 { 618 if (install_errors.GetString().empty()) 619 err.SetErrorString ("couldn't install checkers, unknown error"); 620 else 621 err.SetErrorString (install_errors.GetString().c_str()); 622 623 return err; 624 } 625 626 process->SetDynamicCheckers(dynamic_checkers); 627 628 if (log) 629 log->Printf("== [ClangUserExpression::Evaluate] Finished installing dynamic checkers =="); 630 } 631 632 IRDynamicChecks ir_dynamic_checks(*process->GetDynamicCheckers(), function_name.AsCString()); 633 634 if (!ir_dynamic_checks.runOnModule(*execution_unit_sp->GetModule())) 635 { 636 err.SetErrorToGenericError(); 637 err.SetErrorString("Couldn't add dynamic checks to the expression"); 638 return err; 639 } 640 } 641 642 execution_unit_sp->GetRunnableInfo(err, func_addr, func_end); 643 } 644 } 645 else 646 { 647 execution_unit_sp->GetRunnableInfo(err, func_addr, func_end); 648 } 649 650 return err; 651 } 652