[Lldb-commits] [lldb] r249027 - Made Target hold a map of languages to TypeSystems, and added some accessors.

Sean Callanan via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 1 09:28:03 PDT 2015


Author: spyffe
Date: Thu Oct  1 11:28:02 2015
New Revision: 249027

URL: http://llvm.org/viewvc/llvm-project?rev=249027&view=rev
Log:
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.

Modified:
    lldb/trunk/include/lldb/Target/Target.h
    lldb/trunk/source/Commands/CommandObjectMemory.cpp
    lldb/trunk/source/Core/ValueObject.cpp
    lldb/trunk/source/Expression/UserExpression.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
    lldb/trunk/source/Target/ABI.cpp
    lldb/trunk/source/Target/Target.cpp

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=249027&r1=249026&r2=249027&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Thu Oct  1 11:28:02 2015
@@ -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;

Modified: lldb/trunk/source/Commands/CommandObjectMemory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectMemory.cpp?rev=249027&r1=249026&r2=249027&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectMemory.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectMemory.cpp Thu Oct  1 11:28:02 2015
@@ -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());
+                    }
                 }
             }
             

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=249027&r1=249026&r2=249027&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Thu Oct  1 11:28:02 2015
@@ -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;

Modified: lldb/trunk/source/Expression/UserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/UserExpression.cpp?rev=249027&r1=249026&r2=249027&view=diff
==============================================================================
--- lldb/trunk/source/Expression/UserExpression.cpp (original)
+++ lldb/trunk/source/Expression/UserExpression.cpp Thu Oct  1 11:28:02 2015
@@ -587,7 +587,7 @@ UserExpression::Evaluate (ExecutionConte
 
             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)

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp?rev=249027&r1=249026&r2=249027&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp Thu Oct  1 11:28:02 2015
@@ -464,7 +464,7 @@ ASTResultSynthesizer::MaybeRecordPersist
                                                                  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

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp?rev=249027&r1=249026&r2=249027&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp Thu Oct  1 11:28:02 2015
@@ -104,7 +104,7 @@ ClangExpressionDeclMap::WillParse(Execut
 
     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;

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp?rev=249027&r1=249026&r2=249027&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp Thu Oct  1 11:28:02 2015
@@ -331,7 +331,7 @@ ClangExpressionParser::ClangExpressionPa
     
     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));

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp?rev=249027&r1=249026&r2=249027&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp Thu Oct  1 11:28:02 2015
@@ -357,7 +357,7 @@ ClangUserExpression::Parse (Stream &erro
     
     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)

Modified: lldb/trunk/source/Target/ABI.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ABI.cpp?rev=249027&r1=249026&r2=249027&view=diff
==============================================================================
--- lldb/trunk/source/Target/ABI.cpp (original)
+++ lldb/trunk/source/Target/ABI.cpp Thu Oct  1 11:28:02 2015
@@ -124,7 +124,11 @@ ABI::GetReturnValueObject (Thread &threa
     
     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;

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=249027&r1=249026&r2=249027&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Thu Oct  1 11:28:02 2015
@@ -85,7 +85,6 @@ Target::Target(Debugger &debugger, const
     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_locatio
     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 (c
     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 Cons
 }
 
 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;




More information about the lldb-commits mailing list