Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h @@ -20,6 +20,10 @@ class DWARFDeclContext; class SymbolFileDWARF; +namespace lldb_private { +class DWARFContext; +} + class DWARFBaseDIE { public: DWARFBaseDIE() : m_cu(nullptr), m_die(nullptr) {} @@ -52,6 +56,7 @@ // Accessors //---------------------------------------------------------------------- SymbolFileDWARF *GetDWARF() const; + lldb_private::DWARFContext &GetDWARFContext() const; DWARFUnit *GetCU() const { return m_cu; } Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp @@ -121,6 +121,10 @@ return nullptr; } +DWARFContext &DWARFBaseDIE::GetDWARFContext() const { + return m_cu->GetDWARFContext(); +} + lldb_private::TypeSystem *DWARFBaseDIE::GetTypeSystem() const { if (m_cu) return m_cu->GetTypeSystem(); Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h @@ -14,6 +14,8 @@ #include "llvm/ADT/Optional.h" #include +class DWARFDebugRangesBase; + namespace lldb_private { class DWARFContext { private: @@ -30,6 +32,8 @@ llvm::Optional m_data_debug_types; llvm::Optional m_data_gnu_debug_altlink; + llvm::Optional> m_ranges; + public: explicit DWARFContext(Module &module); @@ -46,6 +50,8 @@ const DWARFDataExtractor *getOrLoadGnuDebugAltlinkData(); const DWARFDataExtractor *getOrLoadBestDebugLocData(); + + const DWARFDebugRangesBase *getOrLoadRangeInfo(); }; } // namespace lldb_private Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "DWARFContext.h" +#include "DWARFDebugRanges.h" #include "lldb/Core/Section.h" @@ -106,3 +107,21 @@ return getOrLoadDebugLoclistData(); } + +const DWARFDebugRangesBase *DWARFContext::getOrLoadRangeInfo() { + + if (m_ranges.hasValue()) + return m_ranges->get(); + + m_ranges.emplace(); + + if (getOrLoadDebugRangesData()) + m_ranges = llvm::make_unique(); + else if (getOrLoadDebugRnglistsData()) + m_ranges = llvm::make_unique(); + else + return nullptr; + + (*m_ranges)->Extract(*this); + return m_ranges->get(); +} \ No newline at end of file Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp @@ -146,10 +146,12 @@ DWARFDIE::LookupDeepestBlock(lldb::addr_t file_addr) const { if (IsValid()) { SymbolFileDWARF *dwarf = GetDWARF(); + DWARFContext &context = GetDWARFContext(); DWARFUnit *cu = GetCU(); DWARFDebugInfoEntry *function_die = nullptr; DWARFDebugInfoEntry *block_die = nullptr; - if (m_die->LookupAddress(file_addr, dwarf, cu, &function_die, &block_die)) { + if (m_die->LookupAddress(file_addr, dwarf, context, cu, &function_die, + &block_die)) { if (block_die && block_die != function_die) { if (cu->ContainsDIEOffset(block_die->GetOffset())) return DWARFDIE(cu, block_die); Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h @@ -40,6 +40,9 @@ typedef UInt32ToDIEMMap::const_iterator UInt32ToDIEMMapConstIter; class DWARFDeclContext; +namespace lldb_private { +class DWARFContext; +} #define DIE_SIBLING_IDX_BITSIZE 31 @@ -77,7 +80,7 @@ bool Extract(const DWARFUnit *cu, lldb::offset_t *offset_ptr); bool LookupAddress(const dw_addr_t address, SymbolFileDWARF *dwarf2Data, - const DWARFUnit *cu, + lldb_private::DWARFContext &context, const DWARFUnit *cu, DWARFDebugInfoEntry **function_die, DWARFDebugInfoEntry **block_die); @@ -124,8 +127,8 @@ bool check_specification_or_abstract_origin = false) const; size_t GetAttributeAddressRanges( - SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, - DWARFRangeList &ranges, bool check_hi_lo_pc, + SymbolFileDWARF *dwarf2Data, lldb_private::DWARFContext &context, + const DWARFUnit *cu, DWARFRangeList &ranges, bool check_hi_lo_pc, bool check_specification_or_abstract_origin = false) const; const char *GetName(SymbolFileDWARF *dwarf2Data, Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp @@ -447,7 +447,8 @@ break; case DW_AT_ranges: { - const DWARFDebugRangesBase *debug_ranges = dwarf2Data->DebugRanges(); + const DWARFDebugRangesBase *debug_ranges = + dwarf_context.getOrLoadRangeInfo(); if (debug_ranges) debug_ranges->FindRanges(cu, GetRangesOffset(debug_ranges, form_value), ranges); else @@ -730,7 +731,7 @@ if (!dwarf2Data) break; lldb::offset_t ranges_offset = - GetRangesOffset(dwarf2Data->DebugRanges(), form_value); + GetRangesOffset(dwarf_context.getOrLoadRangeInfo(), form_value); dw_addr_t base_addr = cu ? cu->GetBaseAddress() : 0; const DWARFDataExtractor *debug_ranges = dwarf_context.getOrLoadDebugRangesData(); @@ -1027,14 +1028,14 @@ } size_t DWARFDebugInfoEntry::GetAttributeAddressRanges( - SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, + SymbolFileDWARF *dwarf2Data, DWARFContext &context, const DWARFUnit *cu, DWARFRangeList &ranges, bool check_hi_lo_pc, bool check_specification_or_abstract_origin) const { ranges.Clear(); DWARFFormValue form_value; if (GetAttributeValue(dwarf2Data, cu, DW_AT_ranges, form_value)) { - if (DWARFDebugRangesBase *debug_ranges = dwarf2Data->DebugRanges()) + if (const DWARFDebugRangesBase *debug_ranges = context.getOrLoadRangeInfo()) debug_ranges->FindRanges(cu, GetRangesOffset(debug_ranges, form_value), ranges); } else if (check_hi_lo_pc) { @@ -1499,6 +1500,7 @@ //---------------------------------------------------------------------- bool DWARFDebugInfoEntry::LookupAddress(const dw_addr_t address, SymbolFileDWARF *dwarf2Data, + DWARFContext &context, const DWARFUnit *cu, DWARFDebugInfoEntry **function_die, DWARFDebugInfoEntry **block_die) { @@ -1690,7 +1692,8 @@ DWARFFormValue form_value; if (GetAttributeValue(dwarf2Data, cu, DW_AT_ranges, form_value)) { DWARFRangeList ranges; - DWARFDebugRangesBase *debug_ranges = dwarf2Data->DebugRanges(); + const DWARFDebugRangesBase *debug_ranges = + context.getOrLoadRangeInfo(); debug_ranges->FindRanges( cu, GetRangesOffset(debug_ranges, form_value), ranges); @@ -1732,7 +1735,7 @@ // printf("checking children\n"); DWARFDebugInfoEntry *child = GetFirstChild(); while (child) { - if (child->LookupAddress(address, dwarf2Data, cu, function_die, + if (child->LookupAddress(address, dwarf2Data, context, cu, function_die, block_die)) return true; child = child->GetSibling(); Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h @@ -22,8 +22,7 @@ public: virtual ~DWARFDebugRangesBase(){}; - virtual void Extract(SymbolFileDWARF *dwarf2Data, - lldb_private::DWARFContext &dwarf_context) = 0; + virtual void Extract(lldb_private::DWARFContext &dwarf_context) = 0; virtual bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset, DWARFRangeList &range_list) const = 0; virtual uint64_t GetOffset(size_t Index) const = 0; @@ -33,8 +32,7 @@ public: DWARFDebugRanges(); - void Extract(SymbolFileDWARF *dwarf2Data, - lldb_private::DWARFContext &dwarf_context) override; + void Extract(lldb_private::DWARFContext &dwarf_context) override; bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset, DWARFRangeList &range_list) const override; uint64_t GetOffset(size_t Index) const override; @@ -44,8 +42,7 @@ lldb::offset_t *offset_ptr, dw_addr_t cu_base_addr); protected: - bool Extract(SymbolFileDWARF *dwarf2Data, - lldb_private::DWARFContext &dwarf_context, + bool Extract(lldb_private::DWARFContext &dwarf_context, lldb::offset_t *offset_ptr, DWARFRangeList &range_list); typedef std::map range_map; @@ -63,8 +60,7 @@ }; public: - void Extract(SymbolFileDWARF *dwarf2Data, - lldb_private::DWARFContext &dwarf_context) override; + void Extract(lldb_private::DWARFContext &dwarf_context) override; bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset, DWARFRangeList &range_list) const override; uint64_t GetOffset(size_t Index) const override; Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp @@ -29,20 +29,18 @@ DWARFDebugRanges::DWARFDebugRanges() : m_range_map() {} -void DWARFDebugRanges::Extract(SymbolFileDWARF *dwarf2Data, - lldb_private::DWARFContext &dwarf_context) { +void DWARFDebugRanges::Extract(lldb_private::DWARFContext &dwarf_context) { DWARFRangeList range_list; lldb::offset_t offset = 0; dw_offset_t debug_ranges_offset = offset; - while (Extract(dwarf2Data, dwarf_context, &offset, range_list)) { + while (Extract(dwarf_context, &offset, range_list)) { range_list.Sort(); m_range_map[debug_ranges_offset] = range_list; debug_ranges_offset = offset; } } -bool DWARFDebugRanges::Extract(SymbolFileDWARF *dwarf2Data, - DWARFContext &dwarf_context, +bool DWARFDebugRanges::Extract(DWARFContext &dwarf_context, lldb::offset_t *offset_ptr, DWARFRangeList &range_list) { range_list.Clear(); @@ -259,8 +257,7 @@ return false; } -void DWARFDebugRngLists::Extract(SymbolFileDWARF *dwarf2Data, - lldb_private::DWARFContext &dwarf_context) { +void DWARFDebugRngLists::Extract(lldb_private::DWARFContext &dwarf_context) { const DWARFDataExtractor *data = dwarf_context.getOrLoadDebugRnglistsData(); if (!data) return; Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -436,8 +436,8 @@ const dw_offset_t cu_offset = GetOffset(); if (die) { DWARFRangeList ranges; - const size_t num_ranges = - die->GetAttributeAddressRanges(dwarf, this, ranges, false); + const size_t num_ranges = die->GetAttributeAddressRanges( + dwarf, GetDWARFContext(), this, ranges, false); if (num_ranges > 0) { // This compile unit has DW_AT_ranges, assume this is correct if it is // present since clang no longer makes .debug_aranges by default and it Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -240,10 +240,6 @@ const DWARFDebugInfo *DebugInfo() const; - DWARFDebugRangesBase *DebugRanges(); - - const DWARFDebugRangesBase *DebugRanges() const; - static bool SupportedVersion(uint16_t version); DWARFDIE Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -633,27 +633,6 @@ return NULL; } -DWARFDebugRangesBase *SymbolFileDWARF::DebugRanges() { - if (m_ranges == NULL) { - static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); - Timer scoped_timer(func_cat, "%s this = %p", LLVM_PRETTY_FUNCTION, - static_cast(this)); - - if (m_context.getOrLoadDebugRangesData()) - m_ranges = llvm::make_unique(); - else if (m_context.getOrLoadDebugRnglistsData()) - m_ranges = llvm::make_unique(); - - if (m_ranges) - m_ranges->Extract(this, m_context); - } - return m_ranges.get(); -} - -const DWARFDebugRangesBase *SymbolFileDWARF::DebugRanges() const { - return m_ranges.get(); -} - lldb::CompUnitSP SymbolFileDWARF::ParseCompileUnit(DWARFUnit *dwarf_cu, uint32_t cu_idx) { CompUnitSP cu_sp; @@ -3269,7 +3248,8 @@ case DW_AT_start_scope: { if (form_value.Form() == DW_FORM_sec_offset) { DWARFRangeList dwarf_scope_ranges; - const DWARFDebugRangesBase *debug_ranges = DebugRanges(); + const DWARFDebugRangesBase *debug_ranges = + m_context.getOrLoadRangeInfo(); debug_ranges->FindRanges(die.GetCU(), form_value.Unsigned(), dwarf_scope_ranges);