From 8a98287f255b974a8636c50a662e13ad61a59446 Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Wed, 3 Aug 2022 17:09:40 -0700 Subject: [PATCH] [lldb][NFCish] Move DWARFDebugInfoEntry::GetQualifiedName() into DWARFASTParserClang In D134378, we'll need the clang AST to be able to construct the qualified in some cases. This makes logging in one place slightly less informative. Reviewed By: dblaikie, Michael137 Differential Revision: https://reviews.llvm.org/D135979 --- .../SymbolFile/DWARF/DWARFASTParserClang.cpp | 53 ++++++++++++++++++- .../Plugins/SymbolFile/DWARF/DWARFASTParserClang.h | 3 ++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp | 7 --- lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h | 2 - .../SymbolFile/DWARF/DWARFDebugInfoEntry.cpp | 60 ---------------------- .../Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h | 5 -- .../Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp | 4 +- 7 files changed, 55 insertions(+), 79 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index 988dc02..3f2614a 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -1523,6 +1523,55 @@ TypeSP DWARFASTParserClang::UpdateSymbolContextScopeForType( return type_sp; } +std::string +DWARFASTParserClang::GetCPlusPlusQualifiedName(const DWARFDIE &die) { + if (!die.IsValid()) + return ""; + const char *name = die.GetName(); + if (!name) + return ""; + std::string qualified_name; + DWARFDIE parent_decl_ctx_die = die.GetParentDeclContextDIE(); + // TODO: change this to get the correct decl context parent.... + while (parent_decl_ctx_die) { + const dw_tag_t parent_tag = parent_decl_ctx_die.Tag(); + switch (parent_tag) { + case DW_TAG_namespace: { + if (const char *namespace_name = parent_decl_ctx_die.GetName()) { + qualified_name.insert(0, "::"); + qualified_name.insert(0, namespace_name); + } else { + qualified_name.insert(0, "(anonymous namespace)::"); + } + parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE(); + break; + } + + case DW_TAG_class_type: + case DW_TAG_structure_type: + case DW_TAG_union_type: { + if (const char *class_union_struct_name = parent_decl_ctx_die.GetName()) { + qualified_name.insert(0, "::"); + qualified_name.insert(0, class_union_struct_name); + } + parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE(); + break; + } + + default: + parent_decl_ctx_die.Clear(); + break; + } + } + + if (qualified_name.empty()) + qualified_name.append("::"); + + qualified_name.append(name); + + return qualified_name; +} + TypeSP DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc, const DWARFDIE &die, @@ -1548,8 +1597,8 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc, // For C++, we rely solely upon the one definition rule that says // only one thing can exist at a given decl context. We ignore the // file and line that things are declared on. - std::string qualified_name; - if (die.GetQualifiedName(qualified_name)) + std::string qualified_name = GetCPlusPlusQualifiedName(die); + if (!qualified_name.empty()) unique_typename = ConstString(qualified_name); unique_decl.Clear(); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h index a8640b4..860e5f4 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h @@ -121,11 +121,14 @@ protected: bool ParseTemplateDIE(const DWARFDIE &die, lldb_private::TypeSystemClang::TemplateParameterInfos &template_param_infos); + bool ParseTemplateParameterInfos( const DWARFDIE &parent_die, lldb_private::TypeSystemClang::TemplateParameterInfos &template_param_infos); + std::string GetCPlusPlusQualifiedName(const DWARFDIE &die); + bool ParseChildMembers( const DWARFDIE &die, lldb_private::CompilerType &class_compiler_type, std::vector> &base_classes, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp index e849207..7b9da6f 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp @@ -210,13 +210,6 @@ const char *DWARFDIE::GetPubname() const { return nullptr; } -const char *DWARFDIE::GetQualifiedName(std::string &storage) const { - if (IsValid()) - return m_die->GetQualifiedName(m_cu, storage); - else - return nullptr; -} - // GetName // // Get value of the DW_AT_name attribute and place that value into the supplied diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h index 7ce9550..3564f75 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h @@ -30,8 +30,6 @@ public: const char *GetPubname() const; - const char *GetQualifiedName(std::string &storage) const; - using DWARFBaseDIE::GetName; void GetName(lldb_private::Stream &s) const; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp index 5a584e1..c10eae3 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp @@ -798,66 +798,6 @@ DWARFDebugInfoEntry::GetParentDeclContextDIE( return DWARFDIE(); } -const char *DWARFDebugInfoEntry::GetQualifiedName(DWARFUnit *cu, - std::string &storage) const { - DWARFAttributes attributes; - GetAttributes(cu, attributes, Recurse::yes); - return GetQualifiedName(cu, attributes, storage); -} - -const char * -DWARFDebugInfoEntry::GetQualifiedName(DWARFUnit *cu, - const DWARFAttributes &attributes, - std::string &storage) const { - - const char *name = GetName(cu); - - if (name) { - DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE(cu); - storage.clear(); - // TODO: change this to get the correct decl context parent.... - while (parent_decl_ctx_die) { - const dw_tag_t parent_tag = parent_decl_ctx_die.Tag(); - switch (parent_tag) { - case DW_TAG_namespace: { - const char *namespace_name = parent_decl_ctx_die.GetName(); - if (namespace_name) { - storage.insert(0, "::"); - storage.insert(0, namespace_name); - } else { - storage.insert(0, "(anonymous namespace)::"); - } - parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE(); - } break; - - case DW_TAG_class_type: - case DW_TAG_structure_type: - case DW_TAG_union_type: { - const char *class_union_struct_name = parent_decl_ctx_die.GetName(); - - if (class_union_struct_name) { - storage.insert(0, "::"); - storage.insert(0, class_union_struct_name); - } - parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE(); - } break; - - default: - parent_decl_ctx_die.Clear(); - break; - } - } - - if (storage.empty()) - storage.append("::"); - - storage.append(name); - } - if (storage.empty()) - return nullptr; - return storage.c_str(); -} - lldb::offset_t DWARFDebugInfoEntry::GetFirstAttributeOffset() const { return GetOffset() + llvm::getULEB128Size(m_abbr_idx); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h index 63d6aa7..de34dc5 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h @@ -99,11 +99,6 @@ public: const char *GetPubname(const DWARFUnit *cu) const; - const char *GetQualifiedName(DWARFUnit *cu, std::string &storage) const; - - const char *GetQualifiedName(DWARFUnit *cu, const DWARFAttributes &attributes, - std::string &storage) const; - bool GetDIENamesAndRanges( DWARFUnit *cu, const char *&name, const char *&mangled, DWARFRangeList &rangeList, int &decl_file, int &decl_line, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index 06c1245..d029e4d 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -2960,8 +2960,6 @@ TypeSP SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext( if (!try_resolving_type) { if (log) { - std::string qualified_name; - type_die.GetQualifiedName(qualified_name); GetObjectFile()->GetModule()->LogMessage( log, "SymbolFileDWARF::" @@ -2969,7 +2967,7 @@ TypeSP SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext( "qualified-name='%s') ignoring die=0x%8.8x (%s)", DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), dwarf_decl_ctx.GetQualifiedName(), type_die.GetOffset(), - qualified_name.c_str()); + type_die.GetName()); } return true; } -- 2.7.4