[Lldb-commits] [lldb] 70aad4e - [lldb][NFCI] Use llvm's libDebugInfo for DebugRanges

Felipe de Azevedo Piovezan via lldb-commits lldb-commits at lists.llvm.org
Tue May 23 08:11:41 PDT 2023


Author: Felipe de Azevedo Piovezan
Date: 2023-05-23T11:11:10-04:00
New Revision: 70aad4ec90f2df69b91a356b91c3dd16e15be3d1

URL: https://github.com/llvm/llvm-project/commit/70aad4ec90f2df69b91a356b91c3dd16e15be3d1
DIFF: https://github.com/llvm/llvm-project/commit/70aad4ec90f2df69b91a356b91c3dd16e15be3d1.diff

LOG: [lldb][NFCI] Use llvm's libDebugInfo for DebugRanges

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

Differential Revision: https://reviews.llvm.org/D150366

Added: 
    

Modified: 
    lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
    lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
index d3598de5b3d31..7c6740d77aaf8 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
@@ -8,67 +8,35 @@
 
 #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, &current_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];
+    lldb_range_list.Reserve(extracted_list.getEntries().size());
+    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

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h
index 5d5ddada6c2f9..2e06cd5daf6f3 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h
@@ -26,9 +26,6 @@ class DWARFDebugRanges {
                             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;
 };
 


        


More information about the lldb-commits mailing list