diff options
author | Greg Clayton <gclayton@apple.com> | 2011-10-14 21:34:45 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2011-10-14 21:34:45 +0000 |
commit | 030a204664a8f13fb59c765aa5aa4d1e3aa013cd (patch) | |
tree | 7a317a0005d34e2b522d835f95b66928b4521a46 | |
parent | 1ac5da10173fa5fe2ec4a63c761c0f1a7b6832ad (diff) | |
download | bcm5719-llvm-030a204664a8f13fb59c765aa5aa4d1e3aa013cd.tar.gz bcm5719-llvm-030a204664a8f13fb59c765aa5aa4d1e3aa013cd.zip |
Make sure we create only unique one namespace per AST when parsing the DWARF.
llvm-svn: 142005
-rw-r--r-- | lldb/include/lldb/Symbol/ClangASTContext.h | 1 | ||||
-rw-r--r-- | lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp | 11 | ||||
-rw-r--r-- | lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp | 53 | ||||
-rw-r--r-- | lldb/source/Symbol/ClangASTContext.cpp | 22 |
4 files changed, 57 insertions, 30 deletions
diff --git a/lldb/include/lldb/Symbol/ClangASTContext.h b/lldb/include/lldb/Symbol/ClangASTContext.h index 801d8e22849..27bccbb4083 100644 --- a/lldb/include/lldb/Symbol/ClangASTContext.h +++ b/lldb/include/lldb/Symbol/ClangASTContext.h @@ -540,7 +540,6 @@ public: clang::NamespaceDecl * GetUniqueNamespaceDeclaration (const char *name, - const Declaration &decl, clang::DeclContext *decl_ctx); //------------------------------------------------------------------ diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp index bcce74c60c9..a20424581bd 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp @@ -1145,11 +1145,12 @@ DWARFDebugInfoEntry::DumpLocation 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>"); } //---------------------------------------------------------------------- diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index 4c67d14f911..d2f0311d843 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -3313,16 +3313,41 @@ SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_of 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 @@ SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const D 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: diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp index 5e0e28e076a..3fc15a36fd4 100644 --- a/lldb/source/Symbol/ClangASTContext.cpp +++ b/lldb/source/Symbol/ClangASTContext.cpp @@ -4115,18 +4115,30 @@ ClangASTContext::GetDeclContextForType (clang_type_t clang_type) #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; } |