diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h @@ -26,9 +26,6 @@ dw_offset_t debug_ranges_offset) const; protected: - bool Extract(lldb_private::DWARFContext &context, lldb::offset_t *offset_ptr, - DWARFRangeList &range_list); - std::map m_range_map; }; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp @@ -8,67 +8,34 @@ #include "DWARFDebugRanges.h" #include "DWARFUnit.h" +#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h" using namespace lldb_private; -static dw_addr_t GetBaseAddressMarker(uint32_t addr_size) { - switch(addr_size) { - case 2: - return 0xffff; - case 4: - return 0xffffffff; - case 8: - return 0xffffffffffffffff; - } - llvm_unreachable("GetBaseAddressMarker unsupported address size."); -} - DWARFDebugRanges::DWARFDebugRanges() : m_range_map() {} void DWARFDebugRanges::Extract(DWARFContext &context) { - DWARFRangeList range_list; - lldb::offset_t offset = 0; - dw_offset_t debug_ranges_offset = offset; - while (Extract(context, &offset, range_list)) { - range_list.Sort(); - m_range_map[debug_ranges_offset] = range_list; - debug_ranges_offset = offset; - } -} - -bool DWARFDebugRanges::Extract(DWARFContext &context, - lldb::offset_t *offset_ptr, - DWARFRangeList &range_list) { - range_list.Clear(); - - lldb::offset_t range_offset = *offset_ptr; - const DWARFDataExtractor &debug_ranges_data = context.getOrLoadRangesData(); - uint32_t addr_size = debug_ranges_data.GetAddressByteSize(); - dw_addr_t base_addr = 0; - dw_addr_t base_addr_marker = GetBaseAddressMarker(addr_size); - - while ( - debug_ranges_data.ValidOffsetForDataOfSize(*offset_ptr, 2 * addr_size)) { - dw_addr_t begin = debug_ranges_data.GetMaxU64(offset_ptr, addr_size); - dw_addr_t end = debug_ranges_data.GetMaxU64(offset_ptr, addr_size); - - if (!begin && !end) { - // End of range list - break; - } - - if (begin == base_addr_marker) { - base_addr = end; - continue; + llvm::DWARFDataExtractor extractor = + context.getOrLoadRangesData().GetAsLLVM(); + llvm::DWARFDebugRangeList extracted_list; + uint64_t current_offset = 0; + auto extract_next_list = [&] { + if (auto error = extracted_list.extract(extractor, ¤t_offset)) { + consumeError(std::move(error)); + return false; } - - // Filter out empty ranges - if (begin < end) - range_list.Append(DWARFRangeList::Entry(begin + base_addr, end - begin)); + return true; + }; + + uint64_t previous_offset = current_offset; + while (extractor.isValidOffset(current_offset) && extract_next_list()) { + DWARFRangeList &lldb_range_list = m_range_map[previous_offset]; + for (auto &range : extracted_list.getEntries()) + lldb_range_list.Append(range.StartAddress, + range.EndAddress - range.StartAddress); + lldb_range_list.Sort(); + previous_offset = current_offset; } - - // Make sure we consumed at least something - return range_offset != *offset_ptr; } DWARFRangeList