[Lldb-commits] [lldb] r142005 - in /lldb/trunk: include/lldb/Symbol/ClangASTContext.h source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp source/Symbol/ClangASTContext.cpp

Greg Clayton gclayton at apple.com
Fri Oct 14 14:34:45 PDT 2011


Author: gclayton
Date: Fri Oct 14 16:34:45 2011
New Revision: 142005

URL: http://llvm.org/viewvc/llvm-project?rev=142005&view=rev
Log:
Make sure we create only unique one namespace per AST when parsing the DWARF.


Modified:
    lldb/trunk/include/lldb/Symbol/ClangASTContext.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/trunk/source/Symbol/ClangASTContext.cpp

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=142005&r1=142004&r2=142005&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Fri Oct 14 16:34:45 2011
@@ -540,7 +540,6 @@
 
     clang::NamespaceDecl *
     GetUniqueNamespaceDeclaration (const char *name,
-                                   const Declaration &decl,
                                    clang::DeclContext *decl_ctx);
 
     //------------------------------------------------------------------

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp?rev=142005&r1=142004&r2=142005&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp Fri Oct 14 16:34:45 2011
@@ -1145,11 +1145,12 @@
     if (obj_file)
         obj_file_name = obj_file->GetFileSpec().GetFilename().AsCString();
     const char *die_name = GetName (dwarf2Data, cu);
-    s.Printf ("CU: %s OBJFILE: %s DIE: %s (0x%x).", 
-                cu_name ? cu_name : "<UNKNOWN>",
-                obj_file_name ? obj_file_name : "<UNKNOWN>",
-                die_name ? die_name : "<NO NAME>", 
-                GetOffset());
+    s.Printf ("0x%8.8x/0x%8.8x: %-30s (from %s in %s)", 
+              cu->GetOffset(),
+              GetOffset(),
+              die_name ? die_name : "", 
+              cu_name ? cu_name : "<NULL>",
+              obj_file_name ? obj_file_name : "<NULL>");
 }
 
 //----------------------------------------------------------------------

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=142005&r1=142004&r2=142005&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Fri Oct 14 16:34:45 2011
@@ -3313,16 +3313,41 @@
 clang::NamespaceDecl *
 SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
 {
-    if (die->Tag() == DW_TAG_namespace)
+    if (die && die->Tag() == DW_TAG_namespace)
     {
-        const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
-        if (namespace_name)
-        {
-            Declaration decl;   // TODO: fill in the decl object
-            clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextContainingDIE (curr_cu, die->GetParent(), NULL));
-            if (namespace_decl)
-                LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
+        // See if we already parsed this namespace DIE and associated it with a
+        // uniqued namespace declaration
+        clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
+        if (namespace_decl)
             return namespace_decl;
+        else
+        {
+            const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
+            if (namespace_name)
+            {
+                clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (curr_cu, die, NULL);            
+                namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
+                LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
+                if (log)
+                {
+                    const char *object_name = m_obj_file->GetModule()->GetObjectName().GetCString();
+                    log->Printf ("ASTContext => %p: 0x%8.8x: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl * %p in %s/%s%s%s%s (original = %p)", 
+                                 GetClangASTContext().getASTContext(),
+                                 die->GetOffset(),
+                                 namespace_name,
+                                 namespace_decl,
+                                 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
+                                 m_obj_file->GetFileSpec().GetFilename().GetCString(),
+                                 object_name ? "(" : "",
+                                 object_name ? object_name : "",
+                                 object_name ? "(" : "",
+                                 namespace_decl->getOriginalNamespace());
+                }
+
+                if (namespace_decl)
+                    LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
+                return namespace_decl;
+            }
         }
     }
     return NULL;
@@ -3377,17 +3402,7 @@
             return m_clang_tu_decl;
 
         case DW_TAG_namespace:
-            {
-                const char *namespace_name = decl_ctx_die->GetAttributeValueAsString(this, cu, DW_AT_name, NULL);
-                if (namespace_name)
-                {
-                    Declaration decl;   // TODO: fill in the decl object
-                    clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextContainingDIE (cu, decl_ctx_die, NULL));
-                    if (namespace_decl)
-                        LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, decl_ctx_die);
-                    return namespace_decl;
-                }
-            }
+            return ResolveNamespaceDIE (cu, decl_ctx_die);
             break;
 
         case DW_TAG_structure_type:

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=142005&r1=142004&r2=142005&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Fri Oct 14 16:34:45 2011
@@ -4115,18 +4115,30 @@
 #pragma mark Namespace Declarations
 
 NamespaceDecl *
-ClangASTContext::GetUniqueNamespaceDeclaration (const char *name, const Declaration &decl, DeclContext *decl_ctx)
+ClangASTContext::GetUniqueNamespaceDeclaration (const char *name, DeclContext *decl_ctx)
 {
-    // TODO: Do something intelligent with the Declaration object passed in
-    // like maybe filling in the SourceLocation with it...
+    NamespaceDecl *namespace_decl = NULL;
     if (name)
     {
         ASTContext *ast = getASTContext();
         if (decl_ctx == NULL)
             decl_ctx = ast->getTranslationUnitDecl();
-        return NamespaceDecl::Create(*ast, decl_ctx, SourceLocation(), SourceLocation(), &ast->Idents.get(name));
+        
+        IdentifierInfo &identifier_info = ast->Idents.get(name);
+        DeclarationName decl_name (&identifier_info);
+        clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
+        for (clang::DeclContext::lookup_iterator pos = result.first, end = result.second; pos != end; ++pos) 
+        {
+            namespace_decl = dyn_cast<clang::NamespaceDecl>(*pos);
+            if (namespace_decl)
+                return namespace_decl;
+        }
+
+        namespace_decl = NamespaceDecl::Create(*ast, decl_ctx, SourceLocation(), SourceLocation(), &identifier_info);
+        
+        decl_ctx->addDecl (namespace_decl);
     }
-    return NULL;
+    return namespace_decl;
 }
 
 





More information about the lldb-commits mailing list