fdeazeve created this revision. Herald added a project: All. fdeazeve requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
In an effort to unify the different dwarf parsers available in the codebase, this commit removes LLDB's custom parsing for the `.debug_ranges` DWARF section, instead calling into LLVM's parser. Subsequent work should look into unifying `llvm::DWARDebugRangeList` (whose entries are pairs of (start, end) addresses) with `lldb::DWARFRangeList` (whose entries are pairs of (start, length)). The lists themselves are also different data structures, but functionally equivalent. Depends on D150363 <https://reviews.llvm.org/D150363> Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D150366 Files: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h +++ 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<dw_offset_t, DWARFRangeList> m_range_map; }; Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp +++ 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
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits