diff --git a/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt b/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt index 0e47ee34fe51..e4badcbb018f 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt +++ b/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt @@ -21,7 +21,6 @@ add_lldb_library(lldbPluginSymbolFileDWARF PLUGIN DWARFDeclContext.cpp DWARFDefines.cpp DWARFDIE.cpp - DWARFDIECollection.cpp DWARFFormValue.cpp DWARFIndex.cpp DWARFUnit.cpp diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index 1d2398ccc0b7..63617c286ebb 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -10,7 +10,6 @@ #include "DWARFASTParserClang.h" #include "DWARFDIE.h" -#include "DWARFDIECollection.h" #include "DWARFDebugInfo.h" #include "DWARFDeclContext.h" #include "DWARFDefines.h" @@ -1393,7 +1392,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc, DIERef(class_type->GetID(), dwarf)); } if (class_type_die) { - DWARFDIECollection failures; + std::vector failures; CopyUniqueClassMethodTypes(decl_ctx_die, class_type_die, class_type, failures); @@ -2194,7 +2193,7 @@ bool DWARFASTParserClang::CompleteTypeFromDWARF(const DWARFDIE &die, std::vector member_accessibilities; bool is_a_class = false; // Parse members and base classes first - DWARFDIECollection member_function_dies; + std::vector member_function_dies; DelayedPropertyList delayed_properties; ParseChildMembers(sc, die, clang_type, class_language, bases, @@ -2203,12 +2202,8 @@ bool DWARFASTParserClang::CompleteTypeFromDWARF(const DWARFDIE &die, layout_info); // Now parse any methods if there were any... - size_t num_functions = member_function_dies.Size(); - if (num_functions > 0) { - for (size_t i = 0; i < num_functions; ++i) { - dwarf->ResolveType(member_function_dies.GetDIEAtIndex(i)); - } - } + for (const DWARFDIE &die : member_function_dies) + dwarf->ResolveType(die); if (class_language == eLanguageTypeObjC) { ConstString class_name(clang_type.GetTypeName()); @@ -2677,7 +2672,7 @@ bool DWARFASTParserClang::ParseChildMembers( CompilerType &class_clang_type, const LanguageType class_language, std::vector> &base_classes, std::vector &member_accessibilities, - DWARFDIECollection &member_function_dies, + std::vector &member_function_dies, DelayedPropertyList &delayed_properties, AccessType &default_accessibility, bool &is_a_class, ClangASTImporter::LayoutInfo &layout_info) { if (!parent_die) @@ -3176,7 +3171,7 @@ bool DWARFASTParserClang::ParseChildMembers( case DW_TAG_subprogram: // Let the type parsing code handle this one for us. - member_function_dies.Append(die); + member_function_dies.push_back(die); break; case DW_TAG_inheritance: { @@ -3872,7 +3867,7 @@ void DWARFASTParserClang::LinkDeclContextToDIE(clang::DeclContext *decl_ctx, bool DWARFASTParserClang::CopyUniqueClassMethodTypes( const DWARFDIE &src_class_die, const DWARFDIE &dst_class_die, - lldb_private::Type *class_type, DWARFDIECollection &failures) { + lldb_private::Type *class_type, std::vector &failures) { if (!class_type || !src_class_die || !dst_class_die) return false; if (src_class_die.Tag() != dst_class_die.Tag()) @@ -4077,7 +4072,7 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes( log->Printf("warning: couldn't find a match for 0x%8.8x", dst_die.GetOffset()); - failures.Append(dst_die); + failures.push_back(dst_die); } } } @@ -4142,9 +4137,9 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes( "method '%s'", dst_die.GetOffset(), dst_name_artificial.GetCString()); - failures.Append(dst_die); + failures.push_back(dst_die); } } - return (failures.Size() != 0); + return !failures.empty(); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h index 0ad97e5fe5dd..38cd0bf38a1d 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h @@ -21,11 +21,12 @@ #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/ClangASTImporter.h" +#include + namespace lldb_private { class CompileUnit; } class DWARFDebugInfoEntry; -class DWARFDIECollection; class SymbolFileDWARF; class DWARFASTParserClang : public DWARFASTParser { @@ -85,7 +86,7 @@ protected: const lldb::LanguageType class_language, std::vector> &base_classes, std::vector &member_accessibilities, - DWARFDIECollection &member_function_dies, + std::vector &member_function_dies, DelayedPropertyList &delayed_properties, lldb::AccessType &default_accessibility, bool &is_a_class, lldb_private::ClangASTImporter::LayoutInfo &layout_info); @@ -117,7 +118,7 @@ protected: bool CopyUniqueClassMethodTypes(const DWARFDIE &src_class_die, const DWARFDIE &dst_class_die, lldb_private::Type *class_type, - DWARFDIECollection &failures); + std::vector &failures); clang::DeclContext *GetCachedClangDeclContextForDIE(const DWARFDIE &die); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h index ba9a32f062ac..e23db258f124 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h @@ -18,7 +18,6 @@ class DWARFAttributes; class DWARFUnit; class DWARFDebugInfoEntry; class DWARFDeclContext; -class DWARFDIECollection; class SymbolFileDWARF; class DWARFBaseDIE { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp index 35961cf4794a..dc400771dd0f 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp @@ -9,7 +9,6 @@ #include "DWARFDIE.h" #include "DWARFASTParser.h" -#include "DWARFDIECollection.h" #include "DWARFDebugInfo.h" #include "DWARFDebugInfoEntry.h" #include "DWARFDeclContext.h" @@ -200,15 +199,18 @@ lldb_private::Type *DWARFDIE::ResolveTypeUID(const DIERef &die_ref) const { return nullptr; } -void DWARFDIE::GetDeclContextDIEs(DWARFDIECollection &decl_context_dies) const { - if (IsValid()) { - DWARFDIE parent_decl_ctx_die = - m_die->GetParentDeclContextDIE(GetDWARF(), GetCU()); - if (parent_decl_ctx_die && parent_decl_ctx_die.GetDIE() != GetDIE()) { - decl_context_dies.Append(parent_decl_ctx_die); - parent_decl_ctx_die.GetDeclContextDIEs(decl_context_dies); - } +std::vector DWARFDIE::GetDeclContextDIEs() const { + if (!IsValid()) + return {}; + + std::vector result; + DWARFDIE parent = GetParentDeclContextDIE(); + while (parent.IsValid() && parent.GetDIE() != GetDIE()) { + result.push_back(std::move(parent)); + parent = parent.GetParentDeclContextDIE(); } + + return result; } void DWARFDIE::GetDWARFDeclContext(DWARFDeclContext &dwarf_decl_ctx) const { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h index c513a4377cb4..af3323efe9fe 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h @@ -81,7 +81,7 @@ public: //---------------------------------------------------------------------- // DeclContext related functions //---------------------------------------------------------------------- - void GetDeclContextDIEs(DWARFDIECollection &decl_context_dies) const; + std::vector GetDeclContextDIEs() const; void GetDWARFDeclContext(DWARFDeclContext &dwarf_decl_ctx) const; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIECollection.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIECollection.cpp deleted file mode 100644 index bf463dd18277..000000000000 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIECollection.cpp +++ /dev/null @@ -1,34 +0,0 @@ -//===-- DWARFDIECollection.cpp ----------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "DWARFDIECollection.h" - -#include - -#include "lldb/Utility/Stream.h" - -using namespace lldb_private; -using namespace std; - -void DWARFDIECollection::Append(const DWARFDIE &die) { m_dies.push_back(die); } - -DWARFDIE -DWARFDIECollection::GetDIEAtIndex(uint32_t idx) const { - if (idx < m_dies.size()) - return m_dies[idx]; - return DWARFDIE(); -} - -size_t DWARFDIECollection::Size() const { return m_dies.size(); } - -void DWARFDIECollection::Dump(Stream *s, const char *title) const { - if (title && title[0] != '\0') - s->Printf("%s\n", title); - for (const auto &die : m_dies) - s->Printf("0x%8.8x\n", die.GetOffset()); -} diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIECollection.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIECollection.h deleted file mode 100644 index 3cb3f2e8f6a3..000000000000 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIECollection.h +++ /dev/null @@ -1,37 +0,0 @@ -//===-- DWARFDIECollection.h ------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef SymbolFileDWARF_DWARFDIECollection_h_ -#define SymbolFileDWARF_DWARFDIECollection_h_ - -#include "DWARFDIE.h" -#include - -class DWARFDIECollection { -public: - DWARFDIECollection() : m_dies() {} - ~DWARFDIECollection() {} - - void Append(const DWARFDIE &die); - - void Dump(lldb_private::Stream *s, const char *title) const; - - DWARFDIE - GetDIEAtIndex(uint32_t idx) const; - - size_t Size() const; - -protected: - typedef std::vector collection; - typedef collection::iterator iterator; - typedef collection::const_iterator const_iterator; - - collection m_dies; // Ordered list of die offsets -}; - -#endif // SymbolFileDWARF_DWARFDIECollection_h_ diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp index 554f091ebec2..14e23174fd4e 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp @@ -18,7 +18,6 @@ #include "lldb/Utility/Stream.h" #include "DWARFUnit.h" -#include "DWARFDIECollection.h" #include "DWARFDebugAbbrev.h" #include "DWARFDebugAranges.h" #include "DWARFDebugInfo.h" @@ -1381,11 +1380,11 @@ void DWARFDebugInfoEntry::BuildFunctionAddressRangeTable( } } -void DWARFDebugInfoEntry::GetDeclContextDIEs( - DWARFUnit *cu, DWARFDIECollection &decl_context_dies) const { +std::vector +DWARFDebugInfoEntry::GetDeclContextDIEs(DWARFUnit *cu) const { DWARFDIE die(cu, const_cast(this)); - die.GetDeclContextDIEs(decl_context_dies); + return die.GetDeclContextDIEs(); } void DWARFDebugInfoEntry::GetDWARFDeclContext( diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h index 0df61aaa6b72..695aa3ab3546 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h @@ -230,8 +230,7 @@ public: return HasChildren() ? this + 1 : NULL; } - void GetDeclContextDIEs(DWARFUnit *cu, - DWARFDIECollection &decl_context_dies) const; + std::vector GetDeclContextDIEs(DWARFUnit *cu) const; void GetDWARFDeclContext(SymbolFileDWARF *dwarf2Data, DWARFUnit *cu, DWARFDeclContext &dwarf_decl_ctx) const; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp index 0ffbe98592a7..9501047d0513 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -17,7 +17,6 @@ #include "lldb/Utility/StreamString.h" #include "lldb/Utility/Timer.h" -#include "DWARFDIECollection.h" #include "DWARFDebugAranges.h" #include "DWARFDebugInfo.h" #include "LogChannelDWARF.h" @@ -400,24 +399,23 @@ DWARFDIE DWARFUnit::LookupAddress(const dw_addr_t address) { } size_t DWARFUnit::AppendDIEsWithTag(const dw_tag_t tag, - DWARFDIECollection &dies, - uint32_t depth) const { - size_t old_size = dies.Size(); + std::vector &dies, + uint32_t depth) const { + size_t old_size = dies.size(); { llvm::sys::ScopedReader lock(m_die_array_mutex); DWARFDebugInfoEntry::const_iterator pos; DWARFDebugInfoEntry::const_iterator end = m_die_array.end(); for (pos = m_die_array.begin(); pos != end; ++pos) { if (pos->Tag() == tag) - dies.Append(DWARFDIE(this, &(*pos))); + dies.emplace_back(this, &(*pos)); } } // Return the number of DIEs added to the collection - return dies.Size() - old_size; + return dies.size() - old_size; } - lldb::user_id_t DWARFUnit::GetID() const { dw_offset_t local_id = m_base_obj_offset != DW_INVALID_OFFSET ? m_base_obj_offset : m_offset; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h index d5061f6d4468..93acaa2251dc 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h @@ -54,8 +54,7 @@ public: ScopedExtractDIEs ExtractDIEsScoped(); DWARFDIE LookupAddress(const dw_addr_t address); - size_t AppendDIEsWithTag(const dw_tag_t tag, - DWARFDIECollection &matching_dies, + size_t AppendDIEsWithTag(const dw_tag_t tag, std::vector &dies, uint32_t depth = UINT32_MAX) const; bool Verify(lldb_private::Stream *s) const; virtual void Dump(lldb_private::Stream *s) const = 0; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index 0b789fd0c7c3..0518dbf37475 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -54,7 +54,6 @@ #include "AppleDWARFIndex.h" #include "DWARFASTParser.h" #include "DWARFASTParserClang.h" -#include "DWARFDIECollection.h" #include "DWARFDebugAbbrev.h" #include "DWARFDebugAranges.h" #include "DWARFDebugInfo.h" @@ -861,22 +860,20 @@ lldb::LanguageType SymbolFileDWARF::ParseLanguage(CompileUnit &comp_unit) { size_t SymbolFileDWARF::ParseFunctions(CompileUnit &comp_unit) { ASSERT_MODULE_LOCK(this); - size_t functions_added = 0; DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); - if (dwarf_cu) { - DWARFDIECollection function_dies; - const size_t num_functions = - dwarf_cu->AppendDIEsWithTag(DW_TAG_subprogram, function_dies); - size_t func_idx; - for (func_idx = 0; func_idx < num_functions; ++func_idx) { - DWARFDIE die = function_dies.GetDIEAtIndex(func_idx); - if (comp_unit.FindFunctionByUID(die.GetID()).get() == NULL) { - if (ParseFunction(comp_unit, die)) - ++functions_added; - } - } - // FixupTypes(); + if (!dwarf_cu) + return 0; + + size_t functions_added = 0; + std::vector function_dies; + dwarf_cu->AppendDIEsWithTag(DW_TAG_subprogram, function_dies); + for (const DWARFDIE &die : function_dies) { + if (comp_unit.FindFunctionByUID(die.GetID())) + continue; + if (ParseFunction(comp_unit, die)) + ++functions_added; } + // FixupTypes(); return functions_added; } @@ -2807,8 +2804,8 @@ bool SymbolFileDWARF::DIEDeclContextsMatch(const DWARFDIE &die1, if (die1 == die2) return true; - DWARFDIECollection decl_ctx_1; - DWARFDIECollection decl_ctx_2; + std::vector decl_ctx_1; + std::vector decl_ctx_2; // The declaration DIE stack is a stack of the declaration context DIEs all // the way back to the compile unit. If a type "T" is declared inside a class // "B", and class "B" is declared inside a class "A" and class "A" is in a @@ -2824,11 +2821,11 @@ bool SymbolFileDWARF::DIEDeclContextsMatch(const DWARFDIE &die1, // back to the compiler unit. // First lets grab the decl contexts for both DIEs - die1.GetDeclContextDIEs(decl_ctx_1); - die2.GetDeclContextDIEs(decl_ctx_2); + decl_ctx_1 = die1.GetDeclContextDIEs(); + decl_ctx_2 = die2.GetDeclContextDIEs(); // Make sure the context arrays have the same size, otherwise we are done - const size_t count1 = decl_ctx_1.Size(); - const size_t count2 = decl_ctx_2.Size(); + const size_t count1 = decl_ctx_1.size(); + const size_t count2 = decl_ctx_2.size(); if (count1 != count2) return false; @@ -2838,8 +2835,8 @@ bool SymbolFileDWARF::DIEDeclContextsMatch(const DWARFDIE &die1, DWARFDIE decl_ctx_die2; size_t i; for (i = 0; i < count1; i++) { - decl_ctx_die1 = decl_ctx_1.GetDIEAtIndex(i); - decl_ctx_die2 = decl_ctx_2.GetDIEAtIndex(i); + decl_ctx_die1 = decl_ctx_1[i]; + decl_ctx_die2 = decl_ctx_2[i]; if (decl_ctx_die1.Tag() != decl_ctx_die2.Tag()) return false; } @@ -2849,7 +2846,7 @@ bool SymbolFileDWARF::DIEDeclContextsMatch(const DWARFDIE &die1, // DW_TAG_compile_unit or DW_TAG_partial_unit. If it isn't then // something went wrong in the DWARFDIE::GetDeclContextDIEs() // function. - dw_tag_t cu_tag = decl_ctx_1.GetDIEAtIndex(count1 - 1).Tag(); + dw_tag_t cu_tag = decl_ctx_1[count1 - 1].Tag(); UNUSED_IF_ASSERT_DISABLED(cu_tag); assert(cu_tag == DW_TAG_compile_unit || cu_tag == DW_TAG_partial_unit); @@ -2857,8 +2854,8 @@ bool SymbolFileDWARF::DIEDeclContextsMatch(const DWARFDIE &die1, // Always skip the compile unit when comparing by only iterating up to "count // - 1". Here we compare the names as we go. for (i = 0; i < count1 - 1; i++) { - decl_ctx_die1 = decl_ctx_1.GetDIEAtIndex(i); - decl_ctx_die2 = decl_ctx_2.GetDIEAtIndex(i); + decl_ctx_die1 = decl_ctx_1[i]; + decl_ctx_die2 = decl_ctx_2[i]; const char *name1 = decl_ctx_die1.GetName(); const char *name2 = decl_ctx_die2.GetName(); // If the string was from a DW_FORM_strp, then the pointer will often be diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h index 9fc2015f0ad7..7d4b9e5128bc 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -49,7 +49,6 @@ class DWARFDebugInfoEntry; class DWARFDebugLine; class DWARFDebugRangesBase; class DWARFDeclContext; -class DWARFDIECollection; class DWARFFormValue; class SymbolFileDWARFDebugMap; class SymbolFileDWARFDwo;