diff options
Diffstat (limited to 'lldb/source')
5 files changed, 54 insertions, 99 deletions
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp index 3c3f271a954..66cf47cd450 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp @@ -456,15 +456,20 @@ bool DWARFDebugInfoEntry::GetDIENamesAndRanges( break; case DW_AT_ranges: { - const DWARFDebugRangesBase *debug_ranges = dwarf2Data->DebugRanges(); - if (debug_ranges) - debug_ranges->FindRanges(cu, form_value.Unsigned(), ranges); - else + const DWARFDebugRanges *debug_ranges = dwarf2Data->DebugRanges(); + if (debug_ranges) { + debug_ranges->FindRanges(cu->GetRangesBase(), form_value.Unsigned(), ranges); + // All DW_AT_ranges are relative to the base address of the compile + // unit. We add the compile unit base address to make sure all the + // addresses are properly fixed up. + ranges.Slide(cu->GetBaseAddress()); + } else { cu->GetSymbolFileDWARF()->GetObjectFile()->GetModule()->ReportError( "{0x%8.8x}: DIE has DW_AT_ranges(0x%" PRIx64 ") attribute yet DWARF has no .debug_ranges, please file a bug " "and attach the file at the start of this error message", m_offset, form_value.Unsigned()); + } } break; case DW_AT_name: @@ -1060,8 +1065,10 @@ size_t DWARFDebugInfoEntry::GetAttributeAddressRanges( dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET, check_specification_or_abstract_origin); if (debug_ranges_offset != DW_INVALID_OFFSET) { - if (DWARFDebugRangesBase *debug_ranges = dwarf2Data->DebugRanges()) - debug_ranges->FindRanges(cu, debug_ranges_offset, ranges); + if (DWARFDebugRanges *debug_ranges = dwarf2Data->DebugRanges()) + debug_ranges->FindRanges(cu->GetRangesBase(), debug_ranges_offset, + ranges); + ranges.Slide(cu->GetBaseAddress()); } else if (check_hi_lo_pc) { dw_addr_t lo_pc = LLDB_INVALID_ADDRESS; dw_addr_t hi_pc = LLDB_INVALID_ADDRESS; @@ -1716,9 +1723,12 @@ bool DWARFDebugInfoEntry::LookupAddress(const dw_addr_t address, dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET); if (debug_ranges_offset != DW_INVALID_OFFSET) { DWARFRangeList ranges; - DWARFDebugRangesBase *debug_ranges = dwarf2Data->DebugRanges(); - debug_ranges->FindRanges(cu, debug_ranges_offset, ranges); - + DWARFDebugRanges *debug_ranges = dwarf2Data->DebugRanges(); + debug_ranges->FindRanges(cu->GetRangesBase(), debug_ranges_offset, ranges); + // All DW_AT_ranges are relative to the base address of the compile + // unit. We add the compile unit base address to make sure all the + // addresses are properly fixed up. + ranges.Slide(cu->GetBaseAddress()); if (ranges.FindEntryThatContains(address)) { found_address = true; // puts("***MATCH***"); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp index 1e771471a57..da97e90c672 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// #include "DWARFDebugRanges.h" -#include "DWARFUnit.h" #include "SymbolFileDWARF.h" #include "lldb/Utility/Stream.h" #include <assert.h> @@ -30,6 +29,8 @@ static dw_addr_t GetBaseAddressMarker(uint32_t addr_size) { DWARFDebugRanges::DWARFDebugRanges() : m_range_map() {} +DWARFDebugRanges::~DWARFDebugRanges() {} + void DWARFDebugRanges::Extract(SymbolFileDWARF *dwarf2Data) { DWARFRangeList range_list; lldb::offset_t offset = 0; @@ -111,27 +112,23 @@ void DWARFDebugRanges::Dump(Stream &s, } } -bool DWARFDebugRanges::FindRanges(const DWARFUnit *cu, +bool DWARFDebugRanges::FindRanges(dw_addr_t debug_ranges_base, dw_offset_t debug_ranges_offset, DWARFRangeList &range_list) const { - dw_addr_t debug_ranges_address = cu->GetRangesBase() + debug_ranges_offset; + dw_addr_t debug_ranges_address = debug_ranges_base + debug_ranges_offset; range_map_const_iterator pos = m_range_map.find(debug_ranges_address); if (pos != m_range_map.end()) { range_list = pos->second; - - // All DW_AT_ranges are relative to the base address of the compile - // unit. We add the compile unit base address to make sure all the - // addresses are properly fixed up. - range_list.Slide(cu->GetBaseAddress()); return true; } return false; } -bool DWARFDebugRngLists::ExtractRangeList( - const DWARFDataExtractor &data, uint8_t addrSize, - lldb::offset_t *offset_ptr, std::vector<RngListEntry> &rangeList) { - rangeList.clear(); +bool DWARFDebugRngLists::ExtractRangeList(const DWARFDataExtractor &data, + uint8_t addrSize, + lldb::offset_t *offset_ptr, + DWARFRangeList &rangeList) { + rangeList.Clear(); bool error = false; while (!error) { @@ -142,27 +139,14 @@ bool DWARFDebugRngLists::ExtractRangeList( case DW_RLE_start_length: { dw_addr_t begin = data.GetMaxU64(offset_ptr, addrSize); dw_addr_t len = data.GetULEB128(offset_ptr); - rangeList.push_back({DW_RLE_start_length, begin, len}); + rangeList.Append(DWARFRangeList::Entry(begin, len)); break; } case DW_RLE_start_end: { dw_addr_t begin = data.GetMaxU64(offset_ptr, addrSize); dw_addr_t end = data.GetMaxU64(offset_ptr, addrSize); - rangeList.push_back({DW_RLE_start_end, begin, end - begin}); - break; - } - - case DW_RLE_base_address: { - dw_addr_t base = data.GetMaxU64(offset_ptr, addrSize); - rangeList.push_back({DW_RLE_base_address, base, 0}); - break; - } - - case DW_RLE_offset_pair: { - dw_addr_t begin = data.GetULEB128(offset_ptr); - dw_addr_t end = data.GetULEB128(offset_ptr); - rangeList.push_back({DW_RLE_offset_pair, begin, end}); + rangeList.Append(DWARFRangeList::Entry(begin, end - begin)); break; } @@ -178,35 +162,6 @@ bool DWARFDebugRngLists::ExtractRangeList( return false; } -bool DWARFDebugRngLists::FindRanges(const DWARFUnit *cu, - dw_offset_t debug_ranges_offset, - DWARFRangeList &range_list) const { - range_list.Clear(); - dw_addr_t debug_ranges_address = cu->GetRangesBase() + debug_ranges_offset; - auto pos = m_range_map.find(debug_ranges_address); - if (pos != m_range_map.end()) { - dw_addr_t BaseAddr = cu->GetBaseAddress(); - for (const RngListEntry &E : pos->second) { - switch (E.encoding) { - case DW_RLE_start_length: - range_list.Append(DWARFRangeList::Entry(E.value0, E.value1)); - break; - case DW_RLE_base_address: - BaseAddr = E.value0; - break; - case DW_RLE_offset_pair: - range_list.Append( - DWARFRangeList::Entry(BaseAddr + E.value0, E.value1 - E.value0)); - break; - default: - llvm_unreachable("unexpected encoding"); - } - } - return true; - } - return false; -} - void DWARFDebugRngLists::Extract(SymbolFileDWARF *dwarf2Data) { const DWARFDataExtractor &data = dwarf2Data->get_debug_rnglists_data(); lldb::offset_t offset = 0; @@ -236,8 +191,9 @@ void DWARFDebugRngLists::Extract(SymbolFileDWARF *dwarf2Data) { Offsets.push_back(data.GetPointer(&offset)); lldb::offset_t listOffset = offset; - std::vector<RngListEntry> rangeList; + DWARFRangeList rangeList; while (offset < end && ExtractRangeList(data, addrSize, &offset, rangeList)) { + rangeList.Sort(); m_range_map[listOffset] = rangeList; listOffset = offset; } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h index b346d9291a4..e239bc54add 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h @@ -15,26 +15,18 @@ #include <map> -class DWARFDebugRangesBase { -public: - virtual ~DWARFDebugRangesBase(){}; - - virtual void Extract(SymbolFileDWARF *dwarf2Data) = 0; - virtual bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset, - DWARFRangeList &range_list) const = 0; -}; - -class DWARFDebugRanges final : public DWARFDebugRangesBase { +class DWARFDebugRanges { public: DWARFDebugRanges(); - - virtual void Extract(SymbolFileDWARF *dwarf2Data) override; - virtual bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset, - DWARFRangeList &range_list) const override; + virtual ~DWARFDebugRanges(); + virtual 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_addr_t debug_ranges_base, + dw_offset_t debug_ranges_offset, + DWARFRangeList &range_list) const; protected: bool Extract(SymbolFileDWARF *dwarf2Data, lldb::offset_t *offset_ptr, @@ -47,25 +39,16 @@ protected: }; // DWARF v5 .debug_rnglists section. -class DWARFDebugRngLists final : public DWARFDebugRangesBase { - struct RngListEntry { - uint8_t encoding; - uint64_t value0; - uint64_t value1; - }; - +class DWARFDebugRngLists : public DWARFDebugRanges { public: void Extract(SymbolFileDWARF *dwarf2Data) override; - bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset, - DWARFRangeList &range_list) const override; protected: bool ExtractRangeList(const lldb_private::DWARFDataExtractor &data, uint8_t addrSize, lldb::offset_t *offset_ptr, - std::vector<RngListEntry> &list); + DWARFRangeList &list); std::vector<uint64_t> Offsets; - std::map<dw_offset_t, std::vector<RngListEntry>> m_range_map; }; #endif // SymbolFileDWARF_DWARFDebugRanges_h_ diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index 41be820a288..3a758ce126d 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -769,7 +769,7 @@ SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) { return NULL; } -DWARFDebugRangesBase *SymbolFileDWARF::DebugRanges() { +DWARFDebugRanges *SymbolFileDWARF::DebugRanges() { if (m_ranges.get() == NULL) { static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); Timer scoped_timer(func_cat, "%s this = %p", LLVM_PRETTY_FUNCTION, @@ -786,7 +786,7 @@ DWARFDebugRangesBase *SymbolFileDWARF::DebugRanges() { return m_ranges.get(); } -const DWARFDebugRangesBase *SymbolFileDWARF::DebugRanges() const { +const DWARFDebugRanges *SymbolFileDWARF::DebugRanges() const { return m_ranges.get(); } @@ -3379,10 +3379,15 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc, case DW_AT_start_scope: { if (form_value.Form() == DW_FORM_sec_offset) { DWARFRangeList dwarf_scope_ranges; - const DWARFDebugRangesBase *debug_ranges = DebugRanges(); - debug_ranges->FindRanges(die.GetCU(), + const DWARFDebugRanges *debug_ranges = DebugRanges(); + debug_ranges->FindRanges(die.GetCU()->GetRangesBase(), form_value.Unsigned(), dwarf_scope_ranges); + + // All DW_AT_start_scope are relative to the base address of the + // compile unit. We add the compile unit base address to make + // sure all the addresses are properly fixed up. + dwarf_scope_ranges.Slide(die.GetCU()->GetBaseAddress()); } else { // TODO: Handle the case when DW_AT_start_scope have form // constant. The diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h index 80a9acb2ff6..03137cf68b0 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -53,7 +53,8 @@ class DWARFDebugAranges; class DWARFDebugInfo; class DWARFDebugInfoEntry; class DWARFDebugLine; -class DWARFDebugRangesBase; +class DWARFDebugRanges; +class DWARFDebugRngLists; class DWARFDeclContext; class DWARFDIECollection; class DWARFFormValue; @@ -265,9 +266,9 @@ public: const DWARFDebugInfo *DebugInfo() const; - DWARFDebugRangesBase *DebugRanges(); + DWARFDebugRanges *DebugRanges(); - const DWARFDebugRangesBase *DebugRanges() const; + const DWARFDebugRanges *DebugRanges() const; const lldb_private::DWARFDataExtractor &DebugLocData(); @@ -511,7 +512,7 @@ protected: typedef std::shared_ptr<std::set<DIERef>> DIERefSetSP; typedef std::unordered_map<std::string, DIERefSetSP> NameToOffsetMap; NameToOffsetMap m_function_scope_qualified_name_map; - std::unique_ptr<DWARFDebugRangesBase> m_ranges; + std::unique_ptr<DWARFDebugRanges> m_ranges; UniqueDWARFASTTypeMap m_unique_ast_type_map; DIEToTypePtr m_die_to_type; DIEToVariableSP m_die_to_variable_sp; |