diff options
author | Greg Clayton <gclayton@apple.com> | 2015-08-26 22:57:51 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2015-08-26 22:57:51 +0000 |
commit | 6071e6fc9430add9873523733ab099b5578929e6 (patch) | |
tree | 6b00ad85e6488708ccf8ceebaae608390e7db328 /lldb/source/Plugins/SymbolFile | |
parent | 8cd9d7acb25eec1f0c5fa190759213030f5e1ec8 (diff) | |
download | bcm5719-llvm-6071e6fc9430add9873523733ab099b5578929e6.tar.gz bcm5719-llvm-6071e6fc9430add9873523733ab099b5578929e6.zip |
Major DWARF cleanup.
Added a new class called DWARFDIE that contains a DWARFCompileUnit and DWARFDebugInfoEntry so that these items always stay together.
There were many places where we just handed out DWARFDebugInfoEntry pointers and then use them with a compile unit that may or may not be the correct one. Clients outside of DWARFCompileUnit and DWARFDebugInfoEntry should all be dealing with DWARFDIE instances instead of playing with DWARFCompileUnit/DWARFDebugInfoEntry pairs manually.
This paves to the way for some modifications that are coming for DWO.
llvm-svn: 246100
Diffstat (limited to 'lldb/source/Plugins/SymbolFile')
25 files changed, 1651 insertions, 1395 deletions
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt b/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt index 05aa0b83e9f..b4ded6288a7 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt +++ b/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt @@ -2,6 +2,7 @@ set(LLVM_NO_RTTI 1) add_lldb_library(lldbPluginSymbolFileDWARF DWARFAbbreviationDeclaration.cpp + DWARFAttribute.cpp DWARFCompileUnit.cpp DWARFDataExtractor.cpp DWARFDebugAbbrev.cpp @@ -17,6 +18,7 @@ add_lldb_library(lldbPluginSymbolFileDWARF DWARFDebugRanges.cpp DWARFDeclContext.cpp DWARFDefines.cpp + DWARFDIE.cpp DWARFDIECollection.cpp DWARFFormValue.cpp DWARFLocationDescription.cpp diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.cpp new file mode 100644 index 00000000000..a522bcb3528 --- /dev/null +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.cpp @@ -0,0 +1,90 @@ +//===-- DWARFAttribute.cpp --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "DWARFAttribute.h" +#include "DWARFDebugInfo.h" +#include "DWARFCompileUnit.h" + +DWARFAttributes::DWARFAttributes() : + m_infos() +{ +} + +DWARFAttributes::~DWARFAttributes() +{ +} + + +uint32_t +DWARFAttributes::FindAttributeIndex(dw_attr_t attr) const +{ + collection::const_iterator end = m_infos.end(); + collection::const_iterator beg = m_infos.begin(); + collection::const_iterator pos; + for (pos = beg; pos != end; ++pos) + { + if (pos->attr.get_attr() == attr) + return std::distance(beg, pos); + } + return UINT32_MAX; +} + +void +DWARFAttributes::Append(const DWARFCompileUnit *cu, dw_offset_t attr_die_offset, dw_attr_t attr, dw_form_t form) +{ + AttributeValue attr_value = { cu, attr_die_offset, { attr, form } }; + m_infos.push_back(attr_value); +} + +bool +DWARFAttributes::ContainsAttribute(dw_attr_t attr) const +{ + return FindAttributeIndex(attr) != UINT32_MAX; +} + +bool +DWARFAttributes::RemoveAttribute(dw_attr_t attr) +{ + uint32_t attr_index = FindAttributeIndex(attr); + if (attr_index != UINT32_MAX) + { + m_infos.erase(m_infos.begin() + attr_index); + return true; + } + return false; +} + +bool +DWARFAttributes::ExtractFormValueAtIndex (uint32_t i, DWARFFormValue &form_value) const +{ + const DWARFCompileUnit *cu = CompileUnitAtIndex(i); + form_value.SetCompileUnit(cu); + form_value.SetForm(FormAtIndex(i)); + lldb::offset_t offset = DIEOffsetAtIndex(i); + return form_value.ExtractValue(cu->GetSymbolFileDWARF()->get_debug_info_data(), &offset); +} + +uint64_t +DWARFAttributes::FormValueAsUnsigned (dw_attr_t attr, uint64_t fail_value) const +{ + const uint32_t attr_idx = FindAttributeIndex (attr); + if (attr_idx != UINT32_MAX) + return FormValueAsUnsignedAtIndex (attr_idx, fail_value); + return fail_value; +} + +uint64_t +DWARFAttributes::FormValueAsUnsignedAtIndex(uint32_t i, uint64_t fail_value) const +{ + DWARFFormValue form_value; + if (ExtractFormValueAtIndex(i, form_value)) + return form_value.Reference(); + return fail_value; +} + diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h index 40c8af3d6e8..f5ca9cce525 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h @@ -10,36 +10,72 @@ #ifndef SymbolFileDWARF_DWARFAttribute_h_ #define SymbolFileDWARF_DWARFAttribute_h_ +#include "llvm/ADT/SmallVector.h" #include "DWARFDefines.h" #include <vector> +class DWARFCompileUnit; +class DWARFFormValue; + class DWARFAttribute { public: DWARFAttribute(dw_attr_t attr, dw_form_t form) : - m_attr_form ( attr << 16 | form ) + m_attr (attr), + m_form (form) { } - void set(dw_attr_t attr, dw_form_t form) { m_attr_form = (attr << 16) | form; } - void set_attr(dw_attr_t attr) { m_attr_form = (m_attr_form & 0x0000ffffu) | (attr << 16); } - void set_form(dw_form_t form) { m_attr_form = (m_attr_form & 0xffff0000u) | form; } - dw_attr_t get_attr() const { return m_attr_form >> 16; } - dw_form_t get_form() const { return (dw_form_t)m_attr_form; } - void get(dw_attr_t& attr, dw_form_t& form) const + void set (dw_attr_t attr, dw_form_t form) { m_attr = attr; m_form = form; } + void set_attr (dw_attr_t attr) { m_attr = attr; } + void set_form (dw_form_t form) { m_form = form; } + dw_attr_t get_attr () const { return m_attr; } + dw_form_t get_form () const { return m_form; } + void get (dw_attr_t& attr, dw_form_t& form) const { - uint32_t attr_form = m_attr_form; - attr = attr_form >> 16; - form = (dw_form_t)attr_form; + attr = m_attr; + form = m_form; } - bool operator == (const DWARFAttribute& rhs) const { return m_attr_form == rhs.m_attr_form; } + bool operator == (const DWARFAttribute& rhs) const { return m_attr == rhs.m_attr && m_form == rhs.m_form; } typedef std::vector<DWARFAttribute> collection; typedef collection::iterator iterator; typedef collection::const_iterator const_iterator; protected: - uint32_t m_attr_form; // Upper 16 bits is attribute, lower 16 bits is form + dw_attr_t m_attr; + dw_form_t m_form; }; +class DWARFAttributes +{ +public: + DWARFAttributes(); + ~DWARFAttributes(); + + void Append(const DWARFCompileUnit *cu, dw_offset_t attr_die_offset, dw_attr_t attr, dw_form_t form); + const DWARFCompileUnit * CompileUnitAtIndex(uint32_t i) const { return m_infos[i].cu; } + dw_offset_t DIEOffsetAtIndex(uint32_t i) const { return m_infos[i].die_offset; } + dw_attr_t AttributeAtIndex(uint32_t i) const { return m_infos[i].attr.get_attr(); } + dw_attr_t FormAtIndex(uint32_t i) const { return m_infos[i].attr.get_form(); } + bool ExtractFormValueAtIndex (uint32_t i, DWARFFormValue &form_value) const; + uint64_t FormValueAsUnsignedAtIndex (uint32_t i, uint64_t fail_value) const; + uint64_t FormValueAsUnsigned (dw_attr_t attr, uint64_t fail_value) const; + uint32_t FindAttributeIndex(dw_attr_t attr) const; + bool ContainsAttribute(dw_attr_t attr) const; + bool RemoveAttribute(dw_attr_t attr); + void Clear() { m_infos.clear(); } + size_t Size() const { return m_infos.size(); } + +protected: + struct AttributeValue + { + const DWARFCompileUnit *cu; // Keep the compile unit with each attribute in case we have DW_FORM_ref_addr values + dw_offset_t die_offset; + DWARFAttribute attr; + }; + typedef llvm::SmallVector<AttributeValue, 8> collection; + collection m_infos; +}; + #endif // SymbolFileDWARF_DWARFAttribute_h_ diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp index 90b65fe6a8a..eec2aee7da9 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp @@ -376,6 +376,15 @@ DWARFCompileUnit::SetDefaultAddressSize(uint8_t addr_size) g_default_addr_size = addr_size; } +lldb::user_id_t +DWARFCompileUnit::GetID () const +{ + if (m_dwarf2Data) + return m_dwarf2Data->MakeUserID(GetOffset()); + else + return GetOffset(); +} + void DWARFCompileUnit::BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data, DWARFDebugAranges* debug_aranges) @@ -392,7 +401,7 @@ DWARFCompileUnit::BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data, const dw_offset_t cu_offset = GetOffset(); if (die) { - DWARFDebugRanges::RangeList ranges; + DWARFRangeList ranges; const size_t num_ranges = die->GetAttributeAddressRanges(dwarf2Data, this, ranges, false); if (num_ranges > 0) { @@ -402,7 +411,7 @@ DWARFCompileUnit::BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data, // this with recent GCC builds. for (size_t i=0; i<num_ranges; ++i) { - const DWARFDebugRanges::RangeList::Entry &range = ranges.GetEntryRef(i); + const DWARFRangeList::Entry &range = ranges.GetEntryRef(i); debug_aranges->AppendRange(cu_offset, range.GetRangeBase(), range.GetRangeEnd()); } @@ -416,7 +425,7 @@ DWARFCompileUnit::BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data, // and then throwing them all away to keep memory usage down. const bool clear_dies = ExtractDIEsIfNeeded (false) > 1; - die = DIE(); + die = DIEPtr(); if (die) die->BuildAddressRangeTable(dwarf2Data, this, debug_aranges); @@ -496,7 +505,7 @@ DWARFCompileUnit::GetFunctionAranges () "DWARFCompileUnit::GetFunctionAranges() for compile unit at .debug_info[0x%8.8x]", GetOffset()); } - const DWARFDebugInfoEntry* die = DIE(); + const DWARFDebugInfoEntry* die = DIEPtr(); if (die) die->BuildFunctionAddressRangeTable (m_dwarf2Data, this, m_func_aranges_ap.get()); const bool minimize = false; @@ -505,74 +514,58 @@ DWARFCompileUnit::GetFunctionAranges () return *m_func_aranges_ap.get(); } -bool -DWARFCompileUnit::LookupAddress -( - const dw_addr_t address, - DWARFDebugInfoEntry** function_die_handle, - DWARFDebugInfoEntry** block_die_handle -) +DWARFDIE +DWARFCompileUnit::LookupAddress (const dw_addr_t address) { - bool success = false; - - if (function_die_handle != NULL && DIE()) + if (DIE()) { - const DWARFDebugAranges &func_aranges = GetFunctionAranges (); // Re-check the aranges auto pointer contents in case it was created above if (!func_aranges.IsEmpty()) - { - *function_die_handle = GetDIEPtr(func_aranges.FindAddress(address)); - if (*function_die_handle != NULL) - { - success = true; - if (block_die_handle != NULL) - { - DWARFDebugInfoEntry* child = (*function_die_handle)->GetFirstChild(); - while (child) - { - if (child->LookupAddress(address, m_dwarf2Data, this, NULL, block_die_handle)) - break; - child = child->GetSibling(); - } - } - } - } + return GetDIE(func_aranges.FindAddress(address)); } - return success; + return DWARFDIE(); } //---------------------------------------------------------------------- // Compare function DWARFDebugAranges::Range structures //---------------------------------------------------------------------- -static bool CompareDIEOffset (const DWARFDebugInfoEntry& die1, const DWARFDebugInfoEntry& die2) +static bool CompareDIEOffset (const DWARFDebugInfoEntry& die, const dw_offset_t die_offset) { - return die1.GetOffset() < die2.GetOffset(); + return die.GetOffset() < die_offset; } //---------------------------------------------------------------------- -// GetDIEPtr() +// GetDIE() // -// Get the DIE (Debug Information Entry) with the specified offset. +// Get the DIE (Debug Information Entry) with the specified offset by +// first checking if the DIE is contained within this compile unit and +// grabbing the DIE from this compile unit. Otherwise we grab the DIE +// from the DWARF file. //---------------------------------------------------------------------- -DWARFDebugInfoEntry* -DWARFCompileUnit::GetDIEPtr(dw_offset_t die_offset) +DWARFDIE +DWARFCompileUnit::GetDIE (dw_offset_t die_offset) { if (die_offset != DW_INVALID_OFFSET) { - ExtractDIEsIfNeeded (false); - DWARFDebugInfoEntry compare_die; - compare_die.SetOffset(die_offset); - DWARFDebugInfoEntry::iterator end = m_die_array.end(); - DWARFDebugInfoEntry::iterator pos = lower_bound(m_die_array.begin(), end, compare_die, CompareDIEOffset); - if (pos != end) + if (ContainsDIEOffset(die_offset)) { - if (die_offset == (*pos).GetOffset()) - return &(*pos); + ExtractDIEsIfNeeded (false); + DWARFDebugInfoEntry::iterator end = m_die_array.end(); + DWARFDebugInfoEntry::iterator pos = lower_bound(m_die_array.begin(), end, die_offset, CompareDIEOffset); + if (pos != end) + { + if (die_offset == (*pos).GetOffset()) + return DWARFDIE(this, &(*pos)); + } + } + else + { + return m_dwarf2Data->DebugInfo()->GetDIE (die_offset); } } - return NULL; // Not found in any compile units + return DWARFDIE(); // Not found } //---------------------------------------------------------------------- @@ -581,30 +574,36 @@ DWARFCompileUnit::GetDIEPtr(dw_offset_t die_offset) // Get the DIE (Debug Information Entry) that contains the specified // .debug_info offset. //---------------------------------------------------------------------- -const DWARFDebugInfoEntry* -DWARFCompileUnit::GetDIEPtrContainingOffset(dw_offset_t die_offset) +DWARFDIE +DWARFCompileUnit::GetDIEContainingOffset(dw_offset_t die_offset) { if (die_offset != DW_INVALID_OFFSET) { - ExtractDIEsIfNeeded (false); - DWARFDebugInfoEntry compare_die; - compare_die.SetOffset(die_offset); - DWARFDebugInfoEntry::iterator end = m_die_array.end(); - DWARFDebugInfoEntry::iterator pos = lower_bound(m_die_array.begin(), end, compare_die, CompareDIEOffset); - if (pos != end) + if (ContainsDIEOffset(die_offset)) { - if (die_offset >= (*pos).GetOffset()) + + ExtractDIEsIfNeeded (false); + DWARFDebugInfoEntry::iterator end = m_die_array.end(); + DWARFDebugInfoEntry::iterator pos = lower_bound(m_die_array.begin(), end, die_offset, CompareDIEOffset); + if (pos != end) { - DWARFDebugInfoEntry::iterator next = pos + 1; - if (next != end) + if (die_offset >= (*pos).GetOffset()) { - if (die_offset < (*next).GetOffset()) - return &(*pos); + DWARFDebugInfoEntry::iterator next = pos + 1; + if (next != end) + { + if (die_offset < (*next).GetOffset()) + return DWARFDIE(this, &(*pos)); + } } } } + else + { + return m_dwarf2Data->DebugInfo()->GetDIEContainingOffset (die_offset); + } } - return NULL; // Not found in any compile units + return DWARFDIE(); // Not found } @@ -618,7 +617,7 @@ DWARFCompileUnit::AppendDIEsWithTag (const dw_tag_t tag, DWARFDIECollection& die for (pos = m_die_array.begin(); pos != end; ++pos) { if (pos->Tag() == tag) - dies.Append (&(*pos)); + dies.Append (DWARFDIE(this, &(*pos))); } // Return the number of DIEs added to the collection @@ -703,7 +702,7 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, continue; } - DWARFDebugInfoEntry::Attributes attributes; + DWARFAttributes attributes; const char *name = NULL; const char *mangled_cstr = NULL; bool is_declaration = false; @@ -713,7 +712,7 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, bool is_global_or_static_variable = false; dw_offset_t specification_die_offset = DW_INVALID_OFFSET; - const size_t num_attributes = die.GetAttributes(m_dwarf2Data, this, fixed_form_sizes, attributes); + const size_t num_attributes = die.GetAttributes(this, fixed_form_sizes, attributes); if (num_attributes > 0) { for (uint32_t i=0; i<num_attributes; ++i) @@ -723,24 +722,24 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, switch (attr) { case DW_AT_name: - if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value)) - name = form_value.AsCString(m_dwarf2Data); + if (attributes.ExtractFormValueAtIndex(i, form_value)) + name = form_value.AsCString(); break; case DW_AT_declaration: - if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value)) + if (attributes.ExtractFormValueAtIndex(i, form_value)) is_declaration = form_value.Unsigned() != 0; break; // case DW_AT_artificial: -// if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value)) +// if (attributes.ExtractFormValueAtIndex(i, form_value)) // is_artificial = form_value.Unsigned() != 0; // break; case DW_AT_MIPS_linkage_name: case DW_AT_linkage_name: - if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value)) - mangled_cstr = form_value.AsCString(m_dwarf2Data); + if (attributes.ExtractFormValueAtIndex(i, form_value)) + mangled_cstr = form_value.AsCString(); break; case DW_AT_low_pc: @@ -802,7 +801,7 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, break; case DW_AT_specification: - if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value)) + if (attributes.ExtractFormValueAtIndex(i, form_value)) specification_die_offset = form_value.Reference(); break; } @@ -850,18 +849,9 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, { if (specification_die_offset != DW_INVALID_OFFSET) { - const DWARFDebugInfoEntry *specification_die = m_dwarf2Data->DebugInfo()->GetDIEPtr (specification_die_offset, NULL); - if (specification_die) - { - parent = specification_die->GetParent(); - if (parent) - { - parent_tag = parent->Tag(); - - if (parent_tag == DW_TAG_class_type || parent_tag == DW_TAG_structure_type) - is_method = true; - } - } + DWARFDIE specification_die = m_dwarf2Data->DebugInfo()->GetDIE (specification_die_offset); + if (specification_die.GetParent().IsStructOrClass()) + is_method = true; } } } @@ -1133,3 +1123,18 @@ DWARFCompileUnit::GetIsOptimized () return false; } } + +DWARFFormValue::FixedFormSizes +DWARFCompileUnit::GetFixedFormSizes () +{ + return DWARFFormValue::GetFixedFormSizesForAddressSize (GetAddressByteSize(), IsDWARF64()); +} + +TypeSystem * +DWARFCompileUnit::GetTypeSystem () +{ + if (m_dwarf2Data) + return m_dwarf2Data->GetTypeSystemForLanguage(GetLanguageType()); + else + return nullptr; +} diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h index 16c00f5ea42..5b1f948ada6 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h @@ -12,6 +12,7 @@ #include "lldb/lldb-enumerations.h" #include "DWARFDebugInfoEntry.h" +#include "DWARFDIE.h" #include "SymbolFileDWARF.h" class NameToDIE; @@ -32,16 +33,13 @@ public: bool Extract(const lldb_private::DWARFDataExtractor &debug_info, lldb::offset_t *offset_ptr); size_t ExtractDIEsIfNeeded (bool cu_die_only); - bool LookupAddress( - const dw_addr_t address, - DWARFDebugInfoEntry** function_die, - DWARFDebugInfoEntry** block_die); - + DWARFDIE LookupAddress(const dw_addr_t address); size_t AppendDIEsWithTag (const dw_tag_t tag, DWARFDIECollection& matching_dies, uint32_t depth = UINT32_MAX) const; void Clear(); bool Verify(lldb_private::Stream *s) const; void Dump(lldb_private::Stream *s) const; dw_offset_t GetOffset() const { return m_offset; } + lldb::user_id_t GetID () const; uint32_t Size() const { return m_is_dwarf64 ? 23 : 11; /* Size in bytes of the compile unit header */ } bool ContainsDIEOffset(dw_offset_t die_offset) const { return die_offset >= GetFirstDIEOffset() && die_offset < GetNextCompileUnitOffset(); } dw_offset_t GetFirstDIEOffset() const { return m_offset + Size(); } @@ -58,6 +56,12 @@ public: void BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data, DWARFDebugAranges* debug_aranges); + lldb_private::TypeSystem * + GetTypeSystem(); + + DWARFFormValue::FixedFormSizes + GetFixedFormSizes (); + void SetBaseAddress(dw_addr_t base_addr) { @@ -73,8 +77,14 @@ public: return &m_die_array[0]; } + DWARFDIE + DIE () + { + return DWARFDIE(this, DIEPtr()); + } + const DWARFDebugInfoEntry* - DIE() + DIEPtr() { ExtractDIEsIfNeeded (false); if (m_die_array.empty()) @@ -111,11 +121,11 @@ public: return &m_die_array[idx]; } - DWARFDebugInfoEntry* - GetDIEPtr (dw_offset_t die_offset); + DWARFDIE + GetDIE (dw_offset_t die_offset); - const DWARFDebugInfoEntry* - GetDIEPtrContainingOffset (dw_offset_t die_offset); + DWARFDIE + GetDIEContainingOffset (dw_offset_t die_offset); static uint8_t GetAddressByteSize(const DWARFCompileUnit* cu); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp new file mode 100644 index 00000000000..d2c898130f1 --- /dev/null +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp @@ -0,0 +1,416 @@ +//===-- DWARFDIE.cpp --------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "DWARFDIE.h" + +#include "DWARFCompileUnit.h" +#include "DWARFDebugAbbrev.h" +#include "DWARFDebugAranges.h" +#include "DWARFDebugInfo.h" +#include "DWARFDebugInfoEntry.h" +#include "DWARFDebugRanges.h" +#include "DWARFDeclContext.h" +#include "DWARFDIECollection.h" +#include "DWARFFormValue.h" +#include "DWARFLocationDescription.h" +#include "DWARFLocationList.h" +#include "SymbolFileDWARF.h" + +#include "lldb/Core/Module.h" +#include "lldb/Symbol/ObjectFile.h" + +dw_tag_t +DWARFDIE::Tag() const +{ + if (m_die) + return m_die->Tag(); + else + return 0; +} + +const char * +DWARFDIE::GetTagAsCString () const +{ + return lldb_private::DW_TAG_value_to_name (Tag()); +} + +DWARFDIE +DWARFDIE::GetParent () const +{ + if (IsValid()) + return DWARFDIE(m_cu, m_die->GetParent()); + else + return DWARFDIE(); +} + +DWARFDIE +DWARFDIE::GetFirstChild () const +{ + if (IsValid()) + return DWARFDIE(m_cu, m_die->GetFirstChild()); + else + return DWARFDIE(); +} + +DWARFDIE +DWARFDIE::GetSibling () const +{ + if (IsValid()) + return DWARFDIE(m_cu, m_die->GetSibling()); + else + return DWARFDIE(); +} + +DWARFDIE +DWARFDIE::GetReferencedDIE (const dw_attr_t attr) const +{ + const dw_offset_t die_offset = GetAttributeValueAsReference (attr, DW_INVALID_OFFSET); + if (die_offset != DW_INVALID_OFFSET) + return GetDIE(die_offset); + else + return DWARFDIE(); +} + +DWARFDIE +DWARFDIE::GetDIE (dw_offset_t die_offset) const +{ + if (IsValid()) + return m_cu->GetDIE(die_offset); + else + return DWARFDIE(); +} + +const char * +DWARFDIE::GetAttributeValueAsString (const dw_attr_t attr, const char *fail_value) const +{ + if (IsValid()) + return m_die->GetAttributeValueAsString(GetDWARF(), GetCU(), attr, fail_value); + else + return fail_value; +} + +uint64_t +DWARFDIE::GetAttributeValueAsUnsigned (const dw_attr_t attr, uint64_t fail_value) const +{ + if (IsValid()) + return m_die->GetAttributeValueAsUnsigned(GetDWARF(), GetCU(), attr, fail_value); + else + return fail_value; +} + +int64_t +DWARFDIE::GetAttributeValueAsSigned (const dw_attr_t attr, int64_t fail_value) const +{ + if (IsValid()) + return m_die->GetAttributeValueAsSigned(GetDWARF(), GetCU(), attr, fail_value); + else + return fail_value; +} + +uint64_t +DWARFDIE::GetAttributeValueAsReference (const dw_attr_t attr, uint64_t fail_value) const +{ + if (IsValid()) + return m_die->GetAttributeValueAsReference(GetDWARF(), GetCU(), attr, fail_value); + else + return fail_value; +} + + +DWARFDIE +DWARFDIE::LookupDeepestBlock (lldb::addr_t file_addr) const +{ + if (IsValid()) + { + SymbolFileDWARF *dwarf= GetDWARF(); + DWARFCompileUnit *cu = GetCU(); + DWARFDebugInfoEntry* function_die = nullptr; + DWARFDebugInfoEntry* block_die = nullptr; + if (m_die->LookupAddress (file_addr, + dwarf, + cu, + &function_die, + &block_die)) + { + if (block_die && block_die != function_die) + { + if (cu->ContainsDIEOffset(block_die->GetOffset())) + return DWARFDIE(cu, block_die); + else + return DWARFDIE(dwarf->DebugInfo()->GetCompileUnitContainingDIE(block_die->GetOffset()), block_die); + } + } + } + return DWARFDIE(); +} + +lldb::user_id_t +DWARFDIE::GetID () const +{ + const dw_offset_t die_offset = GetOffset(); + if (die_offset != DW_INVALID_OFFSET) + { + SymbolFileDWARF *dwarf = GetDWARF(); + if (dwarf) + return dwarf->MakeUserID(die_offset); + else + return die_offset; + } + return LLDB_INVALID_UID; +} + +const char * +DWARFDIE::GetName () const +{ + if (IsValid()) + return m_die->GetName (GetDWARF(), m_cu); + else + return nullptr; +} + +const char * +DWARFDIE::GetMangledName () const +{ + if (IsValid()) + return m_die->GetMangledName (GetDWARF(), m_cu); + else + return nullptr; +} + +const char * +DWARFDIE::GetPubname () const +{ + if (IsValid()) + return m_die->GetPubname (GetDWARF(), m_cu); + else + return nullptr; +} + +const char * +DWARFDIE::GetQualifiedName (std::string &storage) const +{ + if (IsValid()) + return m_die->GetQualifiedName (GetDWARF(), m_cu, storage); + else + return nullptr; +} + +lldb::LanguageType +DWARFDIE::GetLanguage () const +{ + if (IsValid()) + return m_cu->GetLanguageType(); + else + return lldb::eLanguageTypeUnknown; +} + + +lldb::ModuleSP +DWARFDIE::GetModule () const +{ + SymbolFileDWARF *dwarf = GetDWARF(); + if (dwarf) + return dwarf->GetObjectFile()->GetModule(); + else + return lldb::ModuleSP(); +} + +lldb_private::CompileUnit * +DWARFDIE::GetLLDBCompileUnit () const +{ + if (IsValid()) + return GetDWARF()->GetCompUnitForDWARFCompUnit(GetCU()); + else + return nullptr; +} + +lldb_private::Type * +DWARFDIE::ResolveType () const +{ + if (IsValid()) + return GetDWARF()->ResolveType(*this, true); + else + return nullptr; +} + +lldb_private::Type * +DWARFDIE::ResolveTypeUID (lldb::user_id_t uid) const +{ + SymbolFileDWARF *dwarf = GetDWARF(); + if (dwarf) + return dwarf->ResolveTypeUID(uid); + else + 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); + } + } +} + +void +DWARFDIE::GetDWARFDeclContext (DWARFDeclContext &dwarf_decl_ctx) const +{ + if (IsValid()) + { + m_die->GetDWARFDeclContext (GetDWARF(), GetCU(), dwarf_decl_ctx); + } + else + { + dwarf_decl_ctx.Clear(); + } +} + + +DWARFDIE +DWARFDIE::GetParentDeclContextDIE () const +{ + if (IsValid()) + return m_die->GetParentDeclContextDIE(GetDWARF(), m_cu); + else + return DWARFDIE(); +} + + +dw_offset_t +DWARFDIE::GetOffset () const +{ + if (IsValid()) + return m_die->GetOffset(); + else + return DW_INVALID_OFFSET; +} + +dw_offset_t +DWARFDIE::GetCompileUnitRelativeOffset () const +{ + if (IsValid()) + return m_die->GetOffset() - m_cu->GetOffset(); + else + return DW_INVALID_OFFSET; +} + +SymbolFileDWARF * +DWARFDIE::GetDWARF () const +{ + if (m_cu) + return m_cu->GetSymbolFileDWARF(); + else + return nullptr; +} + +lldb_private::TypeSystem * +DWARFDIE::GetTypeSystem () const +{ + if (m_cu) + return m_cu->GetTypeSystem(); + else + return nullptr; +} + +bool +DWARFDIE::IsStructOrClass () const +{ + const dw_tag_t tag = Tag(); + return tag == DW_TAG_class_type || tag == DW_TAG_structure_type; +} + +bool +DWARFDIE::HasChildren () const +{ + if (m_die) + return m_die->HasChildren(); + else + return false; +} + +bool +DWARFDIE::Supports_DW_AT_APPLE_objc_complete_type () const +{ + if (IsValid()) + return GetDWARF()->Supports_DW_AT_APPLE_objc_complete_type(m_cu); + else + return false; +} + +size_t +DWARFDIE::GetAttributes (DWARFAttributes &attributes, uint32_t depth) const +{ + if (IsValid()) + { + return m_die->GetAttributes (m_cu, + m_cu->GetFixedFormSizes(), + attributes, + depth); + } + if (depth == 0) + attributes.Clear(); + return 0; +} + + +bool +DWARFDIE::GetDIENamesAndRanges (const char * &name, + const char * &mangled, + DWARFRangeList& ranges, + int& decl_file, + int& decl_line, + int& decl_column, + int& call_file, + int& call_line, + int& call_column, + lldb_private::DWARFExpression *frame_base) const +{ + if (IsValid()) + { + return m_die->GetDIENamesAndRanges (GetDWARF(), + GetCU(), + name, + mangled, + ranges, + decl_file, + decl_line, + decl_column, + call_file, + call_line, + call_column, + frame_base); + } + else + return false; +} + +void +DWARFDIE::Dump (lldb_private::Stream *s, const uint32_t recurse_depth) const +{ + if (s && IsValid()) + m_die->Dump (GetDWARF(), GetCU(), *s, recurse_depth); +} + + +bool operator == (const DWARFDIE &lhs, const DWARFDIE &rhs) +{ + return lhs.GetDIE() == rhs.GetDIE() && lhs.GetCU() == rhs.GetCU(); +} + +bool operator != (const DWARFDIE &lhs, const DWARFDIE &rhs) +{ + return lhs.GetDIE() != rhs.GetDIE() || lhs.GetCU() != rhs.GetCU(); +} + + diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h new file mode 100644 index 00000000000..c6e2f5b54fa --- /dev/null +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h @@ -0,0 +1,261 @@ +//===-- DWARFDIE.h ----------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef SymbolFileDWARF_DWARFDIE_h_ +#define SymbolFileDWARF_DWARFDIE_h_ + +#include "lldb/lldb-types.h" +#include "lldb/Core/dwarf.h" + +class DWARFAttributes; +class DWARFCompileUnit; +class DWARFDebugInfoEntry; +class DWARFDeclContext; +class DWARFDIECollection; +class SymbolFileDWARF; + +class DWARFDIE +{ +public: + DWARFDIE () : + m_cu (nullptr), + m_die (nullptr) + { + } + + DWARFDIE (DWARFCompileUnit *cu, DWARFDebugInfoEntry *die) : + m_cu (cu), + m_die (die) + { + } + + DWARFDIE (const DWARFCompileUnit *cu, DWARFDebugInfoEntry *die) : + m_cu (const_cast<DWARFCompileUnit *>(cu)), + m_die (die) + { + } + + DWARFDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) : + m_cu (cu), + m_die (const_cast<DWARFDebugInfoEntry *>(die)) + { + } + + DWARFDIE (const DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) : + m_cu (const_cast<DWARFCompileUnit *>(cu)), + m_die (const_cast<DWARFDebugInfoEntry *>(die)) + { + } + + //---------------------------------------------------------------------- + // Tests + //---------------------------------------------------------------------- + operator bool () const + { + return IsValid(); + } + + bool + IsValid() const + { + return m_cu && m_die; + } + + bool + IsStructOrClass () const; + + bool + HasChildren () const; + + bool + Supports_DW_AT_APPLE_objc_complete_type () const; + + //---------------------------------------------------------------------- + // Accessors + //---------------------------------------------------------------------- + SymbolFileDWARF * + GetDWARF () const; + + DWARFCompileUnit * + GetCU() const + { + return m_cu; + } + + DWARFDebugInfoEntry * + GetDIE() const + { + return m_die; + } + + lldb_private::TypeSystem * + GetTypeSystem () const; + + void + Set (DWARFCompileUnit *cu, DWARFDebugInfoEntry *die) + { + if (cu && die) + { + m_cu = cu; + m_die = die; + } + else + { + Clear(); + } + } + + void + Clear () + { + m_cu = nullptr; + m_die = nullptr; + } + + //---------------------------------------------------------------------- + // Accessing information about a DIE + //---------------------------------------------------------------------- + dw_tag_t + Tag() const; + + const char * + GetTagAsCString () const; + + dw_offset_t + GetOffset () const; + + dw_offset_t + GetCompileUnitRelativeOffset () const; + + //---------------------------------------------------------------------- + // Get the LLDB user ID for this DIE. This is often just the DIE offset, + // but it might have a SymbolFileDWARF::GetID() in the high 32 bits if + // we are doing Darwin DWARF in .o file, or DWARF stand alone debug + // info. + //---------------------------------------------------------------------- + lldb::user_id_t + GetID() const; + + const char * + GetName () const; + + const char * + GetMangledName () const; + + const char * + GetPubname () const; + + const char * + GetQualifiedName (std::string &storage) const; + + lldb::LanguageType + GetLanguage () const; + + lldb::ModuleSP + GetModule () const; + + lldb_private::CompileUnit * + GetLLDBCompileUnit () const; + + lldb_private::Type * + ResolveType () const; + + // Resolve a type by UID using this DIE's DWARF file + lldb_private::Type * + ResolveTypeUID (lldb::user_id_t uid) const; + + //---------------------------------------------------------------------- + // Functions for obtaining DIE relations and references + //---------------------------------------------------------------------- + + DWARFDIE + GetParent () const; + + DWARFDIE + GetFirstChild () const; + + DWARFDIE + GetSibling () const; + + DWARFDIE + GetReferencedDIE (const dw_attr_t attr) const; + + //---------------------------------------------------------------------- + // Get a another DIE from the same DWARF file as this DIE. This will + // check the current DIE's compile unit first to see if "die_offset" is + // in the same compile unit, and fall back to checking the DWARF file. + //---------------------------------------------------------------------- + DWARFDIE + GetDIE (dw_offset_t die_offset) const; + + DWARFDIE + LookupDeepestBlock (lldb::addr_t file_addr) const; + + DWARFDIE + GetParentDeclContextDIE () const; + + //---------------------------------------------------------------------- + // DeclContext related functions + //---------------------------------------------------------------------- + void + GetDeclContextDIEs (DWARFDIECollection &decl_context_dies) const; + + void + GetDWARFDeclContext (DWARFDeclContext &dwarf_decl_ctx) const; + + //---------------------------------------------------------------------- + // Getting attribute values from the DIE. + // + // GetAttributeValueAsXXX() functions should only be used if you are + // looking for one or two attributes on a DIE. If you are trying to + // parse all attributes, use GetAttributes (...) instead + //---------------------------------------------------------------------- + const char * + GetAttributeValueAsString (const dw_attr_t attr, const char *fail_value) const; + + uint64_t + GetAttributeValueAsUnsigned (const dw_attr_t attr, uint64_t fail_value) const; + + int64_t + GetAttributeValueAsSigned (const dw_attr_t attr, int64_t fail_value) const; + + uint64_t + GetAttributeValueAsReference (const dw_attr_t attr, uint64_t fail_value) const; + + size_t + GetAttributes (DWARFAttributes &attributes, uint32_t depth = 0) const; + + bool + GetDIENamesAndRanges (const char * &name, + const char * &mangled, + DWARFRangeList& ranges, + int& decl_file, + int& decl_line, + int& decl_column, + int& call_file, + int& call_line, + int& call_column, + lldb_private::DWARFExpression *frame_base) const; + + //---------------------------------------------------------------------- + // Pretty printing + //---------------------------------------------------------------------- + + void + Dump (lldb_private::Stream *s, const uint32_t recurse_depth) const; + +protected: + DWARFCompileUnit *m_cu; + DWARFDebugInfoEntry *m_die; +}; + +bool operator == (const DWARFDIE &lhs, const DWARFDIE &rhs); +bool operator != (const DWARFDIE &lhs, const DWARFDIE &rhs); + +#endif // SymbolFileDWARF_DWARFDIE_h_ diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIECollection.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIECollection.cpp index 1beb75d3364..cc2a3823618 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIECollection.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIECollection.cpp @@ -19,7 +19,7 @@ using namespace lldb_private; using namespace std; bool -DWARFDIECollection::Insert(const DWARFDebugInfoEntry *die) +DWARFDIECollection::Insert(const DWARFDIE &die) { iterator end_pos = m_dies.end(); iterator insert_pos = upper_bound(m_dies.begin(), end_pos, die); @@ -30,17 +30,17 @@ DWARFDIECollection::Insert(const DWARFDebugInfoEntry *die) } void -DWARFDIECollection::Append (const DWARFDebugInfoEntry *die) +DWARFDIECollection::Append (const DWARFDIE &die) { m_dies.push_back (die); } -const DWARFDebugInfoEntry * -DWARFDIECollection::GetDIEPtrAtIndex(uint32_t idx) const +DWARFDIE +DWARFDIECollection::GetDIEAtIndex(uint32_t idx) const { if (idx < m_dies.size()) return m_dies[idx]; - return NULL; + return DWARFDIE(); } @@ -55,8 +55,6 @@ DWARFDIECollection::Dump(Stream *s, const char* title) const { if (title && title[0] != '\0') s->Printf( "%s\n", title); - const_iterator end_pos = m_dies.end(); - const_iterator pos; - for (pos = m_dies.begin(); pos != end_pos; ++pos) - s->Printf( "0x%8.8x\n", (*pos)->GetOffset()); + for (const auto &die : m_dies) + s->Printf( "0x%8.8x\n", die.GetDIE()->GetOffset()); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIECollection.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIECollection.h index 173d0a5604d..e39e1aa4ccd 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIECollection.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIECollection.h @@ -10,7 +10,7 @@ #ifndef SymbolFileDWARF_DWARFDIECollection_h_ #define SymbolFileDWARF_DWARFDIECollection_h_ -#include "SymbolFileDWARF.h" +#include "DWARFDIE.h" #include <vector> class DWARFDIECollection @@ -25,22 +25,22 @@ public: } void - Append (const DWARFDebugInfoEntry *die); + Append (const DWARFDIE &die); void Dump(lldb_private::Stream *s, const char* title) const; - const DWARFDebugInfoEntry* - GetDIEPtrAtIndex(uint32_t idx) const; + DWARFDIE + GetDIEAtIndex (uint32_t idx) const; bool - Insert(const DWARFDebugInfoEntry *die); + Insert(const DWARFDIE &die); size_t Size() const; protected: - typedef std::vector<const DWARFDebugInfoEntry *> collection; + typedef std::vector<DWARFDIE> collection; typedef collection::iterator iterator; typedef collection::const_iterator const_iterator; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp index 133f4acb46d..62bba324dd3 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp @@ -107,50 +107,41 @@ DWARFDebugInfo::GetCompileUnitAranges () //---------------------------------------------------------------------- // LookupAddress //---------------------------------------------------------------------- -bool -DWARFDebugInfo::LookupAddress -( - const dw_addr_t address, - const dw_offset_t hint_die_offset, - DWARFCompileUnitSP& cu_sp, - DWARFDebugInfoEntry** function_die, - DWARFDebugInfoEntry** block_die -) +DWARFDIE +DWARFDebugInfo::LookupAddress (const dw_addr_t address, + const dw_offset_t hint_die_offset) { - + DWARFDIE die; + DWARFCompileUnit *cu = nullptr; if (hint_die_offset != DW_INVALID_OFFSET) - cu_sp = GetCompileUnit(hint_die_offset); + { + cu = GetCompileUnit(hint_die_offset); + } else { DWARFDebugAranges &cu_aranges = GetCompileUnitAranges (); const dw_offset_t cu_offset = cu_aranges.FindAddress (address); - cu_sp = GetCompileUnit(cu_offset); + cu = GetCompileUnit(cu_offset); } - if (cu_sp.get()) + if (cu) { - if (cu_sp->LookupAddress(address, function_die, block_die)) - return true; - cu_sp.reset(); + die = cu->LookupAddress(address); } else { // The hint_die_offset may have been a pointer to the actual item that // we are looking for - DWARFDebugInfoEntry* die_ptr = GetDIEPtr(hint_die_offset, &cu_sp); - if (die_ptr) + die = GetDIE(hint_die_offset); + if (die) { - if (cu_sp.get()) - { - if (function_die || block_die) - return die_ptr->LookupAddress(address, m_dwarf2Data, cu_sp.get(), function_die, block_die); + DWARFDebugInfoEntry* function_die = nullptr; - // We only wanted the compile unit that contained this address - return true; - } + if (die.GetDIE()->LookupAddress (address, die.GetDWARF(), die.GetCU(), &function_die, nullptr)) + die.Set (die.GetCU(), function_die); } } - return false; + return die; } @@ -219,7 +210,7 @@ OffsetLessThanCompileUnitOffset (dw_offset_t offset, const DWARFCompileUnitSP& c return offset < cu_sp->GetOffset(); } -DWARFCompileUnitSP +DWARFCompileUnit * DWARFDebugInfo::GetCompileUnit(dw_offset_t cu_offset, uint32_t* idx_ptr) { DWARFCompileUnitSP cu_sp; @@ -256,11 +247,11 @@ DWARFDebugInfo::GetCompileUnit(dw_offset_t cu_offset, uint32_t* idx_ptr) } if (idx_ptr) *idx_ptr = cu_idx; - return cu_sp; + return cu_sp.get(); } -DWARFCompileUnitSP -DWARFDebugInfo::GetCompileUnitContainingDIE(dw_offset_t die_offset) +DWARFCompileUnit * +DWARFDebugInfo::GetCompileUnitContainingDIE (dw_offset_t die_offset) { DWARFCompileUnitSP cu_sp; if (die_offset != DW_INVALID_OFFSET) @@ -287,7 +278,7 @@ DWARFDebugInfo::GetCompileUnitContainingDIE(dw_offset_t die_offset) } } } - return cu_sp; + return cu_sp.get(); } //---------------------------------------------------------------------- @@ -295,50 +286,23 @@ DWARFDebugInfo::GetCompileUnitContainingDIE(dw_offset_t die_offset) // // Get the DIE (Debug Information Entry) with the specified offset. //---------------------------------------------------------------------- -DWARFDebugInfoEntry* -DWARFDebugInfo::GetDIEPtr(dw_offset_t die_offset, DWARFCompileUnitSP* cu_sp_ptr) +DWARFDIE +DWARFDebugInfo::GetDIE(dw_offset_t die_offset) { - DWARFCompileUnitSP cu_sp(GetCompileUnitContainingDIE(die_offset)); - if (cu_sp_ptr) - *cu_sp_ptr = cu_sp; - if (cu_sp.get()) - return cu_sp->GetDIEPtr(die_offset); - return NULL; // Not found in any compile units + DWARFCompileUnit *cu = GetCompileUnitContainingDIE(die_offset); + if (cu) + return cu->GetDIE (die_offset); + return DWARFDIE(); // Not found } -DWARFDebugInfoEntry* -DWARFDebugInfo::GetDIEPtrWithCompileUnitHint (dw_offset_t die_offset, DWARFCompileUnit**cu_handle) +DWARFDIE +DWARFDebugInfo::GetDIEContainingOffset (dw_offset_t die_offset) { - assert (cu_handle); - DWARFDebugInfoEntry* die = NULL; - if (*cu_handle) - die = (*cu_handle)->GetDIEPtr(die_offset); + DWARFCompileUnit *cu = GetCompileUnitContainingDIE(die_offset); + if (cu) + return cu->GetDIEContainingOffset (die_offset); - if (die == NULL) - { - DWARFCompileUnitSP cu_sp (GetCompileUnitContainingDIE(die_offset)); - if (cu_sp.get()) - { - *cu_handle = cu_sp.get(); - die = cu_sp->GetDIEPtr(die_offset); - } - } - if (die == NULL) - *cu_handle = NULL; - return die; -} - - -const DWARFDebugInfoEntry* -DWARFDebugInfo::GetDIEPtrContainingOffset(dw_offset_t die_offset, DWARFCompileUnitSP* cu_sp_ptr) -{ - DWARFCompileUnitSP cu_sp(GetCompileUnitContainingDIE(die_offset)); - if (cu_sp_ptr) - *cu_sp_ptr = cu_sp; - if (cu_sp.get()) - return cu_sp->GetDIEPtrContainingOffset(die_offset); - - return NULL; // Not found in any compile units + return DWARFDIE(); // Not found } @@ -391,7 +355,7 @@ DWARFDebugInfo::Parse(SymbolFileDWARF* dwarf2Data, Callback callback, void* user depth = 0; // Call the callback function with no DIE pointer for the compile unit // and get the offset that we are to continue to parse from - offset = callback(dwarf2Data, cu, NULL, offset, depth, userData); + offset = callback(dwarf2Data, cu.get(), NULL, offset, depth, userData); // Make sure we are within our compile unit if (offset < next_cu_offset) @@ -402,7 +366,7 @@ DWARFDebugInfo::Parse(SymbolFileDWARF* dwarf2Data, Callback callback, void* user while (!done && die.Extract(dwarf2Data, cu.get(), &offset)) { // Call the callback function with DIE pointer that falls within the compile unit - offset = callback(dwarf2Data, cu, &die, offset, depth, userData); + offset = callback(dwarf2Data, cu.get(), &die, offset, depth, userData); if (die.IsNULL()) { @@ -469,7 +433,7 @@ typedef struct DumpInfo static dw_offset_t DumpCallback ( SymbolFileDWARF* dwarf2Data, - DWARFCompileUnitSP& cu_sp, + DWARFCompileUnit* cu, DWARFDebugInfoEntry* die, const dw_offset_t next_offset, const uint32_t curr_depth, @@ -477,9 +441,6 @@ static dw_offset_t DumpCallback ) { DumpInfo* dumpInfo = (DumpInfo*)userData; - - const DWARFCompileUnit* cu = cu_sp.get(); - Stream *s = dumpInfo->strm; bool show_parents = s->GetFlags().Test(DWARFDebugInfo::eDumpFlag_ShowAncestors); @@ -696,11 +657,11 @@ DWARFDebugInfo::Dump (Stream *s, const uint32_t die_offset, const uint32_t recur for (pos = m_compile_units.begin(); pos != m_compile_units.end(); ++pos) { const DWARFCompileUnitSP& cu_sp = *pos; - DumpCallback(m_dwarf2Data, (DWARFCompileUnitSP&)cu_sp, NULL, 0, curr_depth, &dumpInfo); + DumpCallback(m_dwarf2Data, cu_sp.get(), NULL, 0, curr_depth, &dumpInfo); - const DWARFDebugInfoEntry* die = cu_sp->DIE(); + const DWARFDIE die = cu_sp->DIE(); if (die) - die->Dump(m_dwarf2Data, cu_sp.get(), *s, recurse_depth); + die.Dump(s, recurse_depth); } } @@ -726,7 +687,7 @@ typedef struct FindCallbackStringInfoTag static dw_offset_t FindCallbackString ( SymbolFileDWARF* dwarf2Data, - DWARFCompileUnitSP& cu_sp, + DWARFCompileUnit* cu, DWARFDebugInfoEntry* die, const dw_offset_t next_offset, const uint32_t curr_depth, @@ -734,7 +695,6 @@ static dw_offset_t FindCallbackString ) { FindCallbackStringInfo* info = (FindCallbackStringInfo*)userData; - const DWARFCompileUnit* cu = cu_sp.get(); if (die) { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h index 50a7ae76921..cdcb8867974 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h @@ -16,6 +16,7 @@ #include "lldb/lldb-private.h" #include "lldb/lldb-private.h" #include "SymbolFileDWARF.h" +#include "DWARFDIE.h" typedef std::multimap<const char*, dw_offset_t, CStringCompareFunctionObject> CStringToDIEMap; typedef CStringToDIEMap::iterator CStringToDIEMapIter; @@ -28,7 +29,7 @@ class DWARFDebugInfo public: typedef dw_offset_t (*Callback)( SymbolFileDWARF* dwarf2Data, - DWARFCompileUnitSP& cu_shared_ptr, + DWARFCompileUnit* cu_shared_ptr, DWARFDebugInfoEntry* die, const dw_offset_t next_offset, const uint32_t depth, @@ -37,24 +38,19 @@ public: DWARFDebugInfo(); void SetDwarfData(SymbolFileDWARF* dwarf2Data); - bool LookupAddress( - const dw_addr_t address, - const dw_offset_t cu_offset, // Can be valid (find in .debug_aranges), or DW_INVALID_OFFSET if we need to search manually - DWARFCompileUnitSP& cu_shared_ptr, - DWARFDebugInfoEntry** function_die, - DWARFDebugInfoEntry** block_die); + DWARFDIE + LookupAddress(const dw_addr_t address, + const dw_offset_t cu_offset); // Can be valid (find in .debug_aranges), or DW_INVALID_OFFSET if we need to search manually void AddCompileUnit(DWARFCompileUnitSP& cu); size_t GetNumCompileUnits(); bool ContainsCompileUnit (const DWARFCompileUnit *cu) const; - DWARFCompileUnit* GetCompileUnitAtIndex(uint32_t idx); - DWARFCompileUnitSP GetCompileUnit(dw_offset_t cu_offset, uint32_t* idx_ptr = NULL); - DWARFCompileUnitSP GetCompileUnitContainingDIE(dw_offset_t die_offset); + DWARFCompileUnit* GetCompileUnitAtIndex (uint32_t idx); + DWARFCompileUnit* GetCompileUnit (dw_offset_t cu_offset, uint32_t* idx_ptr = NULL); + DWARFCompileUnit* GetCompileUnitContainingDIE (dw_offset_t die_offset); - DWARFDebugInfoEntry* GetDIEPtr(dw_offset_t die_offset, DWARFCompileUnitSP* cu_sp_ptr); - DWARFDebugInfoEntry* GetDIEPtrWithCompileUnitHint (dw_offset_t die_offset, DWARFCompileUnit**cu_handle); - - const DWARFDebugInfoEntry* GetDIEPtrContainingOffset(dw_offset_t die_offset, DWARFCompileUnitSP* cu_sp_ptr); + DWARFDIE GetDIE (dw_offset_t die_offset); + DWARFDIE GetDIEContainingOffset (dw_offset_t die_offset); void Dump(lldb_private::Stream *s, const uint32_t die_offset, const uint32_t recurse_depth); static void Parse(SymbolFileDWARF* parser, Callback callback, void* userData); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp index 86facaebe10..efe93999e91 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp @@ -34,86 +34,6 @@ using namespace lldb_private; using namespace std; extern int g_verbose; - - -DWARFDebugInfoEntry::Attributes::Attributes() : - m_infos() -{ -} - -DWARFDebugInfoEntry::Attributes::~Attributes() -{ -} - - -uint32_t -DWARFDebugInfoEntry::Attributes::FindAttributeIndex(dw_attr_t attr) const -{ - collection::const_iterator end = m_infos.end(); - collection::const_iterator beg = m_infos.begin(); - collection::const_iterator pos; - for (pos = beg; pos != end; ++pos) - { - if (pos->attr == attr) - return std::distance(beg, pos); - } - return UINT32_MAX; -} - -void -DWARFDebugInfoEntry::Attributes::Append(const DWARFCompileUnit *cu, dw_offset_t attr_die_offset, dw_attr_t attr, dw_form_t form) -{ - Info info = { cu, attr_die_offset, attr, form }; - m_infos.push_back(info); -} - -bool -DWARFDebugInfoEntry::Attributes::ContainsAttribute(dw_attr_t attr) const -{ - return FindAttributeIndex(attr) != UINT32_MAX; -} - -bool -DWARFDebugInfoEntry::Attributes::RemoveAttribute(dw_attr_t attr) -{ - uint32_t attr_index = FindAttributeIndex(attr); - if (attr_index != UINT32_MAX) - { - m_infos.erase(m_infos.begin() + attr_index); - return true; - } - return false; -} - -bool -DWARFDebugInfoEntry::Attributes::ExtractFormValueAtIndex (SymbolFileDWARF* dwarf2Data, uint32_t i, DWARFFormValue &form_value) const -{ - form_value.SetCompileUnit(CompileUnitAtIndex(i)); - form_value.SetForm(FormAtIndex(i)); - lldb::offset_t offset = DIEOffsetAtIndex(i); - return form_value.ExtractValue(dwarf2Data->get_debug_info_data(), &offset); -} - -uint64_t -DWARFDebugInfoEntry::Attributes::FormValueAsUnsigned (SymbolFileDWARF* dwarf2Data, dw_attr_t attr, uint64_t fail_value) const -{ - const uint32_t attr_idx = FindAttributeIndex (attr); - if (attr_idx != UINT32_MAX) - return FormValueAsUnsignedAtIndex (dwarf2Data, attr_idx, fail_value); - return fail_value; -} - -uint64_t -DWARFDebugInfoEntry::Attributes::FormValueAsUnsignedAtIndex(SymbolFileDWARF* dwarf2Data, uint32_t i, uint64_t fail_value) const -{ - DWARFFormValue form_value; - if (ExtractFormValueAtIndex(dwarf2Data, i, form_value)) - return form_value.Reference(); - return fail_value; -} - - - bool DWARFDebugInfoEntry::FastExtract ( @@ -530,8 +450,8 @@ DWARFDebugInfoEntry::DumpAncestry // else if (a_tag > b_tag) // return 1; // -// DWARFDebugInfoEntry::Attributes a_attrs; -// DWARFDebugInfoEntry::Attributes b_attrs; +// DWARFAttributes a_attrs; +// DWARFAttributes b_attrs; // size_t a_attr_count = a_die->GetAttributes(dwarf2Data, a_cu, a_attrs); // size_t b_attr_count = b_die->GetAttributes(dwarf2Data, b_cu, b_attrs); // if (a_attr_count != b_attr_count) @@ -743,7 +663,7 @@ DWARFDebugInfoEntry::GetDIENamesAndRanges const DWARFCompileUnit* cu, const char * &name, const char * &mangled, - DWARFDebugRanges::RangeList& ranges, + DWARFRangeList& ranges, int& decl_file, int& decl_line, int& decl_column, @@ -823,13 +743,13 @@ DWARFDebugInfoEntry::GetDIENamesAndRanges case DW_AT_name: if (name == NULL) - name = form_value.AsCString(dwarf2Data); + name = form_value.AsCString(); break; case DW_AT_MIPS_linkage_name: case DW_AT_linkage_name: if (mangled == NULL) - mangled = form_value.AsCString(dwarf2Data); + mangled = form_value.AsCString(); break; case DW_AT_abstract_origin: @@ -914,9 +834,9 @@ DWARFDebugInfoEntry::GetDIENamesAndRanges if (lo_pc != LLDB_INVALID_ADDRESS) { if (hi_pc != LLDB_INVALID_ADDRESS && hi_pc > lo_pc) - ranges.Append(DWARFDebugRanges::Range (lo_pc, hi_pc - lo_pc)); + ranges.Append(DWARFRangeList::Entry (lo_pc, hi_pc - lo_pc)); else - ranges.Append(DWARFDebugRanges::Range (lo_pc, 0)); + ranges.Append(DWARFRangeList::Entry (lo_pc, 0)); } } @@ -933,14 +853,12 @@ DWARFDebugInfoEntry::GetDIENamesAndRanges std::vector<dw_offset_t>::const_iterator end = die_offsets.end(); for (pos = die_offsets.begin(); pos != end; ++pos) { - DWARFCompileUnitSP cu_sp_ptr; - const DWARFDebugInfoEntry* die = NULL; dw_offset_t die_offset = *pos; if (die_offset != DW_INVALID_OFFSET) { - die = dwarf2Data->DebugInfo()->GetDIEPtr(die_offset, &cu_sp_ptr); + DWARFDIE die = dwarf2Data->DebugInfo()->GetDIE(die_offset); if (die) - die->GetDIENamesAndRanges(dwarf2Data, cu_sp_ptr.get(), name, mangled, ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column); + die.GetDIE()->GetDIENamesAndRanges(die.GetDWARF(), die.GetCU(), name, mangled, ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column); } } } @@ -1097,7 +1015,7 @@ DWARFDebugInfoEntry::DumpAttribute // Always dump form value if verbose is enabled if (verbose) { - form_value.Dump(s, dwarf2Data); + form_value.Dump(s); } @@ -1130,7 +1048,7 @@ DWARFDebugInfoEntry::DumpAttribute if (blockData) { if (!verbose) - form_value.Dump(s, dwarf2Data); + form_value.Dump(s); // Location description is inlined in data in the form value DWARFDataExtractor locationData(debug_info_data, (*offset_ptr) - form_value.Unsigned(), form_value.Unsigned()); @@ -1147,13 +1065,13 @@ DWARFDebugInfoEntry::DumpAttribute if (dwarf2Data) { if ( !verbose ) - form_value.Dump(s, dwarf2Data); + form_value.Dump(s); DWARFLocationList::Dump(s, cu, dwarf2Data->get_debug_loc_data(), debug_loc_offset); } else { if ( !verbose ) - form_value.Dump(s, NULL); + form_value.Dump(s); } } } @@ -1163,7 +1081,7 @@ DWARFDebugInfoEntry::DumpAttribute case DW_AT_specification: { uint64_t abstract_die_offset = form_value.Reference(); - form_value.Dump(s, dwarf2Data); + form_value.Dump(s); // *ostrm_ptr << HEX32 << abstract_die_offset << " ( "; if ( verbose ) s.PutCString(" ( "); GetName(dwarf2Data, cu, abstract_die_offset, s); @@ -1175,7 +1093,7 @@ DWARFDebugInfoEntry::DumpAttribute { uint64_t type_die_offset = form_value.Reference(); if (!verbose) - form_value.Dump(s, dwarf2Data); + form_value.Dump(s); s.PutCString(" ( "); AppendTypeName(dwarf2Data, cu, type_die_offset, s); s.PutCString(" )"); @@ -1185,7 +1103,7 @@ DWARFDebugInfoEntry::DumpAttribute case DW_AT_ranges: { if ( !verbose ) - form_value.Dump(s, dwarf2Data); + form_value.Dump(s); lldb::offset_t ranges_offset = form_value.Unsigned(); dw_addr_t base_addr = cu ? cu->GetBaseAddress() : 0; if (dwarf2Data) @@ -1195,7 +1113,7 @@ DWARFDebugInfoEntry::DumpAttribute default: if ( !verbose ) - form_value.Dump(s, dwarf2Data); + form_value.Dump(s); break; } @@ -1209,17 +1127,19 @@ DWARFDebugInfoEntry::DumpAttribute // take precedence (this can happen for declaration attributes). //---------------------------------------------------------------------- size_t -DWARFDebugInfoEntry::GetAttributes -( - SymbolFileDWARF* dwarf2Data, - const DWARFCompileUnit* cu, - DWARFFormValue::FixedFormSizes fixed_form_sizes, - DWARFDebugInfoEntry::Attributes& attributes, - uint32_t curr_depth -) const +DWARFDebugInfoEntry::GetAttributes (const DWARFCompileUnit* cu, + DWARFFormValue::FixedFormSizes fixed_form_sizes, + DWARFAttributes& attributes, + uint32_t curr_depth) const { - lldb::offset_t offset; - const DWARFAbbreviationDeclaration* abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset); + SymbolFileDWARF* dwarf2Data = nullptr; + const DWARFAbbreviationDeclaration* abbrevDecl = nullptr; + lldb::offset_t offset = 0; + if (cu) + { + dwarf2Data = cu->GetSymbolFileDWARF(); + abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset); + } if (abbrevDecl) { @@ -1262,21 +1182,10 @@ DWARFDebugInfoEntry::GetAttributes DWARFFormValue form_value (cu, form); if (form_value.ExtractValue(debug_info_data, &offset)) { - const DWARFDebugInfoEntry* die = NULL; dw_offset_t die_offset = form_value.Reference(); - if (cu->ContainsDIEOffset(die_offset)) - { - die = const_cast<DWARFCompileUnit*>(cu)->GetDIEPtr(die_offset); - if (die) - die->GetAttributes(dwarf2Data, cu, fixed_form_sizes, attributes, curr_depth + 1); - } - else - { - DWARFCompileUnitSP cu_sp_ptr; - die = const_cast<SymbolFileDWARF*>(dwarf2Data)->DebugInfo()->GetDIEPtr(die_offset, &cu_sp_ptr); - if (die) - die->GetAttributes(dwarf2Data, cu_sp_ptr.get(), fixed_form_sizes, attributes, curr_depth + 1); - } + DWARFDIE spec_die = const_cast<DWARFCompileUnit*>(cu)->GetDIE(die_offset); + if (spec_die) + spec_die.GetAttributes(attributes, curr_depth + 1); } } else @@ -1363,7 +1272,7 @@ DWARFDebugInfoEntry::GetAttributeValueAsString { DWARFFormValue form_value; if (GetAttributeValue(dwarf2Data, cu, attr, form_value)) - return form_value.AsCString(dwarf2Data); + return form_value.AsCString(); return fail_value; } @@ -1450,7 +1359,7 @@ DWARFDebugInfoEntry::GetAttributeHighPC { dw_form_t form = form_value.Form(); if (form == DW_FORM_addr || form == DW_FORM_GNU_addr_index) - return form_value.Address(dwarf2Data); + return form_value.Address(); // DWARF4 can specify the hi_pc as an <offset-from-lowpc> return lo_pc + form_value.Unsigned(); @@ -1491,7 +1400,7 @@ DWARFDebugInfoEntry::GetAttributeAddressRange size_t DWARFDebugInfoEntry::GetAttributeAddressRanges(SymbolFileDWARF* dwarf2Data, const DWARFCompileUnit* cu, - DWARFDebugRanges::RangeList &ranges, + DWARFRangeList &ranges, bool check_hi_lo_pc) const { ranges.Clear(); @@ -1515,7 +1424,7 @@ DWARFDebugInfoEntry::GetAttributeAddressRanges(SymbolFileDWARF* dwarf2Data, if (GetAttributeAddressRange (dwarf2Data, cu, lo_pc, hi_pc, LLDB_INVALID_ADDRESS)) { if (lo_pc < hi_pc) - ranges.Append(DWARFDebugRanges::RangeList::Entry(lo_pc, hi_pc - lo_pc)); + ranges.Append(DWARFRangeList::Entry(lo_pc, hi_pc - lo_pc)); } } return ranges.GetSize(); @@ -1586,20 +1495,18 @@ DWARFDebugInfoEntry::GetName { DWARFFormValue form_value; if (GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value)) - return form_value.AsCString(dwarf2Data); + return form_value.AsCString(); else if (GetAttributeValue(dwarf2Data, cu, DW_AT_specification, form_value)) { - DWARFCompileUnitSP cu_sp_ptr; - const DWARFDebugInfoEntry* die = const_cast<SymbolFileDWARF*>(dwarf2Data)->DebugInfo()->GetDIEPtr(form_value.Reference(), &cu_sp_ptr); + DWARFDIE die = const_cast<DWARFCompileUnit*>(cu)->GetDIE(form_value.Reference()); if (die) - return die->GetName(dwarf2Data, cu_sp_ptr.get()); + return die.GetName(); } else if (GetAttributeValue(dwarf2Data, cu, DW_AT_abstract_origin, form_value)) { - DWARFCompileUnitSP cu_sp_ptr; - const DWARFDebugInfoEntry* die = const_cast<SymbolFileDWARF*>(dwarf2Data)->DebugInfo()->GetDIEPtr(form_value.Reference(), &cu_sp_ptr); + DWARFDIE die = const_cast<DWARFCompileUnit*>(cu)->GetDIE(form_value.Reference()); if (die) - return die->GetName(dwarf2Data, cu_sp_ptr.get()); + return die.GetName(); } return nullptr; } @@ -1623,15 +1530,15 @@ DWARFDebugInfoEntry::GetMangledName DWARFFormValue form_value; if (GetAttributeValue(dwarf2Data, cu, DW_AT_MIPS_linkage_name, form_value)) - name = form_value.AsCString(dwarf2Data); + name = form_value.AsCString(); if (GetAttributeValue(dwarf2Data, cu, DW_AT_linkage_name, form_value)) - name = form_value.AsCString(dwarf2Data); + name = form_value.AsCString(); if (substitute_name_allowed && name == nullptr) { if (GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value)) - name = form_value.AsCString(dwarf2Data); + name = form_value.AsCString(); } return name; } @@ -1657,19 +1564,16 @@ DWARFDebugInfoEntry::GetPubname DWARFFormValue form_value; if (GetAttributeValue(dwarf2Data, cu, DW_AT_MIPS_linkage_name, form_value)) - name = form_value.AsCString(dwarf2Data); + name = form_value.AsCString(); else if (GetAttributeValue(dwarf2Data, cu, DW_AT_linkage_name, form_value)) - name = form_value.AsCString(dwarf2Data); + name = form_value.AsCString(); else if (GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value)) - name = form_value.AsCString(dwarf2Data); + name = form_value.AsCString(); else if (GetAttributeValue(dwarf2Data, cu, DW_AT_specification, form_value)) { - // The specification DIE may be in another compile unit so we need - // to get a die and its compile unit. - DWARFCompileUnitSP cu_sp_ptr; - const DWARFDebugInfoEntry* die = const_cast<SymbolFileDWARF*>(dwarf2Data)->DebugInfo()->GetDIEPtr(form_value.Reference(), &cu_sp_ptr); + DWARFDIE die = const_cast<DWARFCompileUnit*>(cu)->GetDIE(form_value.Reference()); if (die) - return die->GetPubname(dwarf2Data, cu_sp_ptr.get()); + name = die.GetPubname(); } return name; } @@ -1713,7 +1617,7 @@ DWARFDebugInfoEntry::GetName DWARFFormValue form_value; if (die.GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value)) { - const char* name = form_value.AsCString(dwarf2Data); + const char* name = form_value.AsCString(); if (name) { s.PutCString(name); @@ -1914,16 +1818,12 @@ DWARFDebugInfoEntry::BuildFunctionAddressRangeTable } void -DWARFDebugInfoEntry::GetDeclContextDIEs (SymbolFileDWARF* dwarf2Data, - DWARFCompileUnit* cu, +DWARFDebugInfoEntry::GetDeclContextDIEs (DWARFCompileUnit* cu, DWARFDIECollection &decl_context_dies) const { - const DWARFDebugInfoEntry *parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu); - if (parent_decl_ctx_die && parent_decl_ctx_die != this) - { - decl_context_dies.Append(parent_decl_ctx_die); - parent_decl_ctx_die->GetDeclContextDIEs (dwarf2Data, cu, decl_context_dies); - } + + DWARFDIE die (cu, const_cast<DWARFDebugInfoEntry *>(this)); + die.GetDeclContextDIEs(decl_context_dies); } void @@ -1935,11 +1835,11 @@ DWARFDebugInfoEntry::GetDWARFDeclContext (SymbolFileDWARF* dwarf2Data, if (tag != DW_TAG_compile_unit) { dwarf_decl_ctx.AppendDeclContext(tag, GetName(dwarf2Data, cu)); - const DWARFDebugInfoEntry *parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu); - if (parent_decl_ctx_die && parent_decl_ctx_die != this) + DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu); + if (parent_decl_ctx_die && parent_decl_ctx_die.GetDIE() != this) { - if (parent_decl_ctx_die->Tag() != DW_TAG_compile_unit) - parent_decl_ctx_die->GetDWARFDeclContext (dwarf2Data, cu, dwarf_decl_ctx); + if (parent_decl_ctx_die.Tag() != DW_TAG_compile_unit) + parent_decl_ctx_die.GetDIE()->GetDWARFDeclContext (parent_decl_ctx_die.GetDWARF(), parent_decl_ctx_die.GetCU(), dwarf_decl_ctx); } } } @@ -1956,30 +1856,30 @@ DWARFDebugInfoEntry::MatchesDWARFDeclContext (SymbolFileDWARF* dwarf2Data, return this_dwarf_decl_ctx == dwarf_decl_ctx; } -const DWARFDebugInfoEntry * +DWARFDIE DWARFDebugInfoEntry::GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data, DWARFCompileUnit* cu) const { - DWARFDebugInfoEntry::Attributes attributes; - GetAttributes(dwarf2Data, cu, DWARFFormValue::FixedFormSizes(), attributes); + DWARFAttributes attributes; + GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes); return GetParentDeclContextDIE (dwarf2Data, cu, attributes); } -const DWARFDebugInfoEntry * +DWARFDIE DWARFDebugInfoEntry::GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data, DWARFCompileUnit* cu, - const DWARFDebugInfoEntry::Attributes& attributes) const + const DWARFAttributes& attributes) const { - const DWARFDebugInfoEntry * die = this; - - while (die != NULL) + DWARFDIE die (cu, const_cast<DWARFDebugInfoEntry *>(this)); + + while (die) { // If this is the original DIE that we are searching for a declaration // for, then don't look in the cache as we don't want our own decl // context to be our decl context... - if (die != this) + if (die.GetDIE() != this) { - switch (die->Tag()) + switch (die.Tag()) { case DW_TAG_compile_unit: case DW_TAG_namespace: @@ -1995,33 +1895,33 @@ DWARFDebugInfoEntry::GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data, dw_offset_t die_offset; - die_offset = attributes.FormValueAsUnsigned(dwarf2Data, DW_AT_specification, DW_INVALID_OFFSET); + die_offset = attributes.FormValueAsUnsigned(DW_AT_specification, DW_INVALID_OFFSET); if (die_offset != DW_INVALID_OFFSET) { - const DWARFDebugInfoEntry *spec_die = cu->GetDIEPtr (die_offset); + DWARFDIE spec_die = cu->GetDIE (die_offset); if (spec_die) - { - const DWARFDebugInfoEntry *spec_die_decl_ctx_die = spec_die->GetParentDeclContextDIE (dwarf2Data, cu); - if (spec_die_decl_ctx_die) - return spec_die_decl_ctx_die; - } + { + DWARFDIE decl_ctx_die = spec_die.GetParentDeclContextDIE(); + if (decl_ctx_die) + return decl_ctx_die; + } } - die_offset = attributes.FormValueAsUnsigned(dwarf2Data, DW_AT_abstract_origin, DW_INVALID_OFFSET); + die_offset = attributes.FormValueAsUnsigned(DW_AT_abstract_origin, DW_INVALID_OFFSET); if (die_offset != DW_INVALID_OFFSET) { - const DWARFDebugInfoEntry *abs_die = cu->GetDIEPtr (die_offset); + DWARFDIE abs_die = cu->GetDIE (die_offset); if (abs_die) { - const DWARFDebugInfoEntry *abs_die_decl_ctx_die = abs_die->GetParentDeclContextDIE (dwarf2Data, cu); - if (abs_die_decl_ctx_die) - return abs_die_decl_ctx_die; + DWARFDIE decl_ctx_die = abs_die.GetParentDeclContextDIE(); + if (decl_ctx_die) + return decl_ctx_die; } } - die = die->GetParent(); + die = die.GetParent(); } - return NULL; + return DWARFDIE(); } @@ -2030,15 +1930,15 @@ DWARFDebugInfoEntry::GetQualifiedName (SymbolFileDWARF* dwarf2Data, DWARFCompileUnit* cu, std::string &storage) const { - DWARFDebugInfoEntry::Attributes attributes; - GetAttributes(dwarf2Data, cu, DWARFFormValue::FixedFormSizes(), attributes); + DWARFAttributes attributes; + GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes); return GetQualifiedName (dwarf2Data, cu, attributes, storage); } const char* DWARFDebugInfoEntry::GetQualifiedName (SymbolFileDWARF* dwarf2Data, DWARFCompileUnit* cu, - const DWARFDebugInfoEntry::Attributes& attributes, + const DWARFAttributes& attributes, std::string &storage) const { @@ -2046,47 +1946,47 @@ DWARFDebugInfoEntry::GetQualifiedName (SymbolFileDWARF* dwarf2Data, if (name) { - const DWARFDebugInfoEntry *parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu); + DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, 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(); + 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 (dwarf2Data, cu); - 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(dwarf2Data, cu); - } + { + 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 (dwarf2Data, cu); - - if (class_union_struct_name) - { - storage.insert (0, "::"); - storage.insert (0, class_union_struct_name); - } - parent_decl_ctx_die = parent_decl_ctx_die->GetParentDeclContextDIE(dwarf2Data, cu); - } + { + 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 = NULL; + parent_decl_ctx_die.Clear(); break; } } @@ -2234,7 +2134,7 @@ DWARFDebugInfoEntry::LookupAddress dw_offset_t debug_ranges_offset = GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET); if (debug_ranges_offset != DW_INVALID_OFFSET) { - DWARFDebugRanges::RangeList ranges; + DWARFRangeList ranges; DWARFDebugRanges* debug_ranges = dwarf2Data->DebugRanges(); debug_ranges->FindRanges(debug_ranges_offset, ranges); // All DW_AT_ranges are relative to the base address of the diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h index e8c937387ee..20b937c859c 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h @@ -57,38 +57,6 @@ public: typedef offset_collection::iterator offset_collection_iterator; typedef offset_collection::const_iterator offset_collection_const_iterator; - class Attributes - { - public: - Attributes(); - ~Attributes(); - - void Append(const DWARFCompileUnit *cu, dw_offset_t attr_die_offset, dw_attr_t attr, dw_form_t form); - const DWARFCompileUnit * CompileUnitAtIndex(uint32_t i) const { return m_infos[i].cu; } - dw_offset_t DIEOffsetAtIndex(uint32_t i) const { return m_infos[i].die_offset; } - dw_attr_t AttributeAtIndex(uint32_t i) const { return m_infos[i].attr; } - dw_attr_t FormAtIndex(uint32_t i) const { return m_infos[i].form; } - bool ExtractFormValueAtIndex (SymbolFileDWARF* dwarf2Data, uint32_t i, DWARFFormValue &form_value) const; - uint64_t FormValueAsUnsignedAtIndex (SymbolFileDWARF* dwarf2Data, uint32_t i, uint64_t fail_value) const; - uint64_t FormValueAsUnsigned (SymbolFileDWARF* dwarf2Data, dw_attr_t attr, uint64_t fail_value) const; - uint32_t FindAttributeIndex(dw_attr_t attr) const; - bool ContainsAttribute(dw_attr_t attr) const; - bool RemoveAttribute(dw_attr_t attr); - void Clear() { m_infos.clear(); } - size_t Size() const { return m_infos.size(); } - - protected: - struct Info - { - const DWARFCompileUnit *cu; // Keep the compile unit with each attribute in case we have DW_FORM_ref_addr values - dw_offset_t die_offset; - dw_attr_t attr; - dw_form_t form; - }; - typedef llvm::SmallVector<Info, 8> collection; - collection m_infos; - }; - struct CompareState { CompareState() : @@ -159,10 +127,9 @@ public: DWARFDebugInfoEntry** block_die); size_t GetAttributes( - SymbolFileDWARF* dwarf2Data, const DWARFCompileUnit* cu, DWARFFormValue::FixedFormSizes fixed_form_sizes, - DWARFDebugInfoEntry::Attributes& attrs, + DWARFAttributes& attrs, uint32_t curr_depth = 0) const; // "curr_depth" for internal use only, don't set this yourself!!! dw_offset_t GetAttributeValue( @@ -212,7 +179,7 @@ public: size_t GetAttributeAddressRanges ( SymbolFileDWARF* dwarf2Data, const DWARFCompileUnit* cu, - DWARFDebugRanges::RangeList &ranges, + DWARFRangeList &ranges, bool check_hi_lo_pc) const; dw_offset_t GetAttributeValueAsLocation( @@ -255,7 +222,7 @@ public: const char * GetQualifiedName ( SymbolFileDWARF* dwarf2Data, DWARFCompileUnit* cu, - const DWARFDebugInfoEntry::Attributes& attributes, + const DWARFAttributes& attributes, std::string &storage) const; // static int Compare( @@ -310,7 +277,7 @@ public: const DWARFCompileUnit* cu, const char * &name, const char * &mangled, - DWARFDebugRanges::RangeList& rangeList, + DWARFRangeList& rangeList, int& decl_file, int& decl_line, int& decl_column, @@ -375,8 +342,7 @@ public: const DWARFDebugInfoEntry* GetFirstChild() const { return (HasChildren() && !m_empty_children) ? this + 1 : NULL; } - void GetDeclContextDIEs (SymbolFileDWARF* dwarf2Data, - DWARFCompileUnit* cu, + void GetDeclContextDIEs (DWARFCompileUnit* cu, DWARFDIECollection &decl_context_dies) const; void GetDWARFDeclContext (SymbolFileDWARF* dwarf2Data, @@ -388,11 +354,11 @@ public: DWARFCompileUnit* cu, const DWARFDeclContext &dwarf_decl_ctx) const; - const DWARFDebugInfoEntry* GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data, + DWARFDIE GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data, DWARFCompileUnit* cu) const; - const DWARFDebugInfoEntry* GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data, + DWARFDIE GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data, DWARFCompileUnit* cu, - const DWARFDebugInfoEntry::Attributes& attributes) const; + const DWARFAttributes& attributes) const; void SetParent (DWARFDebugInfoEntry* parent) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugPubnames.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugPubnames.cpp index de019d09722..547bd0cd1a5 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugPubnames.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugPubnames.cpp @@ -100,17 +100,17 @@ DWARFDebugPubnames::GeneratePubnames(SymbolFileDWARF* dwarf2Data) size_t die_idx; for (die_idx = 0; die_idx < die_count; ++die_idx) { - const DWARFDebugInfoEntry *die = dies.GetDIEPtrAtIndex(die_idx); - DWARFDebugInfoEntry::Attributes attributes; + DWARFDIE die = dies.GetDIEAtIndex(die_idx); + DWARFAttributes attributes; const char *name = NULL; const char *mangled = NULL; bool add_die = false; - const size_t num_attributes = die->GetAttributes(dwarf2Data, cu, fixed_form_sizes, attributes); + const size_t num_attributes = die.GetDIE()->GetAttributes(die.GetCU(), fixed_form_sizes, attributes); if (num_attributes > 0) { uint32_t i; - dw_tag_t tag = die->Tag(); + dw_tag_t tag = die.Tag(); for (i=0; i<num_attributes; ++i) { @@ -119,14 +119,14 @@ DWARFDebugPubnames::GeneratePubnames(SymbolFileDWARF* dwarf2Data) switch (attr) { case DW_AT_name: - if (attributes.ExtractFormValueAtIndex(dwarf2Data, i, form_value)) - name = form_value.AsCString(dwarf2Data); + if (attributes.ExtractFormValueAtIndex(i, form_value)) + name = form_value.AsCString(); break; case DW_AT_MIPS_linkage_name: case DW_AT_linkage_name: - if (attributes.ExtractFormValueAtIndex(dwarf2Data, i, form_value)) - mangled = form_value.AsCString(dwarf2Data); + if (attributes.ExtractFormValueAtIndex(i, form_value)) + mangled = form_value.AsCString(); break; case DW_AT_low_pc: @@ -139,10 +139,10 @@ DWARFDebugPubnames::GeneratePubnames(SymbolFileDWARF* dwarf2Data) case DW_AT_location: if (tag == DW_TAG_variable) { - const DWARFDebugInfoEntry* parent_die = die->GetParent(); - while ( parent_die != NULL ) + DWARFDIE parent_die = die.GetParent(); + while ( parent_die ) { - switch (parent_die->Tag()) + switch (parent_die.Tag()) { case DW_TAG_subprogram: case DW_TAG_lexical_block: @@ -152,31 +152,16 @@ DWARFDebugPubnames::GeneratePubnames(SymbolFileDWARF* dwarf2Data) // if the location describes a hard coded address, but we don't want the performance // penalty of that right now. add_die = false; -// if (attributes.ExtractFormValueAtIndex(dwarf2Data, i, form_value)) -// { -// // If we have valid block data, then we have location expression bytes -// // that are fixed (not a location list). -// const uint8_t *block_data = form_value.BlockData(); -// if (block_data) -// { -// uint32_t block_length = form_value.Unsigned(); -// if (block_length == 1 + attributes.CompileUnitAtIndex(i)->GetAddressByteSize()) -// { -// if (block_data[0] == DW_OP_addr) -// add_die = true; -// } -// } -// } - parent_die = NULL; // Terminate the while loop. + parent_die.Clear(); // Terminate the while loop. break; case DW_TAG_compile_unit: add_die = true; - parent_die = NULL; // Terminate the while loop. + parent_die.Clear(); // Terminate the while loop. break; default: - parent_die = parent_die->GetParent(); // Keep going in the while loop. + parent_die = parent_die.GetParent(); // Keep going in the while loop. break; } } @@ -188,7 +173,7 @@ DWARFDebugPubnames::GeneratePubnames(SymbolFileDWARF* dwarf2Data) if (add_die && (name || mangled)) { - pubnames_set.AddDescriptor(die->GetOffset() - cu_offset, mangled ? mangled : name); + pubnames_set.AddDescriptor(die.GetCompileUnitRelativeOffset(), mangled ? mangled : name); } } @@ -230,13 +215,11 @@ DWARFDebugPubnames::GeneratePubBaseTypes(SymbolFileDWARF* dwarf2Data) size_t die_idx; for (die_idx = 0; die_idx < die_count; ++die_idx) { - const DWARFDebugInfoEntry *die = dies.GetDIEPtrAtIndex(die_idx); - const char *name = die->GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, NULL); + DWARFDIE die = dies.GetDIEAtIndex (die_idx); + const char *name = die.GetName(); if (name) - { - pubnames_set.AddDescriptor(die->GetOffset() - cu_offset, name); - } + pubnames_set.AddDescriptor(die.GetCompileUnitRelativeOffset(), name); } if (pubnames_set.NumDescriptors() > 0) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp index 0953554ffd7..fc2831f2243 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp @@ -27,7 +27,7 @@ DWARFDebugRanges::~DWARFDebugRanges() void DWARFDebugRanges::Extract(SymbolFileDWARF* dwarf2Data) { - RangeList range_list; + DWARFRangeList range_list; lldb::offset_t offset = 0; dw_offset_t debug_ranges_offset = offset; while (Extract(dwarf2Data, &offset, range_list)) @@ -38,52 +38,8 @@ DWARFDebugRanges::Extract(SymbolFileDWARF* dwarf2Data) } } -//void -//DWARFDebugRanges::RangeList::AddOffset(dw_addr_t offset) -//{ -// if (!ranges.empty()) -// { -// Range::iterator pos = ranges.begin(); -// Range::iterator end_pos = ranges.end(); -// for (pos = ranges.begin(); pos != end_pos; ++pos) -// { -// // assert for unsigned overflows -// assert (~pos->begin_offset >= offset); -// assert (~pos->end_offset >= offset); -// pos->begin_offset += offset; -// pos->end_offset += offset; -// } -// } -//} -// -//void -//DWARFDebugRanges::RangeList::SubtractOffset(dw_addr_t offset) -//{ -// if (!ranges.empty()) -// { -// Range::iterator pos = ranges.begin(); -// Range::iterator end_pos = ranges.end(); -// for (pos = ranges.begin(); pos != end_pos; ++pos) -// { -// assert (pos->begin_offset >= offset); -// assert (pos->end_offset >= offset); -// pos->begin_offset -= offset; -// pos->end_offset -= offset; -// } -// } -//} -// -// -//const DWARFDebugRanges::Range* -//DWARFDebugRanges::RangeList::RangeAtIndex(size_t i) const -//{ -// if (i < ranges.size()) -// return &ranges[i]; -// return NULL; -//} - bool -DWARFDebugRanges::Extract(SymbolFileDWARF* dwarf2Data, lldb::offset_t *offset_ptr, RangeList &range_list) +DWARFDebugRanges::Extract(SymbolFileDWARF* dwarf2Data, lldb::offset_t *offset_ptr, DWARFRangeList &range_list) { range_list.Clear(); @@ -118,13 +74,13 @@ DWARFDebugRanges::Extract(SymbolFileDWARF* dwarf2Data, lldb::offset_t *offset_pt break; default: - assert(!"DWARFDebugRanges::RangeList::Extract() unsupported address size."); + assert(!"DWARFRangeList::Extract() unsupported address size."); break; } // Filter out empty ranges if (begin < end) - range_list.Append(Range(begin, end - begin)); + range_list.Append(DWARFRangeList::Entry(begin, end - begin)); } // Make sure we consumed at least something @@ -178,7 +134,7 @@ DWARFDebugRanges::Dump(Stream &s, const DWARFDataExtractor& debug_ranges_data, l } bool -DWARFDebugRanges::FindRanges(dw_offset_t debug_ranges_offset, RangeList& range_list) const +DWARFDebugRanges::FindRanges(dw_offset_t debug_ranges_offset, DWARFRangeList& range_list) const { range_map_const_iterator pos = m_range_map.find(debug_ranges_offset); if (pos != m_range_map.end()) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h index 50af91d4100..3ff4ea3502c 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h @@ -11,34 +11,30 @@ #define SymbolFileDWARF_DWARFDebugRanges_h_ #include "SymbolFileDWARF.h" +#include "DWARFDIE.h" #include <map> -#include <vector> - -#include "lldb/Core/RangeMap.h" class DWARFDebugRanges { public: - typedef lldb_private::RangeArray<dw_addr_t, dw_addr_t, 2> RangeList; - typedef RangeList::Entry Range; DWARFDebugRanges(); ~DWARFDebugRanges(); void Extract(SymbolFileDWARF* dwarf2Data); static void Dump(lldb_private::Stream &s, const lldb_private::DWARFDataExtractor& debug_ranges_data, lldb::offset_t *offset_ptr, dw_addr_t cu_base_addr); - bool FindRanges(dw_offset_t debug_ranges_offset, DWARFDebugRanges::RangeList& range_list) const; + bool FindRanges(dw_offset_t debug_ranges_offset, DWARFRangeList& range_list) const; protected: bool Extract (SymbolFileDWARF* dwarf2Data, lldb::offset_t *offset_ptr, - RangeList &range_list); + DWARFRangeList &range_list); - typedef std::map<dw_offset_t, RangeList> range_map; - typedef range_map::iterator range_map_iterator; - typedef range_map::const_iterator range_map_const_iterator; + typedef std::map<dw_offset_t, DWARFRangeList> range_map; + typedef range_map::iterator range_map_iterator; + typedef range_map::const_iterator range_map_const_iterator; range_map m_range_map; }; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h index 3a99d2b3387..4c29447b47b 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h @@ -108,6 +108,13 @@ public: return lldb_private::ConstString (GetQualifiedName ()); } + void + Clear() + { + m_entries.clear(); + m_qualified_name.clear(); + } + protected: typedef std::vector<Entry> collection; collection m_entries; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp index 095f5996d89..a0ed9731a56 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp @@ -342,7 +342,7 @@ DWARFFormValue::SkipValue(dw_form_t form, const DWARFDataExtractor& debug_info_d void -DWARFFormValue::Dump(Stream &s, SymbolFileDWARF* symbol_file) const +DWARFFormValue::Dump(Stream &s) const { uint64_t uvalue = Unsigned(); bool cu_relative_offset = false; @@ -359,7 +359,7 @@ DWARFFormValue::Dump(Stream &s, SymbolFileDWARF* symbol_file) const case DW_FORM_data4: s.PutHex32(uvalue); break; case DW_FORM_ref_sig8: case DW_FORM_data8: s.PutHex64(uvalue); break; - case DW_FORM_string: s.QuotedCString(AsCString(symbol_file)); break; + case DW_FORM_string: s.QuotedCString(AsCString()); break; case DW_FORM_exprloc: case DW_FORM_block: case DW_FORM_block1: @@ -395,18 +395,18 @@ DWARFFormValue::Dump(Stream &s, SymbolFileDWARF* symbol_file) const case DW_FORM_sdata: s.PutSLEB128(uvalue); break; case DW_FORM_udata: s.PutULEB128(uvalue); break; case DW_FORM_strp: - if (symbol_file) { - if (verbose) - s.Printf(" .debug_str[0x%8.8x] = ", (uint32_t)uvalue); - - const char* dbg_str = AsCString(symbol_file); + const char* dbg_str = AsCString(); if (dbg_str) + { + if (verbose) + s.Printf(" .debug_str[0x%8.8x] = ", (uint32_t)uvalue); s.QuotedCString(dbg_str); - } - else - { - s.PutHex32(uvalue); + } + else + { + s.PutHex32(uvalue); + } } break; @@ -444,8 +444,10 @@ DWARFFormValue::Dump(Stream &s, SymbolFileDWARF* symbol_file) const } const char* -DWARFFormValue::AsCString(SymbolFileDWARF* symbol_file) const +DWARFFormValue::AsCString() const { + SymbolFileDWARF* symbol_file = m_cu->GetSymbolFileDWARF(); + if (m_form == DW_FORM_string) { return m_value.value.cstr; @@ -471,8 +473,10 @@ DWARFFormValue::AsCString(SymbolFileDWARF* symbol_file) const } dw_addr_t -DWARFFormValue::Address(SymbolFileDWARF* symbol_file) const +DWARFFormValue::Address() const { + SymbolFileDWARF* symbol_file = m_cu->GetSymbolFileDWARF(); + if (m_form == DW_FORM_addr) return Unsigned(); @@ -571,8 +575,7 @@ DWARFFormValue::IsDataForm(const dw_form_t form) int DWARFFormValue::Compare (const DWARFFormValue& a_value, - const DWARFFormValue& b_value, - SymbolFileDWARF* symbol_file) + const DWARFFormValue& b_value) { dw_form_t a_form = a_value.Form(); dw_form_t b_form = b_value.Form(); @@ -619,8 +622,8 @@ DWARFFormValue::Compare (const DWARFFormValue& a_value, case DW_FORM_strp: case DW_FORM_GNU_str_index: { - const char *a_string = a_value.AsCString(symbol_file); - const char *b_string = b_value.AsCString(symbol_file); + const char *a_string = a_value.AsCString(); + const char *b_string = b_value.AsCString(); if (a_string == b_string) return 0; else if (a_string && b_string) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h index 278f6289935..60990c0f0f6 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h @@ -14,7 +14,6 @@ #include "DWARFDataExtractor.h" class DWARFCompileUnit; -class SymbolFileDWARF; class DWARFFormValue { @@ -81,7 +80,7 @@ public: dw_form_t Form() const { return m_form; } void SetForm(dw_form_t form) { m_form = form; } const ValueType& Value() const { return m_value; } - void Dump(lldb_private::Stream &s, SymbolFileDWARF* symbol_file) const; + void Dump(lldb_private::Stream &s) const; bool ExtractValue(const lldb_private::DWARFDataExtractor& data, lldb::offset_t* offset_ptr); const uint8_t* BlockData() const; @@ -92,16 +91,15 @@ public: void SetUnsigned(uint64_t uval) { m_value.value.uval = uval; } int64_t Signed() const { return m_value.value.sval; } void SetSigned(int64_t sval) { m_value.value.sval = sval; } - const char* AsCString(SymbolFileDWARF* symbol_file) const; - dw_addr_t Address(SymbolFileDWARF* symbol_file) const; + const char* AsCString() const; + dw_addr_t Address() const; bool SkipValue(const lldb_private::DWARFDataExtractor& debug_info_data, lldb::offset_t *offset_ptr) const; static bool SkipValue(const dw_form_t form, const lldb_private::DWARFDataExtractor& debug_info_data, lldb::offset_t *offset_ptr, const DWARFCompileUnit* cu); static bool IsBlockForm(const dw_form_t form); static bool IsDataForm(const dw_form_t form); static FixedFormSizes GetFixedFormSizesForAddressSize (uint8_t addr_size, bool is_dwarf64); static int Compare (const DWARFFormValue& a, - const DWARFFormValue& b, - SymbolFileDWARF* symbol_file); + const DWARFFormValue& b); protected: const DWARFCompileUnit* m_cu; // Compile unit for this form dw_form_t m_form; // Form for this value diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index 33659248e18..03b65da793f 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -286,65 +286,61 @@ SymbolFileDWARF::GetTypeList () } void -SymbolFileDWARF::GetTypes (DWARFCompileUnit* cu, - const DWARFDebugInfoEntry *die, +SymbolFileDWARF::GetTypes (const DWARFDIE &die, dw_offset_t min_die_offset, dw_offset_t max_die_offset, uint32_t type_mask, TypeSet &type_set) { - if (cu) + if (die) { - if (die) + const dw_offset_t die_offset = die.GetOffset(); + + if (die_offset >= max_die_offset) + return; + + if (die_offset >= min_die_offset) { - const dw_offset_t die_offset = die->GetOffset(); + const dw_tag_t tag = die.Tag(); - if (die_offset >= max_die_offset) - return; - - if (die_offset >= min_die_offset) - { - const dw_tag_t tag = die->Tag(); - - bool add_type = false; + bool add_type = false; - switch (tag) - { - case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break; - case DW_TAG_unspecified_type: - case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break; - case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break; - case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break; - case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break; - case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break; - case DW_TAG_subroutine_type: - case DW_TAG_subprogram: - case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break; - case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break; - case DW_TAG_rvalue_reference_type: - case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break; - case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break; - case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break; - } + switch (tag) + { + case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break; + case DW_TAG_unspecified_type: + case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break; + case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break; + case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break; + case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break; + case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break; + case DW_TAG_subroutine_type: + case DW_TAG_subprogram: + case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break; + case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break; + case DW_TAG_rvalue_reference_type: + case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break; + case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break; + case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break; + } - if (add_type) + if (add_type) + { + const bool assert_not_being_parsed = true; + Type *type = ResolveTypeUID (die, assert_not_being_parsed); + if (type) { - const bool assert_not_being_parsed = true; - Type *type = ResolveTypeUID (cu, die, assert_not_being_parsed); - if (type) - { - if (type_set.find(type) == type_set.end()) - type_set.insert(type); - } + if (type_set.find(type) == type_set.end()) + type_set.insert(type); } } - - for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); - child_die != NULL; - child_die = child_die->GetSibling()) - { - GetTypes (cu, child_die, min_die_offset, max_die_offset, type_mask, type_set); - } + } + + for (DWARFDIE child_die = die.GetFirstChild(); + child_die.IsValid(); + child_die = child_die.GetSibling()) + { + GetTypes (child_die, min_die_offset, max_die_offset, type_mask, type_set); } } } @@ -367,8 +363,7 @@ SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope, dwarf_cu = GetDWARFCompileUnit(comp_unit); if (dwarf_cu == 0) return 0; - GetTypes (dwarf_cu, - dwarf_cu->DIE(), + GetTypes (dwarf_cu->DIE(), dwarf_cu->GetOffset(), dwarf_cu->GetNextCompileUnitOffset(), type_mask, @@ -385,8 +380,7 @@ SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope, dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); if (dwarf_cu) { - GetTypes (dwarf_cu, - dwarf_cu->DIE(), + GetTypes (dwarf_cu->DIE(), 0, UINT32_MAX, type_mask, @@ -395,68 +389,7 @@ SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope, } } } -// if (m_using_apple_tables) -// { -// DWARFMappedHash::MemoryTable *apple_types = m_apple_types_ap.get(); -// if (apple_types) -// { -// apple_types->ForEach([this, &type_set, apple_types, type_mask](const DWARFMappedHash::DIEInfoArray &die_info_array) -> bool { -// -// for (auto die_info: die_info_array) -// { -// bool add_type = TagMatchesTypeMask (type_mask, 0); -// if (!add_type) -// { -// dw_tag_t tag = die_info.tag; -// if (tag == 0) -// { -// const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_info.offset, NULL); -// tag = die->Tag(); -// } -// add_type = TagMatchesTypeMask (type_mask, tag); -// } -// if (add_type) -// { -// Type *type = ResolveTypeUID(die_info.offset); -// -// if (type_set.find(type) == type_set.end()) -// type_set.insert(type); -// } -// } -// return true; // Keep iterating -// }); -// } -// } -// else -// { -// if (!m_indexed) -// Index (); -// -// m_type_index.ForEach([this, &type_set, type_mask](const char *name, uint32_t die_offset) -> bool { -// -// bool add_type = TagMatchesTypeMask (type_mask, 0); -// -// if (!add_type) -// { -// const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_offset, NULL); -// if (die) -// { -// const dw_tag_t tag = die->Tag(); -// add_type = TagMatchesTypeMask (type_mask, tag); -// } -// } -// -// if (add_type) -// { -// Type *type = ResolveTypeUID(die_offset); -// -// if (type_set.find(type) == type_set.end()) -// type_set.insert(type); -// } -// return true; // Keep iterating -// }); -// } - + std::set<CompilerType> clang_type_set; size_t num_types_added = 0; for (Type *type : type_set) @@ -477,13 +410,13 @@ SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope, // Gets the first parent that is a lexical block, function or inlined // subroutine, or compile unit. //---------------------------------------------------------------------- -const DWARFDebugInfoEntry * -SymbolFileDWARF::GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die) +DWARFDIE +SymbolFileDWARF::GetParentSymbolContextDIE(const DWARFDIE &child_die) { - const DWARFDebugInfoEntry *die; - for (die = child_die->GetParent(); die != NULL; die = die->GetParent()) + DWARFDIE die; + for (die = child_die.GetParent(); die; die = die.GetParent()) { - dw_tag_t tag = die->Tag(); + dw_tag_t tag = die.Tag(); switch (tag) { @@ -494,7 +427,7 @@ SymbolFileDWARF::GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die) return die; } } - return NULL; + return DWARFDIE(); } @@ -921,7 +854,7 @@ SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) // TODO: modify to support LTO .o files where each .o file might // have multiple DW_TAG_compile_unit tags. - DWARFCompileUnit *dwarf_cu = info->GetCompileUnit(0).get(); + DWARFCompileUnit *dwarf_cu = info->GetCompileUnit(0); if (dwarf_cu && dwarf_cu->GetUserData() == NULL) dwarf_cu->SetUserData(comp_unit); return dwarf_cu; @@ -931,7 +864,7 @@ SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) // Just a normal DWARF file whose user ID for the compile unit is // the DWARF offset itself - DWARFCompileUnit *dwarf_cu = info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get(); + DWARFCompileUnit *dwarf_cu = info->GetCompileUnit((dw_offset_t)comp_unit->GetID()); if (dwarf_cu && dwarf_cu->GetUserData() == NULL) dwarf_cu->SetUserData(comp_unit); return dwarf_cu; @@ -1015,7 +948,7 @@ SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) cu_sp.reset(new CompileUnit (module_sp, dwarf_cu, cu_file_spec, - MakeUserID(dwarf_cu->GetOffset()), + dwarf_cu->GetID(), cu_language, is_optimized)); if (cu_sp) @@ -1074,14 +1007,18 @@ SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) } Function * -SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die) +SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, const DWARFDIE &die) { - TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType()); + if (die.IsValid()) + { + TypeSystem *type_system = GetTypeSystemForLanguage(die.GetCU()->GetLanguageType()); - if (type_system) - return type_system->ParseFunctionFromDWARF(sc, this, dwarf_cu, die); - else - return nullptr; + if (type_system) + { + return type_system->ParseFunctionFromDWARF(sc, die); + } + } + return nullptr; } bool @@ -1122,10 +1059,10 @@ SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) size_t func_idx; for (func_idx = 0; func_idx < num_functions; ++func_idx) { - const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx); - if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL) + DWARFDIE die = function_dies.GetDIEAtIndex(func_idx); + if (sc.comp_unit->FindFunctionByUID (die.GetID()).get() == NULL) { - if (ParseCompileUnitFunction(sc, dwarf_cu, die)) + if (ParseCompileUnitFunction(sc, die)) ++functions_added; } } @@ -1274,20 +1211,17 @@ SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) } size_t -SymbolFileDWARF::ParseFunctionBlocks -( - const SymbolContext& sc, - Block *parent_block, - DWARFCompileUnit* dwarf_cu, - const DWARFDebugInfoEntry *die, - addr_t subprogram_low_pc, - uint32_t depth -) +SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext& sc, + Block *parent_block, + const DWARFDIE &orig_die, + addr_t subprogram_low_pc, + uint32_t depth) { size_t blocks_added = 0; - while (die != NULL) + DWARFDIE die = orig_die; + while (die) { - dw_tag_t tag = die->Tag(); + dw_tag_t tag = die.Tag(); switch (tag) { @@ -1309,11 +1243,11 @@ SymbolFileDWARF::ParseFunctionBlocks } else { - BlockSP block_sp(new Block (MakeUserID(die->GetOffset()))); + BlockSP block_sp(new Block (die.GetID())); parent_block->AddChild(block_sp); block = block_sp.get(); } - DWARFDebugRanges::RangeList ranges; + DWARFRangeList ranges; const char *name = NULL; const char *mangled_name = NULL; @@ -1323,13 +1257,11 @@ SymbolFileDWARF::ParseFunctionBlocks int call_file = 0; int call_line = 0; int call_column = 0; - if (die->GetDIENamesAndRanges (this, - dwarf_cu, - name, - mangled_name, - ranges, - decl_file, decl_line, decl_column, - call_file, call_line, call_column)) + if (die.GetDIENamesAndRanges (name, + mangled_name, + ranges, + decl_file, decl_line, decl_column, + call_file, call_line, call_column, nullptr)) { if (tag == DW_TAG_subprogram) { @@ -1355,7 +1287,7 @@ SymbolFileDWARF::ParseFunctionBlocks const size_t num_ranges = ranges.GetSize(); for (size_t i = 0; i<num_ranges; ++i) { - const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i); + const DWARFRangeList::Entry &range = ranges.GetEntryRef (i); const addr_t range_base = range.GetRangeBase(); if (range_base >= subprogram_low_pc) block->AddRange(Block::Range (range_base - subprogram_low_pc, range.GetByteSize())); @@ -1387,12 +1319,11 @@ SymbolFileDWARF::ParseFunctionBlocks ++blocks_added; - if (die->HasChildren()) + if (die.HasChildren()) { blocks_added += ParseFunctionBlocks (sc, block, - dwarf_cu, - die->GetFirstChild(), + die.GetFirstChild(), subprogram_low_pc, depth + 1); } @@ -1408,22 +1339,21 @@ SymbolFileDWARF::ParseFunctionBlocks // DW_TAG_subprogram DIE if (depth == 0) - die = NULL; + die.Clear(); else - die = die->GetSibling(); + die = die.GetSibling(); } return blocks_added; } bool -SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu, - const DWARFDebugInfoEntry *parent_die) +SymbolFileDWARF::ClassOrStructIsVirtual (const DWARFDIE &parent_die) { if (parent_die) { - for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) + for (DWARFDIE die = parent_die.GetFirstChild(); die; die = die.GetSibling()) { - dw_tag_t tag = die->Tag(); + dw_tag_t tag = die.Tag(); bool check_virtuality = false; switch (tag) { @@ -1436,7 +1366,7 @@ SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu, } if (check_virtuality) { - if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0) + if (die.GetAttributeValueAsUnsigned(DW_AT_virtuality, 0) != 0) return true; } } @@ -1452,13 +1382,12 @@ SymbolFileDWARF::GetDeclContextForUID (lldb::user_id_t type_uid) DWARFDebugInfo* debug_info = DebugInfo(); if (debug_info) { - DWARFCompileUnitSP cu_sp; - const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); + DWARFDIE die = debug_info->GetDIE(type_uid); if (die) { - TypeSystem *type_system = GetTypeSystemForLanguage(cu_sp->GetLanguageType()); + TypeSystem *type_system = die.GetTypeSystem(); if (type_system) - return type_system->GetDeclContextForUIDFromDWARF(this, cu_sp.get(), die); + return type_system->GetDeclContextForUIDFromDWARF(die); } } } @@ -1473,13 +1402,12 @@ SymbolFileDWARF::GetDeclContextContainingUID (lldb::user_id_t type_uid) DWARFDebugInfo* debug_info = DebugInfo(); if (debug_info) { - DWARFCompileUnitSP cu_sp; - const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); + DWARFDIE die = debug_info->GetDIE(type_uid); if (die) { - TypeSystem *type_system = GetTypeSystemForLanguage(cu_sp->GetLanguageType()); + TypeSystem *type_system = die.GetTypeSystem(); if (type_system) - return type_system->GetDeclContextContainingUIDFromDWARF(this, cu_sp.get(), die); + return type_system->GetDeclContextContainingUIDFromDWARF(die); } } } @@ -1495,70 +1423,61 @@ SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) DWARFDebugInfo* debug_info = DebugInfo(); if (debug_info) { - DWARFCompileUnitSP cu_sp; - const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); - const bool assert_not_being_parsed = true; - return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed); + DWARFDIE type_die = debug_info->GetDIE (type_uid); + if (type_die) + { + const bool assert_not_being_parsed = true; + return ResolveTypeUID (type_die, assert_not_being_parsed); + } } } return NULL; } Type* -SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) +SymbolFileDWARF::ResolveTypeUID (const DWARFDIE &die, bool assert_not_being_parsed) { - if (die != NULL) + if (die) { Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); if (log) GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", - die->GetOffset(), - DW_TAG_value_to_name(die->Tag()), - die->GetName(this, cu)); + die.GetOffset(), + die.GetTagAsCString(), + die.GetName()); // We might be coming in in the middle of a type tree (a class // withing a class, an enum within a class), so parse any needed // parent DIEs before we get to this one... - const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); - switch (decl_ctx_die->Tag()) + DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE (die); + if (decl_ctx_die) { - case DW_TAG_structure_type: - case DW_TAG_union_type: - case DW_TAG_class_type: + if (log) { - // Get the type, which could be a forward declaration - if (log) - GetObjectFile()->GetModule()->LogMessage (log, - "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", - die->GetOffset(), - DW_TAG_value_to_name(die->Tag()), - die->GetName(this, cu), - decl_ctx_die->GetOffset()); -// -// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); -// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) -// { -// if (log) -// GetObjectFile()->GetModule()->LogMessage (log, -// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function", -// die->GetOffset(), -// DW_TAG_value_to_name(die->Tag()), -// die->GetName(this, cu), -// decl_ctx_die->GetOffset()); -// // Ask the type to complete itself if it already hasn't since if we -// // want a function (method or static) from a class, the class must -// // create itself and add it's own methods and class functions. -// if (parent_type) -// parent_type->GetFullCompilerType (); -// } - } - break; + switch (decl_ctx_die.Tag()) + { + case DW_TAG_structure_type: + case DW_TAG_union_type: + case DW_TAG_class_type: + { + // Get the type, which could be a forward declaration + if (log) + GetObjectFile()->GetModule()->LogMessage (log, + "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", + die.GetOffset(), + die.GetTagAsCString(), + die.GetName(), + decl_ctx_die.GetOffset()); + } + break; - default: - break; + default: + break; + } + } } - return ResolveType (cu, die); + return ResolveType (die); } return NULL; } @@ -1593,58 +1512,37 @@ SymbolFileDWARF::CompleteType (CompilerType &clang_type) m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType()); DWARFDebugInfo* debug_info = DebugInfo(); - DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); + DWARFDIE dwarf_die (debug_info->GetCompileUnitContainingDIE (die->GetOffset()), die); Type *type = m_die_to_type.lookup (die); Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); if (log) GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log, "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", - MakeUserID(die->GetOffset()), - DW_TAG_value_to_name(die->Tag()), + dwarf_die.GetID(), + dwarf_die.GetTagAsCString(), type->GetName().AsCString()); assert (clang_type); - DWARFDebugInfoEntry::Attributes attributes; + DWARFAttributes attributes; - TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType()); + TypeSystem *type_system = dwarf_die.GetTypeSystem(); if (type_system) - return type_system->CompleteTypeFromDWARF (this, dwarf_cu, die, type, clang_type); + return type_system->CompleteTypeFromDWARF (dwarf_die, type, clang_type); return false; } -void -SymbolFileDWARF::ClearDIEBeingParsed (const DWARFDebugInfoEntry* type_die) -{ - if (type_die) - { - if (m_die_to_type.lookup (type_die) == DIE_IS_BEING_PARSED) - m_die_to_type[type_die] = nullptr; - } -} -Type* -SymbolFileDWARF::GetCachedTypeForDIE (const DWARFDebugInfoEntry* type_die) const -{ - if (type_die) - { - Type *type = m_die_to_type.lookup (type_die); - if (type != DIE_IS_BEING_PARSED) - return type; - } - return nullptr; -} - Type* -SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed) +SymbolFileDWARF::ResolveType (const DWARFDIE &die, bool assert_not_being_parsed) { - if (type_die != NULL) + if (die) { - Type *type = m_die_to_type.lookup (type_die); + Type *type = m_die_to_type.lookup (die.GetDIE()); if (type == NULL) - type = GetTypeForDIE (dwarf_cu, type_die).get(); + type = GetTypeForDIE (die).get(); if (assert_not_being_parsed) { @@ -1652,15 +1550,15 @@ SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEn return type; GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s", - type_die->GetOffset(), - DW_TAG_value_to_name(type_die->Tag()), - type_die->GetName(this, dwarf_cu)); + die.GetOffset(), + die.GetTagAsCString(), + die.GetName()); } else return type; } - return NULL; + return nullptr; } CompileUnit* @@ -1696,20 +1594,24 @@ SymbolFileDWARF::GetObjCMethodDIEOffsets (ConstString class_name, DIEArray &meth } bool -SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) +SymbolFileDWARF::GetFunction (const DWARFDIE &die, SymbolContext& sc) { sc.Clear(false); - // Check if the symbol vendor already knows about this compile unit? - sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); - sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get(); - if (sc.function == NULL) - sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die); - - if (sc.function) - { - sc.module_sp = sc.function->CalculateSymbolContextModule(); - return true; + if (die) + { + // Check if the symbol vendor already knows about this compile unit? + sc.comp_unit = GetCompUnitForDWARFCompUnit(die.GetCU(), UINT32_MAX); + + sc.function = sc.comp_unit->FindFunctionByUID (die.GetID()).get(); + if (sc.function == NULL) + sc.function = ParseCompileUnitFunction(sc, die); + + if (sc.function) + { + sc.module_sp = sc.function->CalculateSymbolContextModule(); + return true; + } } return false; @@ -1867,7 +1769,7 @@ SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_ else { uint32_t cu_idx = DW_INVALID_INDEX; - DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); + DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx); if (dwarf_cu) { sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); @@ -1878,22 +1780,16 @@ SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_ bool force_check_line_table = false; if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) { - DWARFDebugInfoEntry *function_die = NULL; - DWARFDebugInfoEntry *block_die = NULL; - if (resolve_scope & eSymbolContextBlock) + DWARFDIE function_die = dwarf_cu->LookupAddress(file_vm_addr); + DWARFDIE block_die; + if (function_die) { - dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die); - } - else - { - dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL); - } - - if (function_die != NULL) - { - sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); + sc.function = sc.comp_unit->FindFunctionByUID (function_die.GetID()).get(); if (sc.function == NULL) - sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); + sc.function = ParseCompileUnitFunction(sc, function_die); + + if (sc.function && (resolve_scope & eSymbolContextBlock)) + block_die = function_die.LookupDeepestBlock(file_vm_addr); } else { @@ -1914,10 +1810,10 @@ SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_ { Block& block = sc.function->GetBlock (true); - if (block_die != NULL) - sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); + if (block_die) + sc.block = block.FindBlockByID (block_die.GetID()); else - sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); + sc.block = block.FindBlockByID (function_die.GetID()); if (sc.block) resolved |= eSymbolContextBlock; } @@ -2032,25 +1928,26 @@ SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); if (file_vm_addr != LLDB_INVALID_ADDRESS) { - DWARFDebugInfoEntry *function_die = NULL; - DWARFDebugInfoEntry *block_die = NULL; - dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL); - - if (function_die != NULL) + DWARFDIE function_die = dwarf_cu->LookupAddress(file_vm_addr); + DWARFDIE block_die; + if (function_die) { - sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); + sc.function = sc.comp_unit->FindFunctionByUID (function_die.GetID()).get(); if (sc.function == NULL) - sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); + sc.function = ParseCompileUnitFunction(sc, function_die); + + if (sc.function && (resolve_scope & eSymbolContextBlock)) + block_die = function_die.LookupDeepestBlock(file_vm_addr); } if (sc.function != NULL) { Block& block = sc.function->GetBlock (true); - if (block_die != NULL) - sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); - else if (function_die != NULL) - sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); + if (block_die) + sc.block = block.FindBlockByID (block_die.GetID()); + else if (function_die) + sc.block = block.FindBlockByID (function_die.GetID()); } } } @@ -2229,17 +2126,15 @@ SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const CompilerDec assert (sc.module_sp); DWARFDebugInfo* debug_info = DebugInfo(); - DWARFCompileUnit* dwarf_cu = NULL; - const DWARFDebugInfoEntry* die = NULL; bool done = false; for (size_t i=0; i<num_die_matches && !done; ++i) { const dw_offset_t die_offset = die_offsets[i]; - die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); + DWARFDIE die = debug_info->GetDIE (die_offset); if (die) { - switch (die->Tag()) + switch (die.Tag()) { default: case DW_TAG_subprogram: @@ -2250,21 +2145,21 @@ SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const CompilerDec case DW_TAG_variable: { - sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); + sc.comp_unit = GetCompUnitForDWARFCompUnit(die.GetCU(), UINT32_MAX); if (parent_decl_ctx) { - TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType()); + TypeSystem *type_system = die.GetTypeSystem(); if (type_system) { - CompilerDeclContext actual_parent_decl_ctx = type_system->GetDeclContextContainingUIDFromDWARF (this, dwarf_cu, die); + CompilerDeclContext actual_parent_decl_ctx = type_system->GetDeclContextContainingUIDFromDWARF (die); if (!actual_parent_decl_ctx || actual_parent_decl_ctx != *parent_decl_ctx) continue; } } - ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); + ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables); if (variables.GetSize() - original_size >= max_matches) done = true; @@ -2346,8 +2241,6 @@ SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append sc.module_sp = m_obj_file->GetModule(); assert (sc.module_sp); - DWARFCompileUnit* dwarf_cu = NULL; - const DWARFDebugInfoEntry* die = NULL; const size_t num_matches = die_offsets.size(); if (num_matches) { @@ -2355,13 +2248,13 @@ SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append for (size_t i=0; i<num_matches; ++i) { const dw_offset_t die_offset = die_offsets[i]; - die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); + DWARFDIE die = debug_info->GetDIE (die_offset); if (die) { - sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); + sc.comp_unit = GetCompUnitForDWARFCompUnit(die.GetCU(), UINT32_MAX); - ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); + ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables); if (variables.GetSize() - original_size >= max_matches) break; @@ -2384,52 +2277,58 @@ SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append bool SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset, - DWARFCompileUnit *&dwarf_cu, bool include_inlines, SymbolContextList& sc_list) { - const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); - return ResolveFunction (dwarf_cu, die, include_inlines, sc_list); + DWARFDIE die = DebugInfo()->GetDIE (die_offset); + return ResolveFunction (die, include_inlines, sc_list); } bool -SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu, - const DWARFDebugInfoEntry *die, +SymbolFileDWARF::ResolveFunction (const DWARFDIE &orig_die, bool include_inlines, SymbolContextList& sc_list) { SymbolContext sc; - if (die == NULL) + if (!orig_die) return false; // If we were passed a die that is not a function, just return false... - if (! (die->Tag() == DW_TAG_subprogram || (include_inlines && die->Tag() == DW_TAG_inlined_subroutine))) + if (!(orig_die.Tag() == DW_TAG_subprogram || (include_inlines && orig_die.Tag() == DW_TAG_inlined_subroutine))) return false; - - const DWARFDebugInfoEntry* inlined_die = NULL; - if (die->Tag() == DW_TAG_inlined_subroutine) + + DWARFDIE die = orig_die; + DWARFDIE inlined_die; + if (die.Tag() == DW_TAG_inlined_subroutine) { inlined_die = die; - while ((die = die->GetParent()) != NULL) + while (1) { - if (die->Tag() == DW_TAG_subprogram) + die = die.GetParent(); + + if (die) + { + if (die.Tag() == DW_TAG_subprogram) + break; + } + else break; } } - assert (die && die->Tag() == DW_TAG_subprogram); - if (GetFunction (cu, die, sc)) + assert (die && die.Tag() == DW_TAG_subprogram); + if (GetFunction (die, sc)) { Address addr; // Parse all blocks if needed if (inlined_die) { Block &function_block = sc.function->GetBlock (true); - sc.block = function_block.FindBlockByID (MakeUserID(inlined_die->GetOffset())); + sc.block = function_block.FindBlockByID (inlined_die.GetID()); if (sc.block == NULL) - sc.block = function_block.FindBlockByID (inlined_die->GetOffset()); + sc.block = function_block.FindBlockByID (inlined_die.GetOffset()); if (sc.block == NULL || sc.block->GetStartAddress (addr) == false) addr.Clear(); } @@ -2500,135 +2399,17 @@ SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, const size_t num_matches = die_offsets.size(); if (num_matches) { - DWARFCompileUnit* dwarf_cu = NULL; for (size_t i=0; i<num_matches; ++i) { const dw_offset_t die_offset = die_offsets[i]; - ResolveFunction (die_offset, dwarf_cu, include_inlines, sc_list); + ResolveFunction (die_offset, include_inlines, sc_list); } } } bool -SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, - const DWARFCompileUnit *dwarf_cu, - uint32_t name_type_mask, - const char *partial_name, - const char *base_name_start, - const char *base_name_end) -{ - // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes: - if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase) - { - const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (dwarf_cu, die); - - if (decl_ctx_die == nullptr) - return false; - - const dw_tag_t decl_ctx_tag = decl_ctx_die->Tag(); - - bool is_cxx_method = (decl_ctx_tag == DW_TAG_structure_type) || (decl_ctx_tag == DW_TAG_class_type); - - if (name_type_mask == eFunctionNameTypeMethod) - { - if (is_cxx_method == false) - return false; - } - - if (name_type_mask == eFunctionNameTypeBase) - { - if (is_cxx_method == true) - return false; - } - } - - // Now we need to check whether the name we got back for this type matches the extra specifications - // that were in the name we're looking up: - if (base_name_start != partial_name || *base_name_end != '\0') - { - // First see if the stuff to the left matches the full name. To do that let's see if - // we can pull out the mips linkage name attribute: - - Mangled best_name; - DWARFDebugInfoEntry::Attributes attributes; - DWARFFormValue form_value; - die->GetAttributes(this, dwarf_cu, DWARFFormValue::FixedFormSizes(), attributes); - uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name); - if (idx == UINT32_MAX) - idx = attributes.FindAttributeIndex(DW_AT_linkage_name); - if (idx != UINT32_MAX) - { - if (attributes.ExtractFormValueAtIndex(this, idx, form_value)) - { - const char *mangled_name = form_value.AsCString(this); - if (mangled_name) - best_name.SetValue (ConstString(mangled_name), true); - } - } - - if (!best_name) - { - idx = attributes.FindAttributeIndex(DW_AT_name); - if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value)) - { - const char *name = form_value.AsCString(this); - best_name.SetValue (ConstString(name), false); - } - } - - const LanguageType cu_language = const_cast<DWARFCompileUnit *>(dwarf_cu)->GetLanguageType(); - if (best_name.GetDemangledName(cu_language)) - { - const char *demangled = best_name.GetDemangledName(cu_language).GetCString(); - if (demangled) - { - std::string name_no_parens(partial_name, base_name_end - partial_name); - const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str()); - if (partial_in_demangled == NULL) - return false; - else - { - // Sort out the case where our name is something like "Process::Destroy" and the match is - // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on - // namespace boundaries... - - if (partial_name[0] == ':' && partial_name[1] == ':') - { - // The partial name was already on a namespace boundary so all matches are good. - return true; - } - else if (partial_in_demangled == demangled) - { - // They both start the same, so this is an good match. - return true; - } - else - { - if (partial_in_demangled - demangled == 1) - { - // Only one character difference, can't be a namespace boundary... - return false; - } - else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':') - { - // We are on a namespace boundary, so this is also good. - return true; - } - else - return false; - } - } - } - } - } - - return true; -} - -bool SymbolFileDWARF::DIEInDeclContext (const CompilerDeclContext *decl_ctx, - DWARFCompileUnit *cu, - const DWARFDebugInfoEntry *die) + const DWARFDIE &die) { // If we have no parent decl context to match this DIE matches, and if the parent // decl context isn't valid, we aren't trying to look for any particular decl @@ -2636,13 +2417,13 @@ SymbolFileDWARF::DIEInDeclContext (const CompilerDeclContext *decl_ctx, if (decl_ctx == nullptr || !decl_ctx->IsValid()) return true; - if (cu && die) + if (die) { - TypeSystem *type_system = GetTypeSystemForLanguage(cu->GetLanguageType()); + TypeSystem *type_system = die.GetTypeSystem(); if (type_system) { - CompilerDeclContext actual_decl_ctx = type_system->GetDeclContextContainingUIDFromDWARF (this, cu, die); + CompilerDeclContext actual_decl_ctx = type_system->GetDeclContextContainingUIDFromDWARF (die); if (actual_decl_ctx) return actual_decl_ctx == *decl_ctx; } @@ -2698,7 +2479,6 @@ SymbolFileDWARF::FindFunctions (const ConstString &name, if (info == NULL) return 0; - DWARFCompileUnit *dwarf_cu = NULL; std::set<const DWARFDebugInfoEntry *> resolved_dies; if (m_using_apple_tables) { @@ -2718,16 +2498,16 @@ SymbolFileDWARF::FindFunctions (const ConstString &name, for (uint32_t i = 0; i < num_matches; i++) { const dw_offset_t die_offset = die_offsets[i]; - const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); + DWARFDIE die = info->GetDIE (die_offset); if (die) { - if (!DIEInDeclContext(parent_decl_ctx, dwarf_cu, die)) + if (!DIEInDeclContext(parent_decl_ctx, die)) continue; // The containing decl contexts don't match - if (resolved_dies.find(die) == resolved_dies.end()) + if (resolved_dies.find(die.GetDIE()) == resolved_dies.end()) { - if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) - resolved_dies.insert(die); + if (ResolveFunction (die, include_inlines, sc_list)) + resolved_dies.insert(die.GetDIE()); } } else @@ -2750,16 +2530,16 @@ SymbolFileDWARF::FindFunctions (const ConstString &name, for (uint32_t i = 0; i < num_matches; i++) { const dw_offset_t die_offset = die_offsets[i]; - const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); + DWARFDIE die = info->GetDIE (die_offset); if (die) { - const char *die_name = die->GetName(this, dwarf_cu); + const char *die_name = die.GetName(); if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) { - if (resolved_dies.find(die) == resolved_dies.end()) + if (resolved_dies.find(die.GetDIE()) == resolved_dies.end()) { - if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) - resolved_dies.insert(die); + if (ResolveFunction (die, include_inlines, sc_list)) + resolved_dies.insert(die.GetDIE()); } } } @@ -2784,16 +2564,15 @@ SymbolFileDWARF::FindFunctions (const ConstString &name, for (uint32_t i = 0; i < num_matches; i++) { const dw_offset_t die_offset = die_offsets[i]; - const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); + DWARFDIE die = info->GetDIE (die_offset); if (die) { - if (!DIEInDeclContext(parent_decl_ctx, dwarf_cu, die)) + if (!DIEInDeclContext(parent_decl_ctx, die)) continue; // The containing decl contexts don't match // If we get to here, the die is good, and we should add it: - if (resolved_dies.find(die) == resolved_dies.end()) - if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) + if (resolved_dies.find(die.GetDIE()) == resolved_dies.end() && ResolveFunction (die, include_inlines, sc_list)) { bool keep_die = true; if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod)) @@ -2840,7 +2619,7 @@ SymbolFileDWARF::FindFunctions (const ConstString &name, } } if (keep_die) - resolved_dies.insert(die); + resolved_dies.insert(die.GetDIE()); } } else @@ -2903,24 +2682,22 @@ SymbolFileDWARF::FindFunctions (const ConstString &name, } } DIEArray die_offsets; - DWARFCompileUnit *dwarf_cu = NULL; - if (name_type_mask & eFunctionNameTypeBase) { uint32_t num_base = m_function_basename_index.Find(name, die_offsets); for (uint32_t i = 0; i < num_base; i++) { - const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); + DWARFDIE die = info->GetDIE (die_offsets[i]); if (die) { - if (!DIEInDeclContext(parent_decl_ctx, dwarf_cu, die)) + if (!DIEInDeclContext(parent_decl_ctx, die)) continue; // The containing decl contexts don't match // If we get to here, the die is good, and we should add it: - if (resolved_dies.find(die) == resolved_dies.end()) + if (resolved_dies.find(die.GetDIE()) == resolved_dies.end()) { - if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) - resolved_dies.insert(die); + if (ResolveFunction (die, include_inlines, sc_list)) + resolved_dies.insert(die.GetDIE()); } } } @@ -2936,14 +2713,14 @@ SymbolFileDWARF::FindFunctions (const ConstString &name, { for (uint32_t i = 0; i < num_base; i++) { - const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); + DWARFDIE die = info->GetDIE (die_offsets[i]); if (die) { // If we get to here, the die is good, and we should add it: - if (resolved_dies.find(die) == resolved_dies.end()) + if (resolved_dies.find(die.GetDIE()) == resolved_dies.end()) { - if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) - resolved_dies.insert(die); + if (ResolveFunction (die, include_inlines, sc_list)) + resolved_dies.insert(die.GetDIE()); } } } @@ -3080,20 +2857,18 @@ SymbolFileDWARF::FindTypes (const SymbolContext& sc, if (num_die_matches) { const uint32_t initial_types_size = types.GetSize(); - DWARFCompileUnit* dwarf_cu = NULL; - const DWARFDebugInfoEntry* die = NULL; DWARFDebugInfo* debug_info = DebugInfo(); for (size_t i=0; i<num_die_matches; ++i) { const dw_offset_t die_offset = die_offsets[i]; - die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); + DWARFDIE die = debug_info->GetDIE (die_offset); if (die) { - if (!DIEInDeclContext(parent_decl_ctx, dwarf_cu, die)) + if (!DIEInDeclContext(parent_decl_ctx, die)) continue; // The containing decl contexts don't match - Type *matching_type = ResolveType (dwarf_cu, die); + Type *matching_type = ResolveType (die); if (matching_type) { // We found a type pointer, now find the shared pointer form our type list @@ -3183,8 +2958,6 @@ SymbolFileDWARF::FindNamespace (const SymbolContext& sc, m_namespace_index.Find (name, die_offsets); } - DWARFCompileUnit* dwarf_cu = NULL; - const DWARFDebugInfoEntry* die = NULL; const size_t num_matches = die_offsets.size(); if (num_matches) { @@ -3192,18 +2965,18 @@ SymbolFileDWARF::FindNamespace (const SymbolContext& sc, for (size_t i=0; i<num_matches; ++i) { const dw_offset_t die_offset = die_offsets[i]; - die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); - + DWARFDIE die = debug_info->GetDIE (die_offset); + if (die) { - if (!DIEInDeclContext(parent_decl_ctx, dwarf_cu, die)) + if (!DIEInDeclContext (parent_decl_ctx, die)) continue; // The containing decl contexts don't match - TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType()); + TypeSystem *type_system = die.GetTypeSystem(); if (type_system) { - namespace_decl_ctx = type_system->GetDeclContextForUIDFromDWARF(this, dwarf_cu, die); + namespace_decl_ctx = type_system->GetDeclContextForUIDFromDWARF (die); if (namespace_decl_ctx) break; } @@ -3263,19 +3036,18 @@ SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_ma TypeSP -SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die) +SymbolFileDWARF::GetTypeForDIE (const DWARFDIE &die) { TypeSP type_sp; - if (die != NULL) + if (die) { - assert(dwarf_cu != NULL); - Type *type_ptr = m_die_to_type.lookup (die); + Type *type_ptr = m_die_to_type.lookup (die.GetDIE()); if (type_ptr == NULL) { - CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu); + CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(die.GetCU()); assert (lldb_cu); SymbolContext sc(lldb_cu); - type_sp = ParseType(sc, dwarf_cu, die, NULL); + type_sp = ParseType(sc, die, NULL); } else if (type_ptr != DIE_IS_BEING_PARSED) { @@ -3288,21 +3060,21 @@ SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfo } -const DWARFDebugInfoEntry * -SymbolFileDWARF::GetDeclContextDIEContainingDIE (const DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) +DWARFDIE +SymbolFileDWARF::GetDeclContextDIEContainingDIE (const DWARFDIE &orig_die) { - if (cu && die) + if (orig_die) { - const DWARFDebugInfoEntry * const decl_die = die; + DWARFDIE die = orig_die; - while (die != NULL) + while (die) { // If this is the original DIE that we are searching for a declaration // for, then don't look in the cache as we don't want our own decl // context to be our decl context... - if (decl_die != die) + if (orig_die != die) { - switch (die->Tag()) + switch (die.Tag()) { case DW_TAG_compile_unit: case DW_TAG_namespace: @@ -3315,31 +3087,27 @@ SymbolFileDWARF::GetDeclContextDIEContainingDIE (const DWARFCompileUnit *cu, con break; } } - - dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); - if (die_offset != DW_INVALID_OFFSET) + + DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification); + if (spec_die) { - DWARFCompileUnit *spec_cu = const_cast<DWARFCompileUnit *>(cu); - const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); - const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); - if (spec_die_decl_ctx_die) - return spec_die_decl_ctx_die; + DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(spec_die); + if (decl_ctx_die) + return decl_ctx_die; } - - die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); - if (die_offset != DW_INVALID_OFFSET) + + DWARFDIE abs_die = die.GetReferencedDIE(DW_AT_abstract_origin); + if (abs_die) { - DWARFCompileUnit *abs_cu = const_cast<DWARFCompileUnit *>(cu); - const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); - const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); - if (abs_die_decl_ctx_die) - return abs_die_decl_ctx_die; + DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(abs_die); + if (decl_ctx_die) + return decl_ctx_die; } - - die = die->GetParent(); + + die = die.GetParent(); } } - return NULL; + return DWARFDIE(); } @@ -3397,7 +3165,7 @@ SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) // This function can be used when a DIE is found that is a forward declaration // DIE and we want to try and find a type that has the complete definition. TypeSP -SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, +SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDIE &die, const ConstString &type_name, bool must_be_implementation) { @@ -3427,15 +3195,13 @@ SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry const size_t num_matches = die_offsets.size(); - DWARFCompileUnit* type_cu = NULL; - const DWARFDebugInfoEntry* type_die = NULL; if (num_matches) { DWARFDebugInfo* debug_info = DebugInfo(); for (size_t i=0; i<num_matches; ++i) { const dw_offset_t die_offset = die_offsets[i]; - type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); + DWARFDIE type_die = debug_info->GetDIE (die_offset); if (type_die) { @@ -3444,7 +3210,7 @@ SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry // Don't try and resolve the DIE we are looking for with the DIE itself! if (type_die != die) { - switch (type_die->Tag()) + switch (type_die.Tag()) { case DW_TAG_class_type: case DW_TAG_structure_type: @@ -3457,22 +3223,22 @@ SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry if (try_resolving_type) { - if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type()) - try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0); + if (must_be_implementation && type_die.Supports_DW_AT_APPLE_objc_complete_type()) + try_resolving_type = type_die.GetAttributeValueAsUnsigned (DW_AT_APPLE_objc_complete_type, 0); if (try_resolving_type) { - Type *resolved_type = ResolveType (type_cu, type_die, false); + Type *resolved_type = ResolveType (type_die, false); if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) { DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n", - MakeUserID(die->GetOffset()), + die.GetID(), m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"), - MakeUserID(type_die->GetOffset()), - MakeUserID(type_cu->GetOffset())); + type_die.GetID(), + type_cu->GetID()); if (die) - m_die_to_type[die] = resolved_type; + m_die_to_type[die.GetDIE()] = resolved_type; type_sp = resolved_type->shared_from_this(); break; } @@ -3507,19 +3273,12 @@ SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry // when they don't. //---------------------------------------------------------------------- bool -SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, - DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) +SymbolFileDWARF::DIEDeclContextsMatch (const DWARFDIE &die1, + const DWARFDIE &die2) { if (die1 == die2) return true; -#if defined (LLDB_CONFIGURATION_DEBUG) - // You can't and shouldn't call this function with a compile unit from - // two different SymbolFileDWARF instances. - assert (DebugInfo()->ContainsCompileUnit (cu1)); - assert (DebugInfo()->ContainsCompileUnit (cu2)); -#endif - DWARFDIECollection decl_ctx_1; DWARFDIECollection decl_ctx_2; //The declaration DIE stack is a stack of the declaration context @@ -3537,8 +3296,8 @@ SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugIn // all the way back to the compiler unit. // First lets grab the decl contexts for both DIEs - die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); - die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); + die1.GetDeclContextDIEs (decl_ctx_1); + die2.GetDeclContextDIEs (decl_ctx_2); // Make sure the context arrays have the same size, otherwise // we are done const size_t count1 = decl_ctx_1.Size(); @@ -3548,14 +3307,14 @@ SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugIn // Make sure the DW_TAG values match all the way back up the // compile unit. If they don't, then we are done. - const DWARFDebugInfoEntry *decl_ctx_die1; - const DWARFDebugInfoEntry *decl_ctx_die2; + DWARFDIE decl_ctx_die1; + DWARFDIE decl_ctx_die2; size_t i; for (i=0; i<count1; i++) { - decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); - decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); - if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) + decl_ctx_die1 = decl_ctx_1.GetDIEAtIndex (i); + decl_ctx_die2 = decl_ctx_2.GetDIEAtIndex (i); + if (decl_ctx_die1.Tag() != decl_ctx_die2.Tag()) return false; } #if defined LLDB_CONFIGURATION_DEBUG @@ -3563,17 +3322,17 @@ SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugIn // Make sure the top item in the decl context die array is always // DW_TAG_compile_unit. If it isn't then something went wrong in // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... - assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); + assert (decl_ctx_1.GetDIEAtIndex (count1 - 1).Tag() == DW_TAG_compile_unit); #endif // 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.GetDIEPtrAtIndex (i); - decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); - const char *name1 = decl_ctx_die1->GetName(this, cu1); - const char *name2 = decl_ctx_die2->GetName(this, cu2); + decl_ctx_die1 = decl_ctx_1.GetDIEAtIndex (i); + decl_ctx_die2 = decl_ctx_2.GetDIEAtIndex (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 the same! if (name1 == name2) @@ -3660,22 +3419,20 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext & const size_t num_matches = die_offsets.size(); - DWARFCompileUnit* type_cu = NULL; - const DWARFDebugInfoEntry* type_die = NULL; if (num_matches) { DWARFDebugInfo* debug_info = DebugInfo(); for (size_t i=0; i<num_matches; ++i) { const dw_offset_t die_offset = die_offsets[i]; - type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); + DWARFDIE type_die = debug_info->GetDIE (die_offset); if (type_die) { bool try_resolving_type = false; // Don't try and resolve the DIE we are looking for with the DIE itself! - const dw_tag_t type_tag = type_die->Tag(); + const dw_tag_t type_tag = type_die.Tag(); // Make sure the tags match if (type_tag == tag) { @@ -3708,7 +3465,7 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext & if (try_resolving_type) { DWARFDeclContext type_dwarf_decl_ctx; - type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx); + type_die.GetDWARFDeclContext (type_dwarf_decl_ctx); if (log) { @@ -3716,14 +3473,14 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext & "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)", DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), dwarf_decl_ctx.GetQualifiedName(), - type_die->GetOffset(), + type_die.GetOffset(), type_dwarf_decl_ctx.GetQualifiedName()); } // Make sure the decl contexts match all the way up if (dwarf_decl_ctx == type_dwarf_decl_ctx) { - Type *resolved_type = ResolveType (type_cu, type_die, false); + Type *resolved_type = ResolveType (type_die, false); if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) { type_sp = resolved_type->shared_from_this(); @@ -3736,12 +3493,12 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext & if (log) { std::string qualified_name; - type_die->GetQualifiedName(this, type_cu, qualified_name); + type_die.GetQualifiedName(qualified_name); GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, 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(), + type_die.GetOffset(), qualified_name.c_str()); } } @@ -3763,21 +3520,24 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext & } TypeSP -SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr) +SymbolFileDWARF::ParseType (const SymbolContext& sc, const DWARFDIE &die, bool *type_is_new_ptr) { TypeSP type_sp; - - TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType()); - if (type_system) + if (die) { - Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO); - type_sp = type_system->ParseTypeFromDWARF (sc, this, dwarf_cu, die, log, type_is_new_ptr); - if (type_sp) + TypeSystem *type_system = GetTypeSystemForLanguage(die.GetCU()->GetLanguageType()); + + if (type_system) { - TypeList* type_list = GetTypeList(); - if (type_list) - type_list->Insert(type_sp); + Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO); + type_sp = type_system->ParseTypeFromDWARF (sc, die, log, type_is_new_ptr); + if (type_sp) + { + TypeList* type_list = GetTypeList(); + if (type_list) + type_list->Insert(type_sp); + } } } @@ -3788,38 +3548,38 @@ size_t SymbolFileDWARF::ParseTypes ( const SymbolContext& sc, - DWARFCompileUnit* dwarf_cu, - const DWARFDebugInfoEntry *die, + const DWARFDIE &orig_die, bool parse_siblings, bool parse_children ) { size_t types_added = 0; - while (die != NULL) + DWARFDIE die = orig_die; + while (die) { bool type_is_new = false; - if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) + if (ParseType(sc, die, &type_is_new).get()) { if (type_is_new) ++types_added; } - if (parse_children && die->HasChildren()) + if (parse_children && die.HasChildren()) { - if (die->Tag() == DW_TAG_subprogram) + if (die.Tag() == DW_TAG_subprogram) { SymbolContext child_sc(sc); - child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get(); - types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); + child_sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get(); + types_added += ParseTypes(child_sc, die.GetFirstChild(), true, true); } else - types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); + types_added += ParseTypes(sc, die.GetFirstChild(), true, true); } if (parse_siblings) - die = die->GetSibling(); + die = die.GetSibling(); else - die = NULL; + die.Clear(); } return types_added; } @@ -3833,11 +3593,11 @@ SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); if (dwarf_cu) { - dw_offset_t function_die_offset = sc.function->GetID(); - const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); + const dw_offset_t function_die_offset = sc.function->GetID(); + DWARFDIE function_die = dwarf_cu->GetDIE (function_die_offset); if (function_die) { - ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0); + ParseFunctionBlocks(sc, &sc.function->GetBlock (false), function_die, LLDB_INVALID_ADDRESS, 0); } } @@ -3857,18 +3617,18 @@ SymbolFileDWARF::ParseTypes (const SymbolContext &sc) if (sc.function) { dw_offset_t function_die_offset = sc.function->GetID(); - const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); - if (func_die && func_die->HasChildren()) + DWARFDIE func_die = dwarf_cu->GetDIE(function_die_offset); + if (func_die && func_die.HasChildren()) { - types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); + types_added = ParseTypes(sc, func_die.GetFirstChild(), true, true); } } else { - const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); - if (dwarf_cu_die && dwarf_cu_die->HasChildren()) + DWARFDIE dwarf_cu_die = dwarf_cu->DIE(); + if (dwarf_cu_die && dwarf_cu_die.HasChildren()) { - types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); + types_added = ParseTypes(sc, dwarf_cu_die.GetFirstChild(), true, true); } } } @@ -3887,17 +3647,12 @@ SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) if (sc.function) { - DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get(); + DWARFDIE function_die = info->GetDIE(sc.function->GetID()); - if (dwarf_cu == NULL) - return 0; - - const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); - - dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS); + const dw_addr_t func_lo_pc = function_die.GetAttributeValueAsUnsigned (DW_AT_low_pc, LLDB_INVALID_ADDRESS); if (func_lo_pc != LLDB_INVALID_ADDRESS) { - const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true); + const size_t num_variables = ParseVariables(sc, function_die.GetFirstChild(), func_lo_pc, true, true); // Let all blocks know they have parse all their variables sc.function->GetBlock (false).SetDidParseVariables (true, true); @@ -3906,7 +3661,7 @@ SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) } else if (sc.comp_unit) { - DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get(); + DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()); if (dwarf_cu == NULL) return 0; @@ -3919,8 +3674,6 @@ SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) variables.reset(new VariableList()); sc.comp_unit->SetVariableList(variables); - DWARFCompileUnit* match_dwarf_cu = NULL; - const DWARFDebugInfoEntry* die = NULL; DIEArray die_offsets; if (m_using_apple_tables) { @@ -3954,10 +3707,10 @@ SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) for (size_t i=0; i<num_matches; ++i) { const dw_offset_t die_offset = die_offsets[i]; - die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); + DWARFDIE die = debug_info->GetDIE (die_offset); if (die) { - VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); + VariableSP var_sp (ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS)); if (var_sp) { variables->AddVariableIfUnique (var_sp); @@ -3985,27 +3738,27 @@ VariableSP SymbolFileDWARF::ParseVariableDIE ( const SymbolContext& sc, - DWARFCompileUnit* dwarf_cu, - const DWARFDebugInfoEntry *die, + const DWARFDIE &die, const lldb::addr_t func_low_pc ) { - VariableSP var_sp (m_die_to_variable_sp[die]); + VariableSP var_sp; + if (!die) + return var_sp; + + var_sp = m_die_to_variable_sp[die.GetDIE()]; if (var_sp) return var_sp; // Already been parsed! - const dw_tag_t tag = die->Tag(); + const dw_tag_t tag = die.Tag(); ModuleSP module = GetObjectFile()->GetModule(); if ((tag == DW_TAG_variable) || (tag == DW_TAG_constant) || (tag == DW_TAG_formal_parameter && sc.function)) { - DWARFDebugInfoEntry::Attributes attributes; - const size_t num_attributes = die->GetAttributes(this, - dwarf_cu, - DWARFFormValue::FixedFormSizes(), - attributes); + DWARFAttributes attributes; + const size_t num_attributes = die.GetAttributes(attributes); if (num_attributes > 0) { const char *name = NULL; @@ -4013,7 +3766,7 @@ SymbolFileDWARF::ParseVariableDIE Declaration decl; uint32_t i; lldb::user_id_t type_uid = LLDB_INVALID_UID; - DWARFExpression location(dwarf_cu); + DWARFExpression location(die.GetCU()); bool is_external = false; bool is_artificial = false; bool location_is_const_value_data = false; @@ -4026,16 +3779,16 @@ SymbolFileDWARF::ParseVariableDIE dw_attr_t attr = attributes.AttributeAtIndex(i); DWARFFormValue form_value; - if (attributes.ExtractFormValueAtIndex(this, i, form_value)) + if (attributes.ExtractFormValueAtIndex(i, form_value)) { switch (attr) { case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; - case DW_AT_name: name = form_value.AsCString(this); break; + case DW_AT_name: name = form_value.AsCString(); break; case DW_AT_linkage_name: - case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(this); break; + case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(); break; case DW_AT_type: type_uid = form_value.Reference(); break; case DW_AT_external: is_external = form_value.Boolean(); break; case DW_AT_const_value: @@ -4092,7 +3845,7 @@ SymbolFileDWARF::ParseVariableDIE } else { - const char *str = form_value.AsCString(this); + const char *str = form_value.AsCString(); uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart(); uint32_t string_length = strlen(str) + 1; location.CopyOpcodeData(module, debug_info_data, string_offset, string_length); @@ -4145,13 +3898,13 @@ SymbolFileDWARF::ParseVariableDIE } } - const DWARFDebugInfoEntry *parent_context_die = GetDeclContextDIEContainingDIE(dwarf_cu, die); - bool is_static_member = die->GetParent()->Tag() == DW_TAG_compile_unit && (parent_context_die->Tag() == DW_TAG_class_type || parent_context_die->Tag() == DW_TAG_structure_type); + const DWARFDIE parent_context_die = GetDeclContextDIEContainingDIE(die); + const dw_tag_t parent_tag = die.GetParent().Tag(); + bool is_static_member = parent_tag == DW_TAG_compile_unit && (parent_context_die.Tag() == DW_TAG_class_type || parent_context_die.Tag() == DW_TAG_structure_type); ValueType scope = eValueTypeInvalid; - const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); - dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; + const DWARFDIE sc_parent_die = GetParentSymbolContextDIE(die); SymbolContextScope * symbol_context_scope = NULL; if (!mangled) @@ -4162,12 +3915,12 @@ SymbolFileDWARF::ParseVariableDIE // B which in turn is contained in a namespace A, the command "frame var j" returns // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able // to generate a fully qualified name from the declaration context. - if (die->GetParent()->Tag() == DW_TAG_compile_unit && - LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType())) + if (parent_tag == DW_TAG_compile_unit && + LanguageRuntime::LanguageIsCPlusPlus(die.GetLanguage())) { DWARFDeclContext decl_ctx; - die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx); + die.GetDWARFDeclContext(decl_ctx); mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString(); } } @@ -4196,7 +3949,7 @@ SymbolFileDWARF::ParseVariableDIE { StreamString strm; location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); - GetObjectFile()->GetModule()->ReportError ("0x%8.8x: %s has an invalid location: %s", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), strm.GetString().c_str()); + GetObjectFile()->GetModule()->ReportError ("0x%8.8x: %s has an invalid location: %s", die.GetOffset(), die.GetTagAsCString(), strm.GetString().c_str()); } } @@ -4297,7 +4050,7 @@ SymbolFileDWARF::ParseVariableDIE case DW_TAG_lexical_block: if (sc.function) { - symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); + symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID()); if (symbol_context_scope == NULL) symbol_context_scope = sc.function; } @@ -4314,9 +4067,9 @@ SymbolFileDWARF::ParseVariableDIE SymbolFileTypeSP type_sp(new SymbolFileType(*this, type_uid)); if (const_value.Form() && type_sp && type_sp->GetType()) - location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), dwarf_cu->GetAddressByteSize()); + location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), die.GetCU()->GetAddressByteSize()); - var_sp.reset (new Variable (MakeUserID(die->GetOffset()), + var_sp.reset (new Variable (die.GetID(), name, mangled, type_sp, @@ -4342,57 +4095,40 @@ SymbolFileDWARF::ParseVariableDIE // was missing vital information to be able to be displayed in the debugger // (missing location due to optimization, etc)) so we don't re-parse // this DIE over and over later... - m_die_to_variable_sp[die] = var_sp; + m_die_to_variable_sp[die.GetDIE()] = var_sp; } return var_sp; } -const DWARFDebugInfoEntry * +DWARFDIE SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, - dw_offset_t spec_block_die_offset, - DWARFCompileUnit **result_die_cu_handle) + dw_offset_t spec_block_die_offset) { // Give the concrete function die specified by "func_die_offset", find the // concrete block whose DW_AT_specification or DW_AT_abstract_origin points // to "spec_block_die_offset" - DWARFDebugInfo* info = DebugInfo(); - - const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); - if (die) - { - assert (*result_die_cu_handle); - return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); - } - return NULL; + return FindBlockContainingSpecification (DebugInfo()->GetDIE (func_die_offset), spec_block_die_offset); } -const DWARFDebugInfoEntry * -SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, - const DWARFDebugInfoEntry *die, - dw_offset_t spec_block_die_offset, - DWARFCompileUnit **result_die_cu_handle) +DWARFDIE +SymbolFileDWARF::FindBlockContainingSpecification(const DWARFDIE &die, + dw_offset_t spec_block_die_offset) { if (die) { - switch (die->Tag()) + switch (die.Tag()) { case DW_TAG_subprogram: case DW_TAG_inlined_subroutine: case DW_TAG_lexical_block: { - if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) - { - *result_die_cu_handle = dwarf_cu; + if (die.GetAttributeValueAsReference (DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) return die; - } - if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) - { - *result_die_cu_handle = dwarf_cu; + if (die.GetAttributeValueAsReference (DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) return die; - } } break; } @@ -4400,49 +4136,42 @@ SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, // Give the concrete function die specified by "func_die_offset", find the // concrete block whose DW_AT_specification or DW_AT_abstract_origin points // to "spec_block_die_offset" - for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) + for (DWARFDIE child_die = die.GetFirstChild(); child_die; child_die = child_die.GetSibling()) { - const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, - child_die, - spec_block_die_offset, - result_die_cu_handle); + DWARFDIE result_die = FindBlockContainingSpecification (child_die, spec_block_die_offset); if (result_die) return result_die; } } - *result_die_cu_handle = NULL; - return NULL; + return DWARFDIE(); } size_t -SymbolFileDWARF::ParseVariables -( - const SymbolContext& sc, - DWARFCompileUnit* dwarf_cu, - const lldb::addr_t func_low_pc, - const DWARFDebugInfoEntry *orig_die, - bool parse_siblings, - bool parse_children, - VariableList* cc_variable_list -) +SymbolFileDWARF::ParseVariables (const SymbolContext& sc, + const DWARFDIE &orig_die, + const lldb::addr_t func_low_pc, + bool parse_siblings, + bool parse_children, + VariableList* cc_variable_list) { - if (orig_die == NULL) + if (!orig_die) return 0; VariableListSP variable_list_sp; size_t vars_added = 0; - const DWARFDebugInfoEntry *die = orig_die; - while (die != NULL) + DWARFDIE die = orig_die; + while (die) { - dw_tag_t tag = die->Tag(); + dw_tag_t tag = die.Tag(); // Check to see if we have already parsed this variable or constant? - if (m_die_to_variable_sp[die]) + VariableSP var_sp = m_die_to_variable_sp[die.GetDIE()]; + if (var_sp) { if (cc_variable_list) - cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); + cc_variable_list->AddVariableIfUnique (var_sp); } else { @@ -4453,8 +4182,8 @@ SymbolFileDWARF::ParseVariables { if (variable_list_sp.get() == NULL) { - const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); - dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; + DWARFDIE sc_parent_die = GetParentSymbolContextDIE(orig_die); + dw_tag_t parent_tag = sc_parent_die.Tag(); switch (parent_tag) { case DW_TAG_compile_unit: @@ -4470,10 +4199,10 @@ SymbolFileDWARF::ParseVariables else { GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8" PRIx64 " %s with no valid compile unit in symbol context for 0x%8.8" PRIx64 " %s.\n", - MakeUserID(sc_parent_die->GetOffset()), - DW_TAG_value_to_name (parent_tag), - MakeUserID(orig_die->GetOffset()), - DW_TAG_value_to_name (orig_die->Tag())); + sc_parent_die.GetID(), + sc_parent_die.GetTagAsCString(), + orig_die.GetID(), + orig_die.GetTagAsCString()); } break; @@ -4484,19 +4213,17 @@ SymbolFileDWARF::ParseVariables { // Check to see if we already have parsed the variables for the given scope - Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); + Block *block = sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID()); if (block == NULL) { // This must be a specification or abstract origin with // a concrete block counterpart in the current function. We need // to find the concrete block so we can correctly add the // variable to it - DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; - const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), - sc_parent_die->GetOffset(), - &concrete_block_die_cu); + const DWARFDIE concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), + sc_parent_die.GetOffset()); if (concrete_block_die) - block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset())); + block = sc.function->GetBlock(true).FindBlockByID(concrete_block_die.GetID()); } if (block != NULL) @@ -4514,15 +4241,15 @@ SymbolFileDWARF::ParseVariables default: GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8" PRIx64 " %s.\n", - MakeUserID(orig_die->GetOffset()), - DW_TAG_value_to_name (orig_die->Tag())); + orig_die.GetID(), + orig_die.GetTagAsCString()); break; } } if (variable_list_sp) { - VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); + VariableSP var_sp (ParseVariableDIE(sc, die, func_low_pc)); if (var_sp) { variable_list_sp->AddVariableIfUnique (var_sp); @@ -4536,15 +4263,15 @@ SymbolFileDWARF::ParseVariables bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); - if (!skip_children && parse_children && die->HasChildren()) + if (!skip_children && parse_children && die.HasChildren()) { - vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); + vars_added += ParseVariables(sc, die.GetFirstChild(), func_low_pc, true, true, cc_variable_list); } if (parse_siblings) - die = die->GetSibling(); + die = die.GetSibling(); else - die = NULL; + die.Clear(); } return vars_added; } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h index 154637b6a9f..d89d727381e 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -148,16 +148,9 @@ public: CompleteType (lldb_private::CompilerType& clang_type) override; lldb_private::Type * - ResolveType (DWARFCompileUnit* dwarf_cu, - const DWARFDebugInfoEntry* type_die, + ResolveType (const DWARFDIE &die, bool assert_not_being_parsed = true); - lldb_private::Type * - GetCachedTypeForDIE (const DWARFDebugInfoEntry* type_die) const; - - void - ClearDIEBeingParsed (const DWARFDebugInfoEntry* type_die); - lldb_private::CompilerDeclContext GetDeclContextForUID (lldb::user_id_t uid) override; @@ -281,9 +274,8 @@ public: static bool SupportedVersion(uint16_t version); - const DWARFDebugInfoEntry * - GetDeclContextDIEContainingDIE (const DWARFCompileUnit *cu, - const DWARFDebugInfoEntry *die); + DWARFDIE + GetDeclContextDIEContainingDIE (const DWARFDIE &die); lldb_private::Flags& GetFlags () @@ -317,8 +309,8 @@ public: bool Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu); - static const DWARFDebugInfoEntry * - GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die); + static DWARFDIE + GetParentSymbolContextDIE(const DWARFDIE &die); protected: @@ -348,8 +340,7 @@ protected: bool DIEInDeclContext (const lldb_private::CompilerDeclContext *parent_decl_ctx, - DWARFCompileUnit *cu, - const DWARFDebugInfoEntry *die); + const DWARFDIE &die); DISALLOW_COPY_AND_ASSIGN (SymbolFileDWARF); @@ -364,81 +355,62 @@ protected: GetNextUnparsedDWARFCompileUnit (DWARFCompileUnit* prev_cu); bool - GetFunction (DWARFCompileUnit* dwarf_cu, - const DWARFDebugInfoEntry* func_die, + GetFunction (const DWARFDIE &die, lldb_private::SymbolContext& sc); lldb_private::Function * ParseCompileUnitFunction (const lldb_private::SymbolContext& sc, - DWARFCompileUnit* dwarf_cu, - const DWARFDebugInfoEntry *die); + const DWARFDIE &die); size_t ParseFunctionBlocks (const lldb_private::SymbolContext& sc, lldb_private::Block *parent_block, - DWARFCompileUnit* dwarf_cu, - const DWARFDebugInfoEntry *die, + const DWARFDIE &die, lldb::addr_t subprogram_low_pc, uint32_t depth); size_t ParseTypes (const lldb_private::SymbolContext& sc, - DWARFCompileUnit* dwarf_cu, - const DWARFDebugInfoEntry *die, + const DWARFDIE &die, bool parse_siblings, bool parse_children); lldb::TypeSP ParseType (const lldb_private::SymbolContext& sc, - DWARFCompileUnit* dwarf_cu, - const DWARFDebugInfoEntry *die, + const DWARFDIE &die, bool *type_is_new); lldb_private::Type * - ResolveTypeUID (DWARFCompileUnit* dwarf_cu, - const DWARFDebugInfoEntry* die, + ResolveTypeUID (const DWARFDIE &die, bool assert_not_being_parsed); lldb::VariableSP ParseVariableDIE(const lldb_private::SymbolContext& sc, - DWARFCompileUnit* dwarf_cu, - const DWARFDebugInfoEntry *die, + const DWARFDIE &die, const lldb::addr_t func_low_pc); size_t - ParseVariables(const lldb_private::SymbolContext& sc, - DWARFCompileUnit* dwarf_cu, - const lldb::addr_t func_low_pc, - const DWARFDebugInfoEntry *die, - bool parse_siblings, - bool parse_children, - lldb_private::VariableList* cc_variable_list = NULL); + ParseVariables (const lldb_private::SymbolContext& sc, + const DWARFDIE &orig_die, + const lldb::addr_t func_low_pc, + bool parse_siblings, + bool parse_children, + lldb_private::VariableList* cc_variable_list = NULL); bool - ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu, - const DWARFDebugInfoEntry *parent_die); + ClassOrStructIsVirtual (const DWARFDIE &die); // Given a die_offset, figure out the symbol context representing that die. bool ResolveFunction (dw_offset_t offset, - DWARFCompileUnit *&dwarf_cu, bool include_inlines, lldb_private::SymbolContextList& sc_list); bool - ResolveFunction (DWARFCompileUnit *cu, - const DWARFDebugInfoEntry *die, + ResolveFunction (const DWARFDIE &die, bool include_inlines, lldb_private::SymbolContextList& sc_list); - bool - FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, - const DWARFCompileUnit *dwarf_cu, - uint32_t name_type_mask, - const char *partial_name, - const char *base_name_start, - const char *base_name_end); - void FindFunctions(const lldb_private::ConstString &name, const NameToDIE &name_to_die, @@ -461,7 +433,7 @@ protected: FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &die_decl_ctx); lldb::TypeSP - FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, + FindCompleteObjCDefinitionTypeForDIE (const DWARFDIE &die, const lldb_private::ConstString &type_name, bool must_be_implementation); @@ -478,8 +450,7 @@ protected: lldb_private::SymbolContextList& sc_list); lldb::TypeSP - GetTypeForDIE (DWARFCompileUnit *cu, - const DWARFDebugInfoEntry* die); + GetTypeForDIE (const DWARFDIE &die); uint32_t FindTypes (std::vector<dw_offset_t> die_offsets, @@ -501,16 +472,13 @@ protected: SymbolFileDWARFDebugMap * GetDebugMapSymfile (); - const DWARFDebugInfoEntry * + DWARFDIE FindBlockContainingSpecification (dw_offset_t func_die_offset, - dw_offset_t spec_block_die_offset, - DWARFCompileUnit **dwarf_cu_handle); - - const DWARFDebugInfoEntry * - FindBlockContainingSpecification (DWARFCompileUnit* dwarf_cu, - const DWARFDebugInfoEntry *die, - dw_offset_t spec_block_die_offset, - DWARFCompileUnit **dwarf_cu_handle); + dw_offset_t spec_block_die_offset); + + DWARFDIE + FindBlockContainingSpecification (const DWARFDIE &die, + dw_offset_t spec_block_die_offset); UniqueDWARFASTTypeMap & GetUniqueDWARFASTTypeMap (); @@ -525,12 +493,11 @@ protected: } bool - DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, - DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2); + DIEDeclContextsMatch (const DWARFDIE &die1, + const DWARFDIE &die2); bool - ClassContainsSelector (DWARFCompileUnit *dwarf_cu, - const DWARFDebugInfoEntry *class_die, + ClassContainsSelector (const DWARFDIE &class_die, const lldb_private::ConstString &selector); bool @@ -546,8 +513,7 @@ protected: typedef std::map<uint64_t, ClangModuleInfo> ExternalTypeModuleMap; void - GetTypes (DWARFCompileUnit* dwarf_cu, - const DWARFDebugInfoEntry *die, + GetTypes (const DWARFDIE &die, dw_offset_t min_die_offset, dw_offset_t max_die_offset, uint32_t type_mask, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp index dc0c42e22a0..0f3e22e22a6 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -1225,7 +1225,7 @@ SymbolFileDWARFDebugMap::Supports_DW_AT_APPLE_objc_complete_type (SymbolFileDWAR } TypeSP -SymbolFileDWARFDebugMap::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, +SymbolFileDWARFDebugMap::FindCompleteObjCDefinitionTypeForDIE (const DWARFDIE &die, const ConstString &type_name, bool must_be_implementation) { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h index fb4d1f88264..3e6245b61d7 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h @@ -266,7 +266,7 @@ protected: Supports_DW_AT_APPLE_objc_complete_type (SymbolFileDWARF *skip_dwarf_oso); lldb::TypeSP - FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, + FindCompleteObjCDefinitionTypeForDIE (const DWARFDIE &die, const lldb_private::ConstString &type_name, bool must_be_implementation); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp b/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp index 94044c0feb3..ba16ca1e3d9 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp @@ -18,55 +18,50 @@ #include "DWARFDebugInfoEntry.h" bool -UniqueDWARFASTTypeList::Find -( - SymbolFileDWARF *symfile, - const DWARFCompileUnit *cu, - const DWARFDebugInfoEntry *die, - const lldb_private::Declaration &decl, - const int32_t byte_size, - UniqueDWARFASTType &entry -) const +UniqueDWARFASTTypeList::Find (const DWARFDIE &die, + const lldb_private::Declaration &decl, + const int32_t byte_size, + UniqueDWARFASTType &entry) const { - collection::const_iterator pos, end = m_collection.end(); - for (pos = m_collection.begin(); pos != end; ++pos) + for (const UniqueDWARFASTType &udt : m_collection) { // Make sure the tags match - if (pos->m_die->Tag() == die->Tag()) + if (udt.m_die.Tag() == die.Tag()) { // Validate byte sizes of both types only if both are valid. - if (pos->m_byte_size < 0 || byte_size < 0 || pos->m_byte_size == byte_size) + if (udt.m_byte_size < 0 || byte_size < 0 || udt.m_byte_size == byte_size) { // Make sure the file and line match - if (pos->m_declaration == decl) + if (udt.m_declaration == decl) { // The type has the same name, and was defined on the same // file and line. Now verify all of the parent DIEs match. - const DWARFDebugInfoEntry *parent_arg_die = die->GetParent(); - const DWARFDebugInfoEntry *parend_pos_die = pos->m_die->GetParent(); + DWARFDIE parent_arg_die = die.GetParent(); + DWARFDIE parent_pos_die = udt.m_die.GetParent(); bool match = true; bool done = false; - while (!done && match && parent_arg_die && parend_pos_die) + while (!done && match && parent_arg_die && parent_pos_die) { - if (parent_arg_die->Tag() == parend_pos_die->Tag()) + const dw_tag_t parent_arg_tag = parent_arg_die.Tag(); + const dw_tag_t parent_pos_tag = parent_pos_die.Tag(); + if (parent_arg_tag == parent_pos_tag) { - const dw_tag_t tag = parent_arg_die->Tag(); - switch (tag) + switch (parent_arg_tag) { case DW_TAG_class_type: case DW_TAG_structure_type: case DW_TAG_union_type: case DW_TAG_namespace: { - const char *parent_arg_die_name = parent_arg_die->GetName(symfile, cu); + const char *parent_arg_die_name = parent_arg_die.GetName(); if (parent_arg_die_name == NULL) // Anonymous (i.e. no-name) struct { match = false; } else { - const char *parent_pos_die_name = parend_pos_die->GetName(pos->m_symfile, pos->m_cu); - if (parent_pos_die_name == NULL || strcmp (parent_arg_die_name, parent_pos_die_name)) + const char *parent_pos_die_name = parent_pos_die.GetName(); + if (parent_pos_die_name == NULL || ((parent_arg_die_name != parent_pos_die_name) && strcmp (parent_arg_die_name, parent_pos_die_name))) match = false; } } @@ -77,13 +72,13 @@ UniqueDWARFASTTypeList::Find break; } } - parent_arg_die = parent_arg_die->GetParent(); - parend_pos_die = parend_pos_die->GetParent(); + parent_arg_die = parent_arg_die.GetParent(); + parent_pos_die = parent_pos_die.GetParent(); } if (match) { - entry = *pos; + entry = udt; return true; } } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h b/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h index c85e175235c..0ead5077ae1 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h @@ -19,6 +19,7 @@ // Project includes #include "lldb/Symbol/Declaration.h" +#include "DWARFDIE.h" class DWARFCompileUnit; class DWARFDebugInfoEntry; @@ -32,23 +33,17 @@ public: //------------------------------------------------------------------ UniqueDWARFASTType () : m_type_sp (), - m_symfile (NULL), - m_cu (NULL), - m_die (NULL), + m_die (), m_declaration (), m_byte_size (-1) // Set to negative value to make sure we have a valid value { } UniqueDWARFASTType (lldb::TypeSP &type_sp, - SymbolFileDWARF *symfile, - DWARFCompileUnit *cu, - DWARFDebugInfoEntry *die, + const DWARFDIE &die, const lldb_private::Declaration &decl, int32_t byte_size) : m_type_sp (type_sp), - m_symfile (symfile), - m_cu (cu), m_die (die), m_declaration (decl), m_byte_size (byte_size) @@ -57,8 +52,6 @@ public: UniqueDWARFASTType (const UniqueDWARFASTType &rhs) : m_type_sp (rhs.m_type_sp), - m_symfile (rhs.m_symfile), - m_cu (rhs.m_cu), m_die (rhs.m_die), m_declaration (rhs.m_declaration), m_byte_size (rhs.m_byte_size) @@ -75,8 +68,6 @@ public: if (this != &rhs) { m_type_sp = rhs.m_type_sp; - m_symfile = rhs.m_symfile; - m_cu = rhs.m_cu; m_die = rhs.m_die; m_declaration = rhs.m_declaration; m_byte_size = rhs.m_byte_size; @@ -85,9 +76,7 @@ public: } lldb::TypeSP m_type_sp; - SymbolFileDWARF *m_symfile; - const DWARFCompileUnit *m_cu; - const DWARFDebugInfoEntry *m_die; + DWARFDIE m_die; lldb_private::Declaration m_declaration; int32_t m_byte_size; }; @@ -117,9 +106,7 @@ public: } bool - Find (SymbolFileDWARF *symfile, - const DWARFCompileUnit *cu, - const DWARFDebugInfoEntry *die, + Find (const DWARFDIE &die, const lldb_private::Declaration &decl, const int32_t byte_size, UniqueDWARFASTType &entry) const; @@ -149,10 +136,8 @@ public: } bool - Find (const lldb_private::ConstString &name, - SymbolFileDWARF *symfile, - const DWARFCompileUnit *cu, - const DWARFDebugInfoEntry *die, + Find (const lldb_private::ConstString &name, + const DWARFDIE &die, const lldb_private::Declaration &decl, const int32_t byte_size, UniqueDWARFASTType &entry) const @@ -161,7 +146,7 @@ public: collection::const_iterator pos = m_collection.find (unique_name_cstr); if (pos != m_collection.end()) { - return pos->second.Find (symfile, cu, die, decl, byte_size, entry); + return pos->second.Find (die, decl, byte_size, entry); } return false; } |