Example #1
0
bool
DynamicCheckerFunctions::Install(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx)
{
    Error error;
    m_valid_pointer_check.reset(exe_ctx.GetTargetRef().GetUtilityFunctionForLanguage(g_valid_pointer_check_text,
                                                                                     lldb::eLanguageTypeC,
                                                                                     VALID_POINTER_CHECK_NAME,
                                                                                     error));
    if (error.Fail())
        return false;

    if (!m_valid_pointer_check->Install(diagnostic_manager, exe_ctx))
        return false;

    Process *process = exe_ctx.GetProcessPtr();

    if (process)
    {
        ObjCLanguageRuntime *objc_language_runtime = process->GetObjCLanguageRuntime();

        if (objc_language_runtime)
        {
            m_objc_object_check.reset(objc_language_runtime->CreateObjectChecker(VALID_OBJC_OBJECT_CHECK_NAME));

            if (!m_objc_object_check->Install(diagnostic_manager, exe_ctx))
                return false;
        }
    }

    return true;
}
bool
DynamicCheckerFunctions::Install(Stream &error_stream,
                                 ExecutionContext &exe_ctx)
{
    m_valid_pointer_check.reset(new ClangUtilityFunction(g_valid_pointer_check_text,
                                                         VALID_POINTER_CHECK_NAME));
    if (!m_valid_pointer_check->Install(error_stream, exe_ctx))
        return false;
    
    Process *process = exe_ctx.GetProcessPtr();

    if (process)
    {
        ObjCLanguageRuntime *objc_language_runtime = process->GetObjCLanguageRuntime();
        
        if (objc_language_runtime)
        {
            m_objc_object_check.reset(objc_language_runtime->CreateObjectChecker(VALID_OBJC_OBJECT_CHECK_NAME));
            
            if (!m_objc_object_check->Install(error_stream, exe_ctx))
                return false;
        }
    }
        
    return true;
}
Example #3
0
        bool
        Find_Impl (ExecutionContextScope *exe_scope,
                   const char *key,
                   ResultSet &results) override
        {
            bool result = false;
            
            Target* target = exe_scope->CalculateTarget().get();
            if (target)
            {
                if (auto clang_modules_decl_vendor = target->GetClangModulesDeclVendor())
                {
                    std::vector <clang::NamedDecl*> decls;
                    ConstString key_cs(key);
                    
                    if (clang_modules_decl_vendor->FindDecls(key_cs, false, UINT32_MAX, decls) > 0 &&
                        !decls.empty())
                    {
                        CompilerType module_type = ClangASTContext::GetTypeForDecl(decls.front());
                        result = true;
                        std::unique_ptr<Language::TypeScavenger::Result> result(new ObjCScavengerResult(module_type));
                        results.insert(std::move(result));
                    }
                }
            }
            
            if (!result)
            {
                Process* process = exe_scope->CalculateProcess().get();
                if (process)
                {
                    const bool create_on_demand = false;
                    auto objc_runtime = process->GetObjCLanguageRuntime(create_on_demand);
                    if (objc_runtime)
                    {
                        auto decl_vendor = objc_runtime->GetDeclVendor();
                        if (decl_vendor)
                        {
                            std::vector<clang::NamedDecl *> decls;
                            ConstString name(key);
                            decl_vendor->FindDecls(name, true, UINT32_MAX, decls);
                            for (auto decl : decls)
                            {
                                if (decl)
                                {
                                    if (CompilerType candidate = ClangASTContext::GetTypeForDecl(decl))
                                    {
                                        result = true;
                                        std::unique_ptr<Language::TypeScavenger::Result> result(new ObjCScavengerResult(candidate));
                                        results.insert(std::move(result));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return result;
        }
Example #4
0
ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope,
                                              ClangExpression &expr) :
    m_expr (expr),
    m_compiler (),
    m_code_generator (NULL),
    m_execution_engine (),
    m_jitted_functions ()
{
    // Initialize targets first, so that --version shows registered targets.
    static struct InitializeLLVM {
        InitializeLLVM() {
            llvm::InitializeAllTargets();
            llvm::InitializeAllAsmPrinters();
        }
    } InitializeLLVM;
        
    // 1. Create a new compiler instance.
    m_compiler.reset(new CompilerInstance());    
    m_compiler->setLLVMContext(new LLVMContext());
    
    // 2. Set options.
    
    // Parse expressions as Objective C++ regardless of context.
    // Our hook into Clang's lookup mechanism only works in C++.
    m_compiler->getLangOpts().CPlusPlus = true;
    
    // Setup objective C
    m_compiler->getLangOpts().ObjC1 = true;
    m_compiler->getLangOpts().ObjC2 = true;
    
    Process *process = NULL;
    if (exe_scope)
        process = exe_scope->CalculateProcess();

    if (process)
    {
        if (process->GetObjCLanguageRuntime())
        {
            if (process->GetObjCLanguageRuntime()->GetRuntimeVersion() == lldb::eAppleObjC_V2)
            {
                m_compiler->getLangOpts().ObjCNonFragileABI = true;     // NOT i386
                m_compiler->getLangOpts().ObjCNonFragileABI2 = true;    // NOT i386
            }
        }
    }

    m_compiler->getLangOpts().ThreadsafeStatics = false;
    m_compiler->getLangOpts().AccessControl = false; // Debuggers get universal access
    m_compiler->getLangOpts().DollarIdents = true; // $ indicates a persistent variable name
    
    // Set CodeGen options
    m_compiler->getCodeGenOpts().EmitDeclMetadata = true;
    m_compiler->getCodeGenOpts().InstrumentFunctions = false;
    
    // Disable some warnings.
    m_compiler->getDiagnosticOpts().Warnings.push_back("no-unused-value");
    
    // Set the target triple.
    Target *target = NULL;
    if (exe_scope)
        target = exe_scope->CalculateTarget();

    // TODO: figure out what to really do when we don't have a valid target.
    // Sometimes this will be ok to just use the host target triple (when we
    // evaluate say "2+3", but other expressions like breakpoint conditions
    // and other things that _are_ target specific really shouldn't just be 
    // using the host triple. This needs to be fixed in a better way.
    if (target && target->GetArchitecture().IsValid())
        m_compiler->getTargetOpts().Triple = target->GetArchitecture().GetTriple().str();
    else
        m_compiler->getTargetOpts().Triple = llvm::sys::getHostTriple();
    
    // 3. Set up various important bits of infrastructure.
    m_compiler->createDiagnostics(0, 0);
    
    // Create the target instance.
    m_compiler->setTarget(TargetInfo::CreateTargetInfo(m_compiler->getDiagnostics(),
                                                       m_compiler->getTargetOpts()));
    
    assert (m_compiler->hasTarget());
    
    // Inform the target of the language options
    //
    // FIXME: We shouldn't need to do this, the target should be immutable once
    // created. This complexity should be lifted elsewhere.
    m_compiler->getTarget().setForcedLangOptions(m_compiler->getLangOpts());
    
    // 4. Set up the diagnostic buffer for reporting errors
    
    m_compiler->getDiagnostics().setClient(new clang::TextDiagnosticBuffer);
    
    // 5. Set up the source management objects inside the compiler
    
    clang::FileSystemOptions file_system_options;
    m_file_manager.reset(new clang::FileManager(file_system_options));
    
    if (!m_compiler->hasSourceManager())
        m_compiler->createSourceManager(*m_file_manager.get());
    
    m_compiler->createFileManager();
    m_compiler->createPreprocessor();
    
    // 6. Most of this we get from the CompilerInstance, but we 
    // also want to give the context an ExternalASTSource.
    m_selector_table.reset(new SelectorTable());
    m_builtin_context.reset(new Builtin::Context(m_compiler->getTarget()));
    
    std::auto_ptr<clang::ASTContext> ast_context(new ASTContext(m_compiler->getLangOpts(),
                                                                m_compiler->getSourceManager(),
                                                                m_compiler->getTarget(),
                                                                m_compiler->getPreprocessor().getIdentifierTable(),
                                                                *m_selector_table.get(),
                                                                *m_builtin_context.get(),
                                                                0));
    
    ClangExpressionDeclMap *decl_map = m_expr.DeclMap();
    
    if (decl_map)
    {
        OwningPtr<clang::ExternalASTSource> ast_source(new ClangASTSource(*ast_context, *decl_map));
        ast_context->setExternalSource(ast_source);
    }
    
    m_compiler->setASTContext(ast_context.release());
    
    std::string module_name("$__lldb_module");

    m_code_generator.reset(CreateLLVMCodeGen(m_compiler->getDiagnostics(),
                                             module_name,
                                             m_compiler->getCodeGenOpts(),
                                             m_compiler->getLLVMContext()));
}