diff options
author | Sean Callanan <scallanan@apple.com> | 2015-10-01 16:28:02 +0000 |
---|---|---|
committer | Sean Callanan <scallanan@apple.com> | 2015-10-01 16:28:02 +0000 |
commit | b92bd7538e167ae058eedaa948fcb3a7ceecd5af (patch) | |
tree | d34c87c3f2524f4782343e60e1216239f1b51442 | |
parent | c8b158155c9c829da0412252ef72e823311b82aa (diff) | |
download | bcm5719-llvm-b92bd7538e167ae058eedaa948fcb3a7ceecd5af.tar.gz bcm5719-llvm-b92bd7538e167ae058eedaa948fcb3a7ceecd5af.zip |
Made Target hold a map of languages to TypeSystems, and added some accessors.
Also added some target-level search functions so that persistent variables and
symbols can be searched for without hand-iterating across the map of
TypeSystems.
llvm-svn: 249027
-rw-r--r-- | lldb/include/lldb/Target/Target.h | 14 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectMemory.cpp | 10 | ||||
-rw-r--r-- | lldb/source/Core/ValueObject.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Expression/UserExpression.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Target/ABI.cpp | 6 | ||||
-rw-r--r-- | lldb/source/Target/Target.cpp | 127 |
10 files changed, 139 insertions, 30 deletions
diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 99e7c49ed2c..59319377c8c 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -1231,6 +1231,9 @@ public: TypeSystem * GetScratchTypeSystemForLanguage (lldb::LanguageType language, bool create_on_demand = true); + PersistentExpressionState * + GetPersistentExpressionStateForLanguage (lldb::LanguageType language); + // Creates a UserExpression for the given language, the rest of the parameters have the // same meaning as for the UserExpression constructor. // Returns a new-ed object which the caller owns. @@ -1322,6 +1325,9 @@ public: lldb::ExpressionVariableSP GetPersistentVariable(const ConstString &name); + lldb::addr_t + GetPersistentSymbol(const ConstString &name); + //------------------------------------------------------------------ // Target Stop Hooks //------------------------------------------------------------------ @@ -1499,6 +1505,9 @@ public: GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, const FileSpecList *containingSourceFiles); protected: + ClangASTContext * + GetScratchClangASTContextImpl(); + //------------------------------------------------------------------ // Member variables. //------------------------------------------------------------------ @@ -1519,7 +1528,10 @@ protected: lldb::ProcessSP m_process_sp; lldb::SearchFilterSP m_search_filter_sp; PathMappingList m_image_search_paths; - lldb::ClangASTContextUP m_scratch_ast_context_ap; + + typedef std::map<lldb::LanguageType, lldb::TypeSystemSP> TypeSystemMap; + TypeSystemMap m_scratch_type_system_map; + lldb::ClangASTSourceUP m_scratch_ast_source_ap; lldb::ClangASTImporterUP m_ast_importer_ap; lldb::ClangModulesDeclVendorUP m_clang_modules_decl_vendor_ap; diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index fb800f9ae72..86633891479 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -530,10 +530,14 @@ protected: if (type_list.GetSize() == 0 && lookup_type_name.GetCString() && *lookup_type_name.GetCString() == '$') { - clang::TypeDecl *tdecl = llvm::cast<ClangPersistentVariables>(target->GetScratchTypeSystemForLanguage(lldb::eLanguageTypeC)->GetPersistentExpressionState())->GetPersistentType(ConstString(lookup_type_name)); - if (tdecl) + if (ClangPersistentVariables *persistent_vars = llvm::dyn_cast_or_null<ClangPersistentVariables>(target->GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC))) { - clang_ast_type.SetCompilerType(ClangASTContext::GetASTContext(&tdecl->getASTContext()),(const lldb::opaque_compiler_type_t)tdecl->getTypeForDecl()); + clang::TypeDecl *tdecl = persistent_vars->GetPersistentType(ConstString(lookup_type_name)); + + if (tdecl) + { + clang_ast_type.SetCompilerType(ClangASTContext::GetASTContext(&tdecl->getASTContext()),(const lldb::opaque_compiler_type_t)tdecl->getTypeForDecl()); + } } } diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index 601c172aed7..3b028786b5b 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -4277,7 +4277,7 @@ ValueObject::Persist () if (!target_sp) return nullptr; - PersistentExpressionState *persistent_state = target_sp->GetScratchTypeSystemForLanguage(GetPreferredDisplayLanguage())->GetPersistentExpressionState(); + PersistentExpressionState *persistent_state = target_sp->GetPersistentExpressionStateForLanguage(GetPreferredDisplayLanguage()); if (!persistent_state) return nullptr; diff --git a/lldb/source/Expression/UserExpression.cpp b/lldb/source/Expression/UserExpression.cpp index a493cc80d88..7e0446f507c 100644 --- a/lldb/source/Expression/UserExpression.cpp +++ b/lldb/source/Expression/UserExpression.cpp @@ -587,7 +587,7 @@ UserExpression::Evaluate (ExecutionContext &exe_ctx, if (options.GetResultIsInternal() && expr_result && process) { - process->GetTarget().GetScratchTypeSystemForLanguage(lldb::eLanguageTypeC)->GetPersistentExpressionState()->RemovePersistentVariable (expr_result); + process->GetTarget().GetPersistentExpressionStateForLanguage(language)->RemovePersistentVariable (expr_result); } if (execution_results != lldb::eExpressionCompleted) diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp index 7845d04f01f..02505bde240 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp @@ -464,7 +464,7 @@ ASTResultSynthesizer::MaybeRecordPersistentType(TypeDecl *D) D); if (TypeDecl *TypeDecl_scratch = dyn_cast<TypeDecl>(D_scratch)) - llvm::cast<ClangPersistentVariables>(m_target.GetScratchTypeSystemForLanguage(lldb::eLanguageTypeC)->GetPersistentExpressionState())->RegisterPersistentType(name_cs, TypeDecl_scratch); + llvm::cast<ClangPersistentVariables>(m_target.GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC))->RegisterPersistentType(name_cs, TypeDecl_scratch); } void diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp index 40fb6c8b0a7..4356297acd9 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp @@ -104,7 +104,7 @@ ClangExpressionDeclMap::WillParse(ExecutionContext &exe_ctx, if (target) { - m_parser_vars->m_persistent_vars = llvm::cast<ClangPersistentVariables>(target->GetScratchTypeSystemForLanguage(eLanguageTypeC)->GetPersistentExpressionState()); + m_parser_vars->m_persistent_vars = llvm::cast<ClangPersistentVariables>(target->GetPersistentExpressionStateForLanguage(eLanguageTypeC)); if (!target->GetScratchClangASTContext()) return false; diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp index af148b4e761..729c50ebdbb 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp @@ -331,7 +331,7 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope, if (ClangModulesDeclVendor *decl_vendor = target_sp->GetClangModulesDeclVendor()) { - ClangPersistentVariables *clang_persistent_vars = llvm::cast<ClangPersistentVariables>(target_sp->GetScratchTypeSystemForLanguage(lldb::eLanguageTypeC)->GetPersistentExpressionState()); + ClangPersistentVariables *clang_persistent_vars = llvm::cast<ClangPersistentVariables>(target_sp->GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC)); std::unique_ptr<PPCallbacks> pp_callbacks(new LLDBPreprocessorCallbacks(*decl_vendor, *clang_persistent_vars)); m_pp_callbacks = static_cast<LLDBPreprocessorCallbacks*>(pp_callbacks.get()); m_compiler->getPreprocessor().addPPCallbacks(std::move(pp_callbacks)); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp index c5e125fc07d..c32ad579fd3 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp @@ -357,7 +357,7 @@ ClangUserExpression::Parse (Stream &error_stream, if (ClangModulesDeclVendor *decl_vendor = m_target->GetClangModulesDeclVendor()) { - const ClangModulesDeclVendor::ModuleVector &hand_imported_modules = llvm::cast<ClangPersistentVariables>(m_target->GetScratchTypeSystemForLanguage(lldb::eLanguageTypeC)->GetPersistentExpressionState())->GetHandLoadedClangModules(); + const ClangModulesDeclVendor::ModuleVector &hand_imported_modules = llvm::cast<ClangPersistentVariables>(m_target->GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC))->GetHandLoadedClangModules(); ClangModulesDeclVendor::ModuleVector modules_for_macros; for (ClangModulesDeclVendor::ModuleID module : hand_imported_modules) diff --git a/lldb/source/Target/ABI.cpp b/lldb/source/Target/ABI.cpp index 6bee1c44f22..b2334d6abb8 100644 --- a/lldb/source/Target/ABI.cpp +++ b/lldb/source/Target/ABI.cpp @@ -124,7 +124,11 @@ ABI::GetReturnValueObject (Thread &thread, if (persistent) { - PersistentExpressionState *persistent_expression_state = thread.CalculateTarget()->GetScratchTypeSystemForLanguage(ast_type.GetMinimumLanguage())->GetPersistentExpressionState(); + PersistentExpressionState *persistent_expression_state = thread.CalculateTarget()->GetPersistentExpressionStateForLanguage(ast_type.GetMinimumLanguage()); + + if (!persistent_expression_state) + return ValueObjectSP(); + ConstString persistent_variable_name (persistent_expression_state->GetNextPersistentVariableName()); lldb::ValueObjectSP const_valobj_sp; diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index e3889b2276a..015b3850292 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -85,7 +85,6 @@ Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::Plat m_process_sp (), m_search_filter_sp (), m_image_search_paths (ImageSearchPathsChanged, this), - m_scratch_ast_context_ap (), m_scratch_ast_source_ap (), m_ast_importer_ap (), m_source_manager_ap(), @@ -1123,7 +1122,7 @@ Target::ClearModules(bool delete_locations) ModulesDidUnload (m_images, delete_locations); m_section_load_history.Clear(); m_images.Clear(); - m_scratch_ast_context_ap.reset(); + m_scratch_type_system_map.clear(); m_scratch_ast_source_ap.reset(); m_ast_importer_ap.reset(); } @@ -1893,14 +1892,56 @@ Target::ImageSearchPathsChanged TypeSystem * Target::GetScratchTypeSystemForLanguage (lldb::LanguageType language, bool create_on_demand) { + Mutex::Locker locker (m_mutex); + + if (language == eLanguageTypeMipsAssembler // GNU AS and LLVM use it for all assembly code + || language == eLanguageTypeUnknown) { + language = eLanguageTypeC; + } + + TypeSystemMap::iterator pos = m_scratch_type_system_map.find(language); + + if (pos != m_scratch_type_system_map.end()) + return pos->second.get(); + + for (const auto &pair : m_scratch_type_system_map) + { + if (pair.second && pair.second->SupportsLanguage(language)) + { + // Add a new mapping for "language" to point to an already existing + // TypeSystem that supports this language + m_scratch_type_system_map[language] = pair.second; + return pair.second.get(); + } + } + + if (!create_on_demand) + return nullptr; + if (Language::LanguageIsC(language) || Language::LanguageIsObjC(language) - || Language::LanguageIsCPlusPlus(language) - || language == eLanguageTypeMipsAssembler // GNU AS and LLVM use it for all assembly code - || language == eLanguageTypeUnknown) - return GetScratchClangASTContext(create_on_demand); + || Language::LanguageIsCPlusPlus(language)) + { + m_scratch_type_system_map[language].reset(GetScratchClangASTContextImpl()); + return m_scratch_type_system_map[language].get(); + } + + return nullptr; +} + +PersistentExpressionState * +Target::GetPersistentExpressionStateForLanguage (lldb::LanguageType language) +{ + TypeSystem *type_system = GetScratchTypeSystemForLanguage(language, true); + + if (type_system) + { + return type_system->GetPersistentExpressionState(); + } else - return NULL; + { + return nullptr; + } } UserExpression * @@ -1972,20 +2013,30 @@ Target::GetUtilityFunctionForLanguage (const char *text, return utility_fn; } - ClangASTContext * Target::GetScratchClangASTContext(bool create_on_demand) { - // Now see if we know the target triple, and if so, create our scratch AST context: - if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand) + if (TypeSystem* type_system = GetScratchTypeSystemForLanguage(eLanguageTypeC, create_on_demand)) { - m_scratch_ast_context_ap.reset (new ClangASTContextForExpressions(*this)); - m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this())); - m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext()); - llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy()); - m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source); + return llvm::dyn_cast<ClangASTContext>(type_system); + } + else + { + return nullptr; } - return m_scratch_ast_context_ap.get(); +} + +ClangASTContext * +Target::GetScratchClangASTContextImpl() +{ + ClangASTContextForExpressions *ast_context = new ClangASTContextForExpressions(*this); + + m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this())); + m_scratch_ast_source_ap->InstallASTContext(ast_context->getASTContext()); + llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy()); + ast_context->SetExternalSource(proxy_ast_source); + + return ast_context; } ClangASTImporter * @@ -2144,11 +2195,23 @@ Target::EvaluateExpression lldb::ExpressionVariableSP Target::GetPersistentVariable(const ConstString &name) { - if (ClangASTContext *ast_context = GetScratchClangASTContext(false)) + std::set<TypeSystem *> visited; + + for (const auto &pair : m_scratch_type_system_map) { - if (PersistentExpressionState *persistent_state = ast_context->GetPersistentExpressionState()) + if (pair.second && !visited.count(pair.second.get())) { - return persistent_state->GetVariable(name); + visited.insert(pair.second.get()); + + if (PersistentExpressionState *persistent_state = pair.second->GetPersistentExpressionState()) + { + lldb::ExpressionVariableSP variable_sp = persistent_state->GetVariable(name); + + if (variable_sp) + { + return variable_sp; + } + } } } @@ -2156,6 +2219,32 @@ Target::GetPersistentVariable(const ConstString &name) } lldb::addr_t +Target::GetPersistentSymbol(const ConstString &name) +{ + std::set<TypeSystem *> visited; + + for (const auto &pair : m_scratch_type_system_map) + { + if (pair.second && !visited.count(pair.second.get())) + { + visited.insert(pair.second.get()); + + if (PersistentExpressionState *persistent_state = pair.second->GetPersistentExpressionState()) + { + lldb::addr_t address = persistent_state->LookupSymbol(name); + + if (address != LLDB_INVALID_ADDRESS) + { + return address; + } + } + } + } + + return LLDB_INVALID_ADDRESS; +} + +lldb::addr_t Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const { addr_t code_addr = load_addr; |