diff options
Diffstat (limited to 'lldb')
-rw-r--r-- | lldb/include/lldb/Expression/ClangASTSource.h | 48 | ||||
-rw-r--r-- | lldb/include/lldb/Expression/ClangExpressionDeclMap.h | 38 | ||||
-rw-r--r-- | lldb/source/Expression/ClangASTSource.cpp | 99 | ||||
-rw-r--r-- | lldb/source/Expression/ClangExpressionDeclMap.cpp | 131 | ||||
-rw-r--r-- | lldb/source/Expression/ClangUserExpression.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Expression/ClangUtilityFunction.cpp | 2 |
6 files changed, 157 insertions, 163 deletions
diff --git a/lldb/include/lldb/Expression/ClangASTSource.h b/lldb/include/lldb/Expression/ClangASTSource.h index 4d46a2fbe1d..7c883377d0d 100644 --- a/lldb/include/lldb/Expression/ClangASTSource.h +++ b/lldb/include/lldb/Expression/ClangASTSource.h @@ -15,11 +15,10 @@ #include "clang/Basic/IdentifierTable.h" #include "clang/AST/ExternalASTSource.h" #include "lldb/Symbol/ClangASTImporter.h" +#include "lldb/Target/Target.h" namespace lldb_private { -class ClangExpressionDeclMap; - //---------------------------------------------------------------------- /// @class ClangASTSource ClangASTSource.h "lldb/Expression/ClangASTSource.h" /// @brief Provider for named objects defined in the debug info for Clang @@ -31,7 +30,9 @@ class ClangExpressionDeclMap; /// to Clang for these names, consulting the ClangExpressionDeclMap to do /// the actual lookups. //---------------------------------------------------------------------- -class ClangASTSource : public clang::ExternalASTSource +class ClangASTSource : + public clang::ExternalASTSource, + public ClangASTImporter::NamespaceMapCompleter { public: //------------------------------------------------------------------ @@ -42,11 +43,12 @@ public: /// @param[in] declMap /// A reference to the LLDB object that handles entity lookup. //------------------------------------------------------------------ - ClangASTSource () : + ClangASTSource (const lldb::TargetSP &target) : m_ast_context (NULL), m_active_lookups (), m_import_in_progress (false), - m_lookups_enabled (false) + m_lookups_enabled (false), + m_target (target) { } @@ -69,6 +71,13 @@ public: void InstallASTContext (clang::ASTContext *ast_context) { + if (!m_ast_importer.get() || + m_ast_importer->TargetASTContext() != ast_context) + { + m_ast_importer.reset(new ClangASTImporter(ast_context)); + m_ast_importer->InstallMapCompleter(*this); + } + m_ast_context = ast_context; } @@ -145,6 +154,29 @@ public: void StartTranslationUnit (clang::ASTConsumer *Consumer); // + // APIs for NamespaceMapCompleter + // + + + //------------------------------------------------------------------ + /// Look up the modules containing a given namespace and put the + /// appropriate entries in the namespace map. + /// + /// @param[in] namespace_map + /// The map to be completed. + /// + /// @param[in] name + /// The name of the namespace to be found. + /// + /// @param[in] parent_map + /// The map for the namespace's parent namespace, if there is + /// one. + //------------------------------------------------------------------ + void CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespace_map, + const ConstString &name, + ClangASTImporter::NamespaceMapSP &parent_map) const; + + // // Helper APIs // @@ -223,8 +255,10 @@ protected: bool m_import_in_progress; bool m_lookups_enabled; - clang::ASTContext *m_ast_context; ///< The parser's AST context, for copying types into - std::set<const char *> m_active_lookups; + const lldb::TargetSP m_target; ///< The target to use in finding variables and types. + clang::ASTContext *m_ast_context; ///< The parser's AST context, for copying types into + std::auto_ptr<ClangASTImporter> m_ast_importer; + std::set<const char *> m_active_lookups; }; //---------------------------------------------------------------------- diff --git a/lldb/include/lldb/Expression/ClangExpressionDeclMap.h b/lldb/include/lldb/Expression/ClangExpressionDeclMap.h index a476e3b380c..22ff0d6acd8 100644 --- a/lldb/include/lldb/Expression/ClangExpressionDeclMap.h +++ b/lldb/include/lldb/Expression/ClangExpressionDeclMap.h @@ -58,8 +58,7 @@ namespace lldb_private { /// has executed, placing the new values back where it found the old ones. //---------------------------------------------------------------------- class ClangExpressionDeclMap : - public ClangASTSource, - public ClangASTImporter::NamespaceMapCompleter + public ClangASTSource { public: //------------------------------------------------------------------ @@ -72,7 +71,8 @@ public: /// the result persistent variable, and instead marks the variable /// as persisting. //------------------------------------------------------------------ - ClangExpressionDeclMap (bool keep_result_in_memory); + ClangExpressionDeclMap (bool keep_result_in_memory, + ExecutionContext &exe_ctx); //------------------------------------------------------------------ /// Destructor @@ -663,25 +663,6 @@ public: //------------------------------------------------------------------ void CompleteType (clang::ObjCInterfaceDecl *interface_decl); - - //------------------------------------------------------------------ - /// [Used by ClangASTImporter] Look up the modules containing a - /// given namespace and put the appropriate entries in the namespace - /// map. - /// - /// @param[in] namespace_map - /// The map to be completed. - /// - /// @param[in] name - /// The name of the namespace to be found. - /// - /// @param[in] parent_map - /// The map for the namespace's parent namespace, if there is - /// one. - //------------------------------------------------------------------ - void CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespace_map, - const ConstString &name, - ClangASTImporter::NamespaceMapSP &parent_map) const; private: ClangExpressionVariableList m_found_entities; ///< All entities that were looked up for the parser. @@ -714,19 +695,6 @@ private: return NULL; } - ClangASTImporter *GetASTImporter (clang::ASTContext *ast_context) - { - if (!m_ast_importer.get()) - m_ast_importer.reset(new ClangASTImporter(ast_context)); - - if (m_ast_importer->TargetASTContext() != ast_context) - return NULL; - - m_ast_importer->InstallMapCompleter(m_decl_map); - - return m_ast_importer.get(); - } - ExecutionContext *m_exe_ctx; ///< The execution context to use when parsing. SymbolContext m_sym_ctx; ///< The symbol context to use in finding variables and types. ClangPersistentVariables *m_persistent_vars; ///< The persistent variables for the process. diff --git a/lldb/source/Expression/ClangASTSource.cpp b/lldb/source/Expression/ClangASTSource.cpp index 858bdf0737e..7ed5a5abcb6 100644 --- a/lldb/source/Expression/ClangASTSource.cpp +++ b/lldb/source/Expression/ClangASTSource.cpp @@ -11,9 +11,13 @@ #include "clang/AST/ASTContext.h" #include "lldb/Core/Log.h" #include "lldb/Core/Module.h" +#include "lldb/Core/ModuleList.h" #include "lldb/Expression/ClangASTSource.h" #include "lldb/Expression/ClangExpression.h" #include "lldb/Expression/ClangExpressionDeclMap.h" +#include "lldb/Symbol/ClangNamespaceDecl.h" +#include "lldb/Symbol/SymbolVendor.h" +#include "lldb/Target/Target.h" using namespace clang; using namespace lldb_private; @@ -143,6 +147,101 @@ ClangASTSource::FindExternalLexicalDecls return ELR_Success; } +void +ClangASTSource::CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespace_map, + const ConstString &name, + ClangASTImporter::NamespaceMapSP &parent_map) const +{ + static unsigned int invocation_id = 0; + unsigned int current_id = invocation_id++; + + lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); + + if (log) + { + if (parent_map && parent_map->size()) + log->Printf("CompleteNamespaceMap[%u] Searching for namespace %s in namespace %s", + current_id, + name.GetCString(), + parent_map->begin()->second.GetNamespaceDecl()->getDeclName().getAsString().c_str()); + else + log->Printf("CompleteNamespaceMap[%u] Searching for namespace %s", + current_id, + name.GetCString()); + } + + + if (parent_map) + { + for (ClangASTImporter::NamespaceMap::iterator i = parent_map->begin(), e = parent_map->end(); + i != e; + ++i) + { + ClangNamespaceDecl found_namespace_decl; + + lldb::ModuleSP module_sp = i->first; + ClangNamespaceDecl module_parent_namespace_decl = i->second; + + SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor(); + + if (!symbol_vendor) + continue; + + SymbolContext null_sc; + + found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &module_parent_namespace_decl); + + if (!found_namespace_decl) + continue; + + namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl)); + + if (log) + log->Printf(" CMN[%u] Found namespace %s in module %s", + current_id, + name.GetCString(), + module_sp->GetFileSpec().GetFilename().GetCString()); + } + } + else + { + ModuleList &images = m_target->GetImages(); + ClangNamespaceDecl null_namespace_decl; + + for (uint32_t i = 0, e = images.GetSize(); + i != e; + ++i) + { + lldb::ModuleSP image = images.GetModuleAtIndex(i); + + if (!image) + continue; + + ClangNamespaceDecl found_namespace_decl; + + SymbolVendor *symbol_vendor = image->GetSymbolVendor(); + + if (!symbol_vendor) + continue; + + SymbolContext null_sc; + + found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &null_namespace_decl); + + if (!found_namespace_decl) + continue; + + namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl)); + + if (log) + log->Printf(" CMN[%u] Found namespace %s in module %s", + current_id, + name.GetCString(), + image->GetFileSpec().GetFilename().GetCString()); + } + } +} + clang::NamedDecl * NameSearchContext::AddVarDecl(void *type) { diff --git a/lldb/source/Expression/ClangExpressionDeclMap.cpp b/lldb/source/Expression/ClangExpressionDeclMap.cpp index 6c85831bff0..dc8acbe0700 100644 --- a/lldb/source/Expression/ClangExpressionDeclMap.cpp +++ b/lldb/source/Expression/ClangExpressionDeclMap.cpp @@ -48,7 +48,8 @@ using namespace lldb; using namespace lldb_private; using namespace clang; -ClangExpressionDeclMap::ClangExpressionDeclMap (bool keep_result_in_memory) : +ClangExpressionDeclMap::ClangExpressionDeclMap (bool keep_result_in_memory, ExecutionContext &exe_ctx) : + ClangASTSource (exe_ctx.GetTargetSP()), m_found_entities (), m_struct_members (), m_keep_result_in_memory (keep_result_in_memory), @@ -2128,103 +2129,6 @@ ClangExpressionDeclMap::FindGlobalVariable return VariableSP(); } -// Interface for ClangASTImporter - -void -ClangExpressionDeclMap::CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespace_map, - const ConstString &name, - ClangASTImporter::NamespaceMapSP &parent_map) const -{ - static unsigned int invocation_id = 0; - unsigned int current_id = invocation_id++; - - lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); - - if (log) - { - if (parent_map && parent_map->size()) - log->Printf("CompleteNamespaceMap[%u] Searching for namespace %s in namespace %s", - current_id, - name.GetCString(), - parent_map->begin()->second.GetNamespaceDecl()->getDeclName().getAsString().c_str()); - else - log->Printf("CompleteNamespaceMap[%u] Searching for namespace %s", - current_id, - name.GetCString()); - } - - - if (parent_map) - { - for (ClangASTImporter::NamespaceMap::iterator i = parent_map->begin(), e = parent_map->end(); - i != e; - ++i) - { - ClangNamespaceDecl found_namespace_decl; - - ModuleSP module_sp = i->first; - ClangNamespaceDecl module_parent_namespace_decl = i->second; - - SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor(); - - if (!symbol_vendor) - continue; - - SymbolContext null_sc; - - found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &module_parent_namespace_decl); - - if (!found_namespace_decl) - continue; - - namespace_map->push_back(std::pair<ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl)); - - if (log) - log->Printf(" CMN[%u] Found namespace %s in module %s", - current_id, - name.GetCString(), - module_sp->GetFileSpec().GetFilename().GetCString()); - } - } - else - { - ModuleList &images = m_parser_vars->m_sym_ctx.target_sp->GetImages(); - ClangNamespaceDecl null_namespace_decl; - - for (uint32_t i = 0, e = images.GetSize(); - i != e; - ++i) - { - ModuleSP image = images.GetModuleAtIndex(i); - - if (!image) - continue; - - ClangNamespaceDecl found_namespace_decl; - - SymbolVendor *symbol_vendor = image->GetSymbolVendor(); - - if (!symbol_vendor) - continue; - - SymbolContext null_sc; - - found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &null_namespace_decl); - - if (!found_namespace_decl) - continue; - - namespace_map->push_back(std::pair<ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl)); - - if (log) - log->Printf(" CMN[%u] Found namespace %s in module %s", - current_id, - name.GetCString(), - image->GetFileSpec().GetFilename().GetCString()); - } - } -} - // Interface for ClangASTSource void @@ -2260,7 +2164,7 @@ ClangExpressionDeclMap::FindExternalVisibleDecls (NameSearchContext &context) if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(context.m_decl_context)) { - ClangASTImporter::NamespaceMapSP namespace_map = m_parser_vars->GetASTImporter(m_ast_context)->GetNamespaceMap(namespace_context); + ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer->GetNamespaceMap(namespace_context); if (log && log->GetVerbose()) log->Printf(" FEVD[%u] Inspecting namespace map %p (%d entries)", @@ -2757,9 +2661,7 @@ ClangExpressionDeclMap::FindExternalLexicalDecls (const DeclContext *decl_contex if (!context_decl) return ELR_Failure; - - ASTContext *ast_context = &context_decl->getASTContext(); - + static unsigned int invocation_id = 0; unsigned int current_id = invocation_id++; @@ -2785,12 +2687,7 @@ ClangExpressionDeclMap::FindExternalLexicalDecls (const DeclContext *decl_contex Decl *original_decl = NULL; ASTContext *original_ctx = NULL; - ClangASTImporter *ast_importer = m_parser_vars->GetASTImporter(ast_context); - - if (!ast_importer) - return ELR_Failure; - - if (!ast_importer->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx)) + if (!m_ast_importer->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx)) return ELR_Failure; if (log) @@ -2829,7 +2726,7 @@ ClangExpressionDeclMap::FindExternalLexicalDecls (const DeclContext *decl_contex log->Printf(" FELD[%d] Adding lexical decl %s", current_id, ast_dumper.GetCString()); } - Decl *copied_decl = ast_importer->CopyDecl(original_ctx, decl); + Decl *copied_decl = m_ast_importer->CopyDecl(original_ctx, decl); decls.push_back(copied_decl); } @@ -2853,7 +2750,7 @@ ClangExpressionDeclMap::CompleteType (TagDecl *tag_decl) dumper.ToLog(log, " [CTD] "); } - m_parser_vars->GetASTImporter(&tag_decl->getASTContext())->CompleteTagDecl (tag_decl); + m_ast_importer->CompleteTagDecl (tag_decl); if (log) { @@ -2878,7 +2775,7 @@ ClangExpressionDeclMap::CompleteType (clang::ObjCInterfaceDecl *interface_decl) dumper.ToLog(log, " [COID] "); } - m_parser_vars->GetASTImporter(&interface_decl->getASTContext())->CompleteObjCInterfaceDecl (interface_decl); + m_ast_importer->CompleteObjCInterfaceDecl (interface_decl); if (log) { @@ -3251,12 +3148,11 @@ ClangExpressionDeclMap::AddNamespace (NameSearchContext &context, ClangASTImport const ClangNamespaceDecl &namespace_decl = namespace_decls->begin()->second; - Decl *copied_decl = m_parser_vars->GetASTImporter(m_ast_context)->CopyDecl(namespace_decl.GetASTContext(), - namespace_decl.GetNamespaceDecl()); + Decl *copied_decl = m_ast_importer->CopyDecl(namespace_decl.GetASTContext(), namespace_decl.GetNamespaceDecl()); NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl); - m_parser_vars->GetASTImporter(m_ast_context)->RegisterNamespaceMap(copied_namespace_decl, namespace_decls); + m_ast_importer->RegisterNamespaceMap(copied_namespace_decl, namespace_decls); return dyn_cast<NamespaceDecl>(copied_decl); } @@ -3416,11 +3312,8 @@ ClangExpressionDeclMap::GuardedCopyType (ASTContext *dest_context, assert (m_parser_vars.get()); m_parser_vars->m_ignore_lookups = true; - - lldb_private::ClangASTImporter *importer = m_parser_vars->GetASTImporter(dest_context); - - QualType ret_qual_type = importer->CopyType (source_context, - QualType::getFromOpaquePtr(clang_type)); + + QualType ret_qual_type = m_ast_importer->CopyType (source_context, QualType::getFromOpaquePtr(clang_type)); void *ret = ret_qual_type.getAsOpaquePtr(); diff --git a/lldb/source/Expression/ClangUserExpression.cpp b/lldb/source/Expression/ClangUserExpression.cpp index b5bad503155..7521bcbab61 100644 --- a/lldb/source/Expression/ClangUserExpression.cpp +++ b/lldb/source/Expression/ClangUserExpression.cpp @@ -231,7 +231,7 @@ ClangUserExpression::Parse (Stream &error_stream, m_desired_type = desired_type; - m_expr_decl_map.reset(new ClangExpressionDeclMap(keep_result_in_memory)); + m_expr_decl_map.reset(new ClangExpressionDeclMap(keep_result_in_memory, exe_ctx)); if (!m_expr_decl_map->WillParse(exe_ctx)) { diff --git a/lldb/source/Expression/ClangUtilityFunction.cpp b/lldb/source/Expression/ClangUtilityFunction.cpp index 6f31d4ce26f..7220be8ae6b 100644 --- a/lldb/source/Expression/ClangUtilityFunction.cpp +++ b/lldb/source/Expression/ClangUtilityFunction.cpp @@ -99,7 +99,7 @@ ClangUtilityFunction::Install (Stream &error_stream, bool keep_result_in_memory = false; - m_expr_decl_map.reset(new ClangExpressionDeclMap(keep_result_in_memory)); + m_expr_decl_map.reset(new ClangExpressionDeclMap(keep_result_in_memory, exe_ctx)); m_data_allocator.reset(new ProcessDataAllocator(*process)); |