[Lldb-commits] [lldb] r141888 - in /lldb/trunk: include/lldb/Expression/ClangASTSource.h include/lldb/Symbol/ClangASTImporter.h source/Expression/ClangExpressionDeclMap.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Sean Callanan scallanan at apple.com
Thu Oct 13 14:08:11 PDT 2011


Author: spyffe
Date: Thu Oct 13 16:08:11 2011
New Revision: 141888

URL: http://llvm.org/viewvc/llvm-project?rev=141888&view=rev
Log:
Moved the list of found namespaces into the search
context object.  Having it populated and registered
within a single FindExternalVisibleDecls call worked
fine when there was only one call (i.e., when we were
just looking in the global namespace).  

However, now FindExternalVisibleDecls is called for
nested namespaces as well, which means that it is
called not once but many times (once per module in
which the parent namespace appears).  This means that
the namespace mapping is built up across many calls
to the inferior FindExternalVisibleDecls, so I moved
it into a data structure (the search context) that is
shared by all calls.

I also added some logging to make it easier to see
what is happening during a namespace search, and 
cleaned up some existing logging.

Modified:
    lldb/trunk/include/lldb/Expression/ClangASTSource.h
    lldb/trunk/include/lldb/Symbol/ClangASTImporter.h
    lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Modified: lldb/trunk/include/lldb/Expression/ClangASTSource.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangASTSource.h?rev=141888&r1=141887&r2=141888&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangASTSource.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangASTSource.h Thu Oct 13 16:08:11 2011
@@ -14,6 +14,7 @@
 
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/AST/ExternalASTSource.h"
+#include "lldb/Symbol/ClangASTImporter.h"
 
 namespace lldb_private {
     
@@ -182,6 +183,7 @@
 struct NameSearchContext {
     ClangASTSource &m_ast_source;                       ///< The AST source making the request
     llvm::SmallVectorImpl<clang::NamedDecl*> &m_decls;  ///< The list of declarations already constructed
+    ClangASTImporter::NamespaceMapSP m_namespace_map;   ///< The mapping of all namespaces found for this request back to their modules
     const clang::DeclarationName &m_decl_name;          ///< The name being looked for
     const clang::DeclContext *m_decl_context;           ///< The DeclContext to put declarations into
     

Modified: lldb/trunk/include/lldb/Symbol/ClangASTImporter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTImporter.h?rev=141888&r1=141887&r2=141888&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTImporter.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTImporter.h Thu Oct 13 16:08:11 2011
@@ -63,7 +63,7 @@
         return origin.Valid();
     }
     
-    typedef std::map<lldb::ModuleSP, ClangNamespaceDecl> NamespaceMap;
+    typedef std::vector < std::pair<lldb::ModuleSP, ClangNamespaceDecl> > NamespaceMap;
     typedef lldb::SharedPtr<NamespaceMap>::Type NamespaceMapSP;
     
     void RegisterNamespaceMap(const clang::NamespaceDecl *decl, 

Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=141888&r1=141887&r2=141888&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Thu Oct 13 16:08:11 2011
@@ -2051,17 +2051,22 @@
         else
             log->Printf("FindExternalVisibleDecls for '%s' in a '%s'", name.GetCString(), context.m_decl_context->getDeclKindName());
     }
+    
+    context.m_namespace_map.reset(new ClangASTImporter::NamespaceMap);
         
     if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(context.m_decl_context))
     {
         ClangASTImporter::NamespaceMapSP namespace_map = m_parser_vars->m_ast_importer->GetNamespaceMap(namespace_context);
-                
+        
+        if (log)
+            log->Printf("Inspecting namespace map %p (%d entries)", namespace_map.get(), (int)namespace_map->size());
+        
         for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end();
              i != e;
              ++i)
         {
             if (log)
-                log->Printf("  Searching namespace '%s' in file '%s'",
+                log->Printf("  Searching namespace %s in module %s",
                             i->second.GetNamespaceDecl()->getNameAsString().c_str(),
                             i->first->GetFileSpec().GetFilename().GetCString());
                 
@@ -2088,6 +2093,17 @@
                                  namespace_decl,
                                  name);
     }
