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