ClangExpressionParser.cpp revision 263508
1204433Sraj//===-- ClangExpressionParser.cpp -------------------------------*- C++ -*-===//
2204433Sraj//
3204433Sraj//                     The LLVM Compiler Infrastructure
4238742Simp//
5266130Sian// This file is distributed under the University of Illinois Open Source
6266130Sian// License. See LICENSE.TXT for details.
7238742Simp//
8204433Sraj//===----------------------------------------------------------------------===//
9238742Simp
10204433Sraj#include "lldb/lldb-python.h"
11204433Sraj
12204433Sraj#include "lldb/Expression/ClangExpressionParser.h"
13204433Sraj
14204433Sraj#include "lldb/Core/ArchSpec.h"
15204433Sraj#include "lldb/Core/DataBufferHeap.h"
16204433Sraj#include "lldb/Core/Debugger.h"
17204433Sraj#include "lldb/Core/Disassembler.h"
18204433Sraj#include "lldb/Core/Stream.h"
19204433Sraj#include "lldb/Core/StreamString.h"
20204433Sraj#include "lldb/Expression/ClangASTSource.h"
21204433Sraj#include "lldb/Expression/ClangExpression.h"
22204433Sraj#include "lldb/Expression/ClangExpressionDeclMap.h"
23204433Sraj#include "lldb/Expression/IRExecutionUnit.h"
24204433Sraj#include "lldb/Expression/IRDynamicChecks.h"
25204433Sraj#include "lldb/Expression/IRInterpreter.h"
26204433Sraj#include "lldb/Target/ExecutionContext.h"
27204433Sraj#include "lldb/Target/ObjCLanguageRuntime.h"
28266130Sian#include "lldb/Target/Process.h"
29266130Sian#include "lldb/Target/Target.h"
30266130Sian
31204433Sraj#include "clang/AST/ASTContext.h"
32204433Sraj#include "clang/AST/ExternalASTSource.h"
33204433Sraj#include "clang/Basic/FileManager.h"
34204433Sraj#include "clang/Basic/TargetInfo.h"
35204433Sraj#include "clang/Basic/Version.h"
36204433Sraj#include "clang/CodeGen/CodeGenAction.h"
37204433Sraj#include "clang/CodeGen/ModuleBuilder.h"
38204433Sraj#include "clang/Driver/CC1Options.h"
39204433Sraj#include "clang/Frontend/CompilerInstance.h"
40204433Sraj#include "clang/Frontend/CompilerInvocation.h"
41204433Sraj#include "clang/Frontend/FrontendActions.h"
42204433Sraj#include "clang/Frontend/FrontendDiagnostic.h"
43204433Sraj#include "clang/Frontend/FrontendPluginRegistry.h"
44204433Sraj#include "clang/Frontend/TextDiagnosticBuffer.h"
45204433Sraj#include "clang/Frontend/TextDiagnosticPrinter.h"
46204433Sraj#include "clang/Lex/Preprocessor.h"
47204433Sraj#include "clang/Parse/ParseAST.h"
48204433Sraj#include "clang/Rewrite/Frontend/FrontendActions.h"
49204433Sraj#include "clang/Sema/SemaConsumer.h"
50204433Sraj#include "clang/StaticAnalyzer/Frontend/FrontendActions.h"
51204433Sraj
52204433Sraj#include "llvm/ADT/StringRef.h"
53204433Sraj#include "llvm/ExecutionEngine/ExecutionEngine.h"
54204433Sraj#include "llvm/Support/Debug.h"
55204433Sraj#include "llvm/Support/FileSystem.h"
56204433Sraj#include "llvm/Support/TargetSelect.h"
57204433Sraj
58204433Sraj#if defined (USE_STANDARD_JIT)
59204433Sraj#include "llvm/ExecutionEngine/JIT.h"
60204433Sraj#else
61238742Simp#include "llvm/ExecutionEngine/MCJIT.h"
62204433Sraj#endif
63238742Simp#include "llvm/IR/LLVMContext.h"
64266130Sian#include "llvm/IR/Module.h"
65266130Sian#include "llvm/Support/ErrorHandling.h"
66266130Sian#include "llvm/Support/MemoryBuffer.h"
67238742Simp#include "llvm/Support/DynamicLibrary.h"
68238742Simp#include "llvm/Support/Host.h"
69238742Simp#include "llvm/Support/Signals.h"
70266130Sian
71266130Sianusing namespace clang;
72266130Sianusing namespace llvm;
73238742Simpusing namespace lldb_private;
74238742Simp
75238742Simp//===----------------------------------------------------------------------===//
76238742Simp// Utility Methods for Clang
77238742Simp//===----------------------------------------------------------------------===//
78238742Simp
79238742Simpstd::string GetBuiltinIncludePath(const char *Argv0) {
80238742Simp    SmallString<128> P(llvm::sys::fs::getMainExecutable(
81238742Simp        Argv0, (void *)(intptr_t) GetBuiltinIncludePath));
82238742Simp
83238742Simp    if (!P.empty()) {
84238742Simp        llvm::sys::path::remove_filename(P); // Remove /clang from foo/bin/clang
85238742Simp        llvm::sys::path::remove_filename(P); // Remove /bin   from foo/bin
86238742Simp
87238742Simp        // Get foo/lib/clang/<version>/include
88238742Simp        llvm::sys::path::append(P, "lib", "clang", CLANG_VERSION_STRING,
89238742Simp                                "include");
90238742Simp    }
91238742Simp
92266130Sian    return P.str();
93266130Sian}
94266130Sian
95266130Sian
96266130Sian//===----------------------------------------------------------------------===//
97266130Sian// Main driver for Clang
98266130Sian//===----------------------------------------------------------------------===//
99238742Simp
100238742Simpstatic void LLVMErrorHandler(void *UserData, const std::string &Message) {
101238742Simp    DiagnosticsEngine &Diags = *static_cast<DiagnosticsEngine*>(UserData);
102238742Simp
103238742Simp    Diags.Report(diag::err_fe_error_backend) << Message;
104238742Simp
105238742Simp    // We cannot recover from llvm errors.
106238742Simp    assert(0);
107238742Simp}
108238742Simp
109266130Sianstatic FrontendAction *CreateFrontendBaseAction(CompilerInstance &CI) {
110266130Sian    using namespace clang::frontend;
111266130Sian
112266130Sian    switch (CI.getFrontendOpts().ProgramAction) {
113266130Sian        default:
114266130Sian            llvm_unreachable("Invalid program action!");
115238742Simp
116238742Simp        case ASTDump:                return new ASTDumpAction();
117238742Simp        case ASTPrint:               return new ASTPrintAction();
118238742Simp        case ASTView:                return new ASTViewAction();
119238742Simp        case DumpRawTokens:          return new DumpRawTokensAction();
120238742Simp        case DumpTokens:             return new DumpTokensAction();
121238742Simp        case EmitAssembly:           return new EmitAssemblyAction();
122238742Simp        case EmitBC:                 return new EmitBCAction();
123238742Simp        case EmitHTML:               return new HTMLPrintAction();
124238742Simp        case EmitLLVM:               return new EmitLLVMAction();
125238742Simp        case EmitLLVMOnly:           return new EmitLLVMOnlyAction();
126238742Simp        case EmitCodeGenOnly:        return new EmitCodeGenOnlyAction();
127238742Simp        case EmitObj:                return new EmitObjAction();
128238742Simp        case FixIt:                  return new FixItAction();
129238742Simp        case GeneratePCH:            return new GeneratePCHAction();
130238742Simp        case GeneratePTH:            return new GeneratePTHAction();
131238742Simp        case InitOnly:               return new InitOnlyAction();
132238742Simp        case ParseSyntaxOnly:        return new SyntaxOnlyAction();
133238742Simp
134238742Simp        case PluginAction: {
135238742Simp            for (FrontendPluginRegistry::iterator it =
136238742Simp                 FrontendPluginRegistry::begin(), ie = FrontendPluginRegistry::end();
137238742Simp                 it != ie; ++it) {
138238742Simp                if (it->getName() == CI.getFrontendOpts().ActionName) {
139238742Simp                    llvm::OwningPtr<PluginASTAction> P(it->instantiate());
140238742Simp                    if (!P->ParseArgs(CI, CI.getFrontendOpts().PluginArgs))
141238742Simp                        return 0;
142238742Simp                    return P.take();
143238742Simp                }
144238742Simp            }
145238742Simp
146238742Simp            CI.getDiagnostics().Report(diag::err_fe_invalid_plugin_name)
147238742Simp            << CI.getFrontendOpts().ActionName;
148238742Simp            return 0;
149238742Simp        }
150238742Simp
151238742Simp        case PrintDeclContext:       return new DeclContextPrintAction();
152238742Simp        case PrintPreamble:          return new PrintPreambleAction();
153238742Simp        case PrintPreprocessedInput: return new PrintPreprocessedAction();
154238742Simp        case RewriteMacros:          return new RewriteMacrosAction();
155238742Simp        case RewriteObjC:            return new RewriteObjCAction();
156238742Simp        case RewriteTest:            return new RewriteTestAction();
157238742Simp        //case RunAnalysis:            return new AnalysisAction();
158238742Simp        case RunPreprocessorOnly:    return new PreprocessOnlyAction();
159238742Simp    }
160238742Simp}
161238742Simp
162238742Simpstatic FrontendAction *CreateFrontendAction(CompilerInstance &CI) {
163238742Simp    // Create the underlying action.
164238742Simp    FrontendAction *Act = CreateFrontendBaseAction(CI);
165238742Simp    if (!Act)
166238742Simp        return 0;
167238742Simp
168238742Simp    // If there are any AST files to merge, create a frontend action
169238742Simp    // adaptor to perform the merge.
170266130Sian    if (!CI.getFrontendOpts().ASTMergeFiles.empty())
171238742Simp        Act = new ASTMergeAction(Act, CI.getFrontendOpts().ASTMergeFiles);
172266130Sian
173266130Sian    return Act;
174266130Sian}
175266130Sian
176266130Sian//===----------------------------------------------------------------------===//
177266130Sian// Implementation of ClangExpressionParser
178266130Sian//===----------------------------------------------------------------------===//
179266130Sian
180266130SianClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope,
181266130Sian                                              ClangExpression &expr) :
182266130Sian    m_expr (expr),
183266130Sian    m_compiler (),
184266130Sian    m_code_generator ()
185266130Sian{
186266130Sian    // Initialize targets first, so that --version shows registered targets.
187266130Sian    static struct InitializeLLVM {
188266130Sian        InitializeLLVM() {
189266130Sian            llvm::InitializeAllTargets();
190266130Sian            llvm::InitializeAllAsmPrinters();
191266130Sian            llvm::InitializeAllTargetMCs();
192266130Sian            llvm::InitializeAllDisassemblers();
193266130Sian        }
194266130Sian    } InitializeLLVM;
195266130Sian
196266130Sian    // 1. Create a new compiler instance.
197266130Sian    m_compiler.reset(new CompilerInstance());
198266130Sian
199266130Sian    // 2. Install the target.
200266130Sian
201266130Sian    lldb::TargetSP target_sp;
202266130Sian    if (exe_scope)
203266130Sian        target_sp = exe_scope->CalculateTarget();
204266130Sian
205266130Sian    // TODO: figure out what to really do when we don't have a valid target.
206266130Sian    // Sometimes this will be ok to just use the host target triple (when we
207266130Sian    // evaluate say "2+3", but other expressions like breakpoint conditions
208266130Sian    // and other things that _are_ target specific really shouldn't just be
209266130Sian    // using the host triple. This needs to be fixed in a better way.
210266130Sian    if (target_sp && target_sp->GetArchitecture().IsValid())
211266130Sian    {
212266130Sian        std::string triple = target_sp->GetArchitecture().GetTriple().str();
213266130Sian
214266130Sian        int dash_count = 0;
215266130Sian        for (size_t i = 0; i < triple.size(); ++i)
216266130Sian        {
217266130Sian            if (triple[i] == '-')
218266130Sian                dash_count++;
219266130Sian            if (dash_count == 3)
220266130Sian            {
221266130Sian                triple.resize(i);
222266130Sian                break;
223266130Sian            }
224266130Sian        }
225266130Sian
226266130Sian        m_compiler->getTargetOpts().Triple = triple;
227266130Sian    }
228266130Sian    else
229266130Sian    {
230266130Sian        m_compiler->getTargetOpts().Triple = llvm::sys::getDefaultTargetTriple();
231266130Sian    }
232266130Sian
233266130Sian    if (target_sp->GetArchitecture().GetMachine() == llvm::Triple::x86 ||
234266130Sian        target_sp->GetArchitecture().GetMachine() == llvm::Triple::x86_64)
235266130Sian    {
236266130Sian        m_compiler->getTargetOpts().Features.push_back("+sse");
237266130Sian        m_compiler->getTargetOpts().Features.push_back("+sse2");
238266130Sian    }
239266130Sian
240266130Sian    if (m_compiler->getTargetOpts().Triple.find("ios") != std::string::npos)
241266130Sian        m_compiler->getTargetOpts().ABI = "apcs-gnu";
242266130Sian
243266130Sian    m_compiler->createDiagnostics();
244266130Sian
245266130Sian    // Create the target instance.
246266130Sian    m_compiler->setTarget(TargetInfo::CreateTargetInfo(m_compiler->getDiagnostics(),
247266130Sian                                                       &m_compiler->getTargetOpts()));
248266130Sian
249266130Sian    assert (m_compiler->hasTarget());
250266130Sian
251204433Sraj    // 3. Set options.
252
253    lldb::LanguageType language = expr.Language();
254
255    switch (language)
256    {
257    case lldb::eLanguageTypeC:
258        break;
259    case lldb::eLanguageTypeObjC:
260        m_compiler->getLangOpts().ObjC1 = true;
261        m_compiler->getLangOpts().ObjC2 = true;
262        break;
263    case lldb::eLanguageTypeC_plus_plus:
264        m_compiler->getLangOpts().CPlusPlus = true;
265        m_compiler->getLangOpts().CPlusPlus11 = true;
266        break;
267    case lldb::eLanguageTypeObjC_plus_plus:
268    default:
269        m_compiler->getLangOpts().ObjC1 = true;
270        m_compiler->getLangOpts().ObjC2 = true;
271        m_compiler->getLangOpts().CPlusPlus = true;
272        m_compiler->getLangOpts().CPlusPlus11 = true;
273        break;
274    }
275
276    m_compiler->getLangOpts().Bool = true;
277    m_compiler->getLangOpts().WChar = true;
278    m_compiler->getLangOpts().Blocks = true;
279    m_compiler->getLangOpts().DebuggerSupport = true; // Features specifically for debugger clients
280    if (expr.DesiredResultType() == ClangExpression::eResultTypeId)
281        m_compiler->getLangOpts().DebuggerCastResultToId = true;
282
283    // Spell checking is a nice feature, but it ends up completing a
284    // lot of types that we didn't strictly speaking need to complete.
285    // As a result, we spend a long time parsing and importing debug
286    // information.
287    m_compiler->getLangOpts().SpellChecking = false;
288
289    lldb::ProcessSP process_sp;
290    if (exe_scope)
291        process_sp = exe_scope->CalculateProcess();
292
293    if (process_sp && m_compiler->getLangOpts().ObjC1)
294    {
295        if (process_sp->GetObjCLanguageRuntime())
296        {
297            if (process_sp->GetObjCLanguageRuntime()->GetRuntimeVersion() == eAppleObjC_V2)
298                m_compiler->getLangOpts().ObjCRuntime.set(ObjCRuntime::MacOSX, VersionTuple(10, 7));
299            else
300                m_compiler->getLangOpts().ObjCRuntime.set(ObjCRuntime::FragileMacOSX, VersionTuple(10, 7));
301
302            if (process_sp->GetObjCLanguageRuntime()->HasNewLiteralsAndIndexing())
303                m_compiler->getLangOpts().DebuggerObjCLiteral = true;
304        }
305    }
306
307    m_compiler->getLangOpts().ThreadsafeStatics = false;
308    m_compiler->getLangOpts().AccessControl = false; // Debuggers get universal access
309    m_compiler->getLangOpts().DollarIdents = true; // $ indicates a persistent variable name
310
311    // Set CodeGen options
312    m_compiler->getCodeGenOpts().EmitDeclMetadata = true;
313    m_compiler->getCodeGenOpts().InstrumentFunctions = false;
314    m_compiler->getCodeGenOpts().DisableFPElim = true;
315    m_compiler->getCodeGenOpts().OmitLeafFramePointer = false;
316
317    // Disable some warnings.
318    m_compiler->getDiagnostics().setDiagnosticGroupMapping("unused-value", clang::diag::MAP_IGNORE, SourceLocation());
319    m_compiler->getDiagnostics().setDiagnosticGroupMapping("odr", clang::diag::MAP_IGNORE, SourceLocation());
320
321    // Inform the target of the language options
322    //
323    // FIXME: We shouldn't need to do this, the target should be immutable once
324    // created. This complexity should be lifted elsewhere.
325    m_compiler->getTarget().setForcedLangOptions(m_compiler->getLangOpts());
326
327    // 4. Set up the diagnostic buffer for reporting errors
328
329    m_compiler->getDiagnostics().setClient(new clang::TextDiagnosticBuffer);
330
331    // 5. Set up the source management objects inside the compiler
332
333    clang::FileSystemOptions file_system_options;
334    m_file_manager.reset(new clang::FileManager(file_system_options));
335
336    if (!m_compiler->hasSourceManager())
337        m_compiler->createSourceManager(*m_file_manager.get());
338
339    m_compiler->createFileManager();
340    m_compiler->createPreprocessor();
341
342    // 6. Most of this we get from the CompilerInstance, but we
343    // also want to give the context an ExternalASTSource.
344    m_selector_table.reset(new SelectorTable());
345    m_builtin_context.reset(new Builtin::Context());
346
347    std::unique_ptr<clang::ASTContext> ast_context(new ASTContext(m_compiler->getLangOpts(),
348                                                                 m_compiler->getSourceManager(),
349                                                                 &m_compiler->getTarget(),
350                                                                 m_compiler->getPreprocessor().getIdentifierTable(),
351                                                                 *m_selector_table.get(),
352                                                                 *m_builtin_context.get(),
353                                                                 0));
354
355    ClangExpressionDeclMap *decl_map = m_expr.DeclMap();
356
357    if (decl_map)
358    {
359        llvm::OwningPtr<clang::ExternalASTSource> ast_source(decl_map->CreateProxy());
360        decl_map->InstallASTContext(ast_context.get());
361        ast_context->setExternalSource(ast_source);
362    }
363
364    m_compiler->setASTContext(ast_context.release());
365
366    std::string module_name("$__lldb_module");
367
368    m_llvm_context.reset(new LLVMContext());
369    m_code_generator.reset(CreateLLVMCodeGen(m_compiler->getDiagnostics(),
370                                             module_name,
371                                             m_compiler->getCodeGenOpts(),
372                                             m_compiler->getTargetOpts(),
373                                             *m_llvm_context));
374}
375
376ClangExpressionParser::~ClangExpressionParser()
377{
378}
379
380unsigned
381ClangExpressionParser::Parse (Stream &stream)
382{
383    TextDiagnosticBuffer *diag_buf = static_cast<TextDiagnosticBuffer*>(m_compiler->getDiagnostics().getClient());
384
385    diag_buf->FlushDiagnostics (m_compiler->getDiagnostics());
386
387    MemoryBuffer *memory_buffer = MemoryBuffer::getMemBufferCopy(m_expr.Text(), __FUNCTION__);
388    m_compiler->getSourceManager().createMainFileIDForMemBuffer (memory_buffer);
389
390    diag_buf->BeginSourceFile(m_compiler->getLangOpts(), &m_compiler->getPreprocessor());
391
392    ASTConsumer *ast_transformer = m_expr.ASTTransformer(m_code_generator.get());
393
394    if (ast_transformer)
395        ParseAST(m_compiler->getPreprocessor(), ast_transformer, m_compiler->getASTContext());
396    else
397        ParseAST(m_compiler->getPreprocessor(), m_code_generator.get(), m_compiler->getASTContext());
398
399    diag_buf->EndSourceFile();
400
401    TextDiagnosticBuffer::const_iterator diag_iterator;
402
403    int num_errors = 0;
404
405    for (diag_iterator = diag_buf->warn_begin();
406         diag_iterator != diag_buf->warn_end();
407         ++diag_iterator)
408        stream.Printf("warning: %s\n", (*diag_iterator).second.c_str());
409
410    num_errors = 0;
411
412    for (diag_iterator = diag_buf->err_begin();
413         diag_iterator != diag_buf->err_end();
414         ++diag_iterator)
415    {
416        num_errors++;
417        stream.Printf("error: %s\n", (*diag_iterator).second.c_str());
418    }
419
420    for (diag_iterator = diag_buf->note_begin();
421         diag_iterator != diag_buf->note_end();
422         ++diag_iterator)
423        stream.Printf("note: %s\n", (*diag_iterator).second.c_str());
424
425    if (!num_errors)
426    {
427        if (m_expr.DeclMap() && !m_expr.DeclMap()->ResolveUnknownTypes())
428        {
429            stream.Printf("error: Couldn't infer the type of a variable\n");
430            num_errors++;
431        }
432    }
433
434    return num_errors;
435}
436
437static bool FindFunctionInModule (ConstString &mangled_name,
438                                  llvm::Module *module,
439                                  const char *orig_name)
440{
441    for (llvm::Module::iterator fi = module->getFunctionList().begin(), fe = module->getFunctionList().end();
442         fi != fe;
443         ++fi)
444    {
445        if (fi->getName().str().find(orig_name) != std::string::npos)
446        {
447            mangled_name.SetCString(fi->getName().str().c_str());
448            return true;
449        }
450    }
451
452    return false;
453}
454
455Error
456ClangExpressionParser::PrepareForExecution (lldb::addr_t &func_addr,
457                                            lldb::addr_t &func_end,
458                                            std::unique_ptr<IRExecutionUnit> &execution_unit_ap,
459                                            ExecutionContext &exe_ctx,
460                                            bool &can_interpret,
461                                            ExecutionPolicy execution_policy)
462{
463	func_addr = LLDB_INVALID_ADDRESS;
464	func_end = LLDB_INVALID_ADDRESS;
465    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
466
467    std::unique_ptr<llvm::ExecutionEngine> execution_engine_ap;
468
469    Error err;
470
471    std::unique_ptr<llvm::Module> module_ap (m_code_generator->ReleaseModule());
472
473    if (!module_ap.get())
474    {
475        err.SetErrorToGenericError();
476        err.SetErrorString("IR doesn't contain a module");
477        return err;
478    }
479
480    // Find the actual name of the function (it's often mangled somehow)
481
482    ConstString function_name;
483
484    if (!FindFunctionInModule(function_name, module_ap.get(), m_expr.FunctionName()))
485    {
486        err.SetErrorToGenericError();
487        err.SetErrorStringWithFormat("Couldn't find %s() in the module", m_expr.FunctionName());
488        return err;
489    }
490    else
491    {
492        if (log)
493            log->Printf("Found function %s for %s", function_name.AsCString(), m_expr.FunctionName());
494    }
495
496    m_execution_unit.reset(new IRExecutionUnit(m_llvm_context, // handed off here
497                                               module_ap, // handed off here
498                                               function_name,
499                                               exe_ctx.GetTargetSP(),
500                                               m_compiler->getTargetOpts().Features));
501
502    ClangExpressionDeclMap *decl_map = m_expr.DeclMap(); // result can be NULL
503
504    if (decl_map)
505    {
506        Stream *error_stream = NULL;
507        Target *target = exe_ctx.GetTargetPtr();
508        if (target)
509            error_stream = &target->GetDebugger().GetErrorStream();
510
511        IRForTarget ir_for_target(decl_map,
512                                  m_expr.NeedsVariableResolution(),
513                                  *m_execution_unit,
514                                  error_stream,
515                                  function_name.AsCString());
516
517        bool ir_can_run = ir_for_target.runOnModule(*m_execution_unit->GetModule());
518
519        Error interpret_error;
520
521        can_interpret = IRInterpreter::CanInterpret(*m_execution_unit->GetModule(), *m_execution_unit->GetFunction(), interpret_error);
522
523        Process *process = exe_ctx.GetProcessPtr();
524
525        if (!ir_can_run)
526        {
527            err.SetErrorString("The expression could not be prepared to run in the target");
528            return err;
529        }
530
531        if (!can_interpret && execution_policy == eExecutionPolicyNever)
532        {
533            err.SetErrorStringWithFormat("Can't run the expression locally: %s", interpret_error.AsCString());
534            return err;
535        }
536
537        if (!process && execution_policy == eExecutionPolicyAlways)
538        {
539            err.SetErrorString("Expression needed to run in the target, but the target can't be run");
540            return err;
541        }
542
543        if (execution_policy == eExecutionPolicyAlways || !can_interpret)
544        {
545            if (m_expr.NeedsValidation() && process)
546            {
547                if (!process->GetDynamicCheckers())
548                {
549                    DynamicCheckerFunctions *dynamic_checkers = new DynamicCheckerFunctions();
550
551                    StreamString install_errors;
552
553                    if (!dynamic_checkers->Install(install_errors, exe_ctx))
554                    {
555                        if (install_errors.GetString().empty())
556                            err.SetErrorString ("couldn't install checkers, unknown error");
557                        else
558                            err.SetErrorString (install_errors.GetString().c_str());
559
560                        return err;
561                    }
562
563                    process->SetDynamicCheckers(dynamic_checkers);
564
565                    if (log)
566                        log->Printf("== [ClangUserExpression::Evaluate] Finished installing dynamic checkers ==");
567                }
568
569                IRDynamicChecks ir_dynamic_checks(*process->GetDynamicCheckers(), function_name.AsCString());
570
571                if (!ir_dynamic_checks.runOnModule(*m_execution_unit->GetModule()))
572                {
573                    err.SetErrorToGenericError();
574                    err.SetErrorString("Couldn't add dynamic checks to the expression");
575                    return err;
576                }
577            }
578
579            m_execution_unit->GetRunnableInfo(err, func_addr, func_end);
580        }
581    }
582    else
583    {
584        m_execution_unit->GetRunnableInfo(err, func_addr, func_end);
585    }
586
587    execution_unit_ap.reset (m_execution_unit.release());
588
589    return err;
590}
591