+    
+    if (!context.m_namespace_map->empty())
+    {
+        if (log)
+            log->Printf("Registering namespace map %p (%d entries)", context.m_namespace_map.get(), (int)context.m_namespace_map->size());
+        
+        NamespaceDecl *clang_namespace_decl = AddNamespace(context, context.m_namespace_map);
+        
+        if (clang_namespace_decl)
+            clang_namespace_decl->setHasExternalVisibleStorage();
+    }
 }
 
 void 
@@ -2410,52 +2426,63 @@
             }
         }
         
-        ModuleList &images = m_parser_vars->m_sym_ctx.target_sp->GetImages();
-        
-        ClangASTImporter::NamespaceMapSP namespace_decls(new ClangASTImporter::NamespaceMap);
-        
-        for (uint32_t i = 0, e = images.GetSize();
-             i != e;
-             ++i)
+        if (module_sp && namespace_decl)
         {
-            ModuleSP image = images.GetModuleAtIndex(i);
-            
-            if (!image)
-                continue;
-            
-            ClangNamespaceDecl namespace_decl;
-            
-            SymbolVendor *symbol_vendor = image->GetSymbolVendor();
-                
-            if (!symbol_vendor)
-                continue;
+            ClangNamespaceDecl found_namespace_decl;
             
-            SymbolContext null_sc;
+            SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor();
             
-            namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl);
-
-            if (namespace_decl)
+            if (symbol_vendor)
             {
-                (*namespace_decls)[image] = namespace_decl;
+                SymbolContext null_sc;
                 
-                if (log)
-                {                
-                    std::string s;
-                    llvm::raw_string_ostream os(s);
-                    namespace_decl.GetNamespaceDecl()->print(os);
-                    os.flush();
+                found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl);
+                
+                if (found_namespace_decl)
+                {
+                    context.m_namespace_map->push_back(std::pair<ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl));
                     
-                    log->Printf("Found namespace %s in file %s", s.c_str(), image->GetFileSpec().GetFilename().GetCString());
+                    if (log)
+                        log->Printf("Found namespace %s in module %s", 
+                                    name.GetCString(), 
+                                    module_sp->GetFileSpec().GetFilename().GetCString());
                 }
             }
         }
-        
-        if (!namespace_decls->empty())
+        else 
         {
-            NamespaceDecl *clang_namespace_decl = AddNamespace(context, namespace_decls);
-            
-            if (clang_namespace_decl)
-                clang_namespace_decl->setHasExternalVisibleStorage();
+            ModuleList &images = m_parser_vars->m_sym_ctx.target_sp->GetImages();
+                        
+            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, &namespace_decl);
+                
+                if (found_namespace_decl)
+                {
+                    context.m_namespace_map->push_back(std::pair<ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl));
+                    
+                    if (log)
+                        log->Printf("Found namespace %s in module %s", 
+                                    name.GetCString(), 
+                                    image->GetFileSpec().GetFilename().GetCString());
+                }
+            }
         }
     }    
     

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=141888&r1=141887&r2=141888&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Thu Oct 13 16:08:11 2011
@@ -1966,6 +1966,11 @@
         return true;    // The ASTs match, return true
     
     // The namespace AST was valid, and it does not match...
+    LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
+
+    if (log)
+        log->Printf("Valid namespace does not match symbol file");
+    
     return false;
 }
 
@@ -2693,7 +2698,7 @@
     
     if (log)
     {
-        log->Printf ("SymbolFileDWARF::FindFunctions (file=\"%s/%s\", sc, name=\"%s\", append=%u, max_matches=%u, type_list)", 
+        log->Printf ("SymbolFileDWARF::FindTypes (file=\"%s/%s\", sc, name=\"%s\", append=%u, max_matches=%u, type_list)", 
                      m_obj_file->GetFileSpec().GetDirectory().GetCString(),
                      m_obj_file->GetFileSpec().GetFilename().GetCString(),
                      name.GetCString(), append, max_matches);





More information about the lldb-commits mailing list