Author: grimar Date: Thu Oct 25 03:25:45 2018 New Revision: 345251 URL: http://llvm.org/viewvc/llvm-project?rev=345251&view=rev Log: Recommit r345127 "[LLDB] - Add support for DW_RLE_base_address and DW_RLE_offset_pair entries (.debug_rnglists)"
With the fix: do not forget to hanlde the DW_RLE_start_end, which seems was omited/forgotten/removed by mistake. Original commit message: The patch implements the support for DW_RLE_base_address and DW_RLE_offset_pair .debug_rnglists entries Differential revision: https://reviews.llvm.org/D53140 ---- Added : /lldb/trunk/lit/Breakpoint/Inputs/debug_rnglist_offset_pair.yaml Added : /lldb/trunk/lit/Breakpoint/debug_rnglist_offset_pair.test Modified : /lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp Modified : /lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp Modified : /lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h Modified : /lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Modified : /lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Added: lldb/trunk/lit/Breakpoint/Inputs/debug_rnglist_offset_pair.yaml - copied unchanged from r345156, lldb/trunk/lit/Breakpoint/Inputs/debug_rnglist_offset_pair.yaml lldb/trunk/lit/Breakpoint/debug_rnglist_offset_pair.test - copied unchanged from r345156, lldb/trunk/lit/Breakpoint/debug_rnglist_offset_pair.test Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp?rev=345251&r1=345250&r2=345251&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp Thu Oct 25 03:25:45 2018 @@ -456,20 +456,15 @@ bool DWARFDebugInfoEntry::GetDIENamesAnd break; case DW_AT_ranges: { - 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 { + const DWARFDebugRangesBase *debug_ranges = dwarf2Data->DebugRanges(); + if (debug_ranges) + debug_ranges->FindRanges(cu, form_value.Unsigned(), ranges); + 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: @@ -1065,10 +1060,8 @@ size_t DWARFDebugInfoEntry::GetAttribute dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET, check_specification_or_abstract_origin); if (debug_ranges_offset != DW_INVALID_OFFSET) { - if (DWARFDebugRanges *debug_ranges = dwarf2Data->DebugRanges()) - debug_ranges->FindRanges(cu->GetRangesBase(), debug_ranges_offset, - ranges); - ranges.Slide(cu->GetBaseAddress()); + if (DWARFDebugRangesBase *debug_ranges = dwarf2Data->DebugRanges()) + debug_ranges->FindRanges(cu, debug_ranges_offset, ranges); } else if (check_hi_lo_pc) { dw_addr_t lo_pc = LLDB_INVALID_ADDRESS; dw_addr_t hi_pc = LLDB_INVALID_ADDRESS; @@ -1723,12 +1716,9 @@ bool DWARFDebugInfoEntry::LookupAddress( dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET); if (debug_ranges_offset != DW_INVALID_OFFSET) { DWARFRangeList 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()); + DWARFDebugRangesBase *debug_ranges = dwarf2Data->DebugRanges(); + debug_ranges->FindRanges(cu, debug_ranges_offset, ranges); + if (ranges.FindEntryThatContains(address)) { found_address = true; // puts("***MATCH***"); Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp?rev=345251&r1=345250&r2=345251&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp Thu Oct 25 03:25:45 2018 @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "DWARFDebugRanges.h" +#include "DWARFUnit.h" #include "SymbolFileDWARF.h" #include "lldb/Utility/Stream.h" #include <assert.h> @@ -29,8 +30,6 @@ static dw_addr_t GetBaseAddressMarker(ui DWARFDebugRanges::DWARFDebugRanges() : m_range_map() {} -DWARFDebugRanges::~DWARFDebugRanges() {} - void DWARFDebugRanges::Extract(SymbolFileDWARF *dwarf2Data) { DWARFRangeList range_list; lldb::offset_t offset = 0; @@ -112,23 +111,27 @@ void DWARFDebugRanges::Dump(Stream &s, } } -bool DWARFDebugRanges::FindRanges(dw_addr_t debug_ranges_base, +bool DWARFDebugRanges::FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset, DWARFRangeList &range_list) const { - dw_addr_t debug_ranges_address = debug_ranges_base + debug_ranges_offset; + dw_addr_t debug_ranges_address = cu->GetRangesBase() + 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, - DWARFRangeList &rangeList) { - rangeList.Clear(); +bool DWARFDebugRngLists::ExtractRangeList( + const DWARFDataExtractor &data, uint8_t addrSize, + lldb::offset_t *offset_ptr, std::vector<RngListEntry> &rangeList) { + rangeList.clear(); bool error = false; while (!error) { @@ -139,14 +142,27 @@ bool DWARFDebugRngLists::ExtractRangeLis case DW_RLE_start_length: { dw_addr_t begin = data.GetMaxU64(offset_ptr, addrSize); dw_addr_t len = data.GetULEB128(offset_ptr); - rangeList.Append(DWARFRangeList::Entry(begin, len)); + rangeList.push_back({DW_RLE_start_length, 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.Append(DWARFRangeList::Entry(begin, end - begin)); + rangeList.push_back({DW_RLE_start_end, begin, end}); + 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}); break; } @@ -162,6 +178,38 @@ bool DWARFDebugRngLists::ExtractRangeLis 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_start_end: + range_list.Append(DWARFRangeList::Entry(E.value0, E.value1 - 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; @@ -191,9 +239,8 @@ void DWARFDebugRngLists::Extract(SymbolF Offsets.push_back(data.GetPointer(&offset)); lldb::offset_t listOffset = offset; - DWARFRangeList rangeList; + std::vector<RngListEntry> rangeList; while (offset < end && ExtractRangeList(data, addrSize, &offset, rangeList)) { - rangeList.Sort(); m_range_map[listOffset] = rangeList; listOffset = offset; } Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h?rev=345251&r1=345250&r2=345251&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h Thu Oct 25 03:25:45 2018 @@ -15,18 +15,26 @@ #include <map> -class DWARFDebugRanges { +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 { public: DWARFDebugRanges(); - virtual ~DWARFDebugRanges(); - virtual void Extract(SymbolFileDWARF *dwarf2Data); + + virtual void Extract(SymbolFileDWARF *dwarf2Data) override; + virtual bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset, + DWARFRangeList &range_list) const override; 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, @@ -39,16 +47,25 @@ protected: }; // DWARF v5 .debug_rnglists section. -class DWARFDebugRngLists : public DWARFDebugRanges { +class DWARFDebugRngLists final : public DWARFDebugRangesBase { + struct RngListEntry { + uint8_t encoding; + uint64_t value0; + uint64_t value1; + }; + 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, - DWARFRangeList &list); + std::vector<RngListEntry> &list); std::vector<uint64_t> Offsets; + std::map<dw_offset_t, std::vector<RngListEntry>> m_range_map; }; #endif // SymbolFileDWARF_DWARFDebugRanges_h_ Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=345251&r1=345250&r2=345251&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Thu Oct 25 03:25:45 2018 @@ -769,7 +769,7 @@ SymbolFileDWARF::GetDWARFCompileUnit(lld return NULL; } -DWARFDebugRanges *SymbolFileDWARF::DebugRanges() { +DWARFDebugRangesBase *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 @@ DWARFDebugRanges *SymbolFileDWARF::Debug return m_ranges.get(); } -const DWARFDebugRanges *SymbolFileDWARF::DebugRanges() const { +const DWARFDebugRangesBase *SymbolFileDWARF::DebugRanges() const { return m_ranges.get(); } @@ -3379,15 +3379,10 @@ VariableSP SymbolFileDWARF::ParseVariabl case DW_AT_start_scope: { if (form_value.Form() == DW_FORM_sec_offset) { DWARFRangeList dwarf_scope_ranges; - const DWARFDebugRanges *debug_ranges = DebugRanges(); - debug_ranges->FindRanges(die.GetCU()->GetRangesBase(), + const DWARFDebugRangesBase *debug_ranges = DebugRanges(); + debug_ranges->FindRanges(die.GetCU(), 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 Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=345251&r1=345250&r2=345251&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Thu Oct 25 03:25:45 2018 @@ -53,8 +53,7 @@ class DWARFDebugAranges; class DWARFDebugInfo; class DWARFDebugInfoEntry; class DWARFDebugLine; -class DWARFDebugRanges; -class DWARFDebugRngLists; +class DWARFDebugRangesBase; class DWARFDeclContext; class DWARFDIECollection; class DWARFFormValue; @@ -266,9 +265,9 @@ public: const DWARFDebugInfo *DebugInfo() const; - DWARFDebugRanges *DebugRanges(); + DWARFDebugRangesBase *DebugRanges(); - const DWARFDebugRanges *DebugRanges() const; + const DWARFDebugRangesBase *DebugRanges() const; const lldb_private::DWARFDataExtractor &DebugLocData(); @@ -512,7 +511,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<DWARFDebugRanges> m_ranges; + std::unique_ptr<DWARFDebugRangesBase> m_ranges; UniqueDWARFASTTypeMap m_unique_ast_type_map; DIEToTypePtr m_die_to_type; DIEToVariableSP m_die_to_variable_sp; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits