[Lldb-commits] [PATCH] D147606: [lldb] fix #61942, discard "empty" ranges in DWARF to better handle gcc binary

LU Hongyi via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Apr 5 05:41:26 PDT 2023


jwnhy created this revision.
jwnhy added reviewers: Michael137, DavidSpickett, JDevlieghere.
Herald added a project: All.
jwnhy requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This patch resolves an issue that lldb not be able to
match the correct range of certain address.

This issue caused by other compilers like gcc generates
"empty ranges" like [address, address) in the DIE. These
"empty ranges" cause lldb matches address with these
ranges unintentionally and causes unpredictable result.
(In #61942, a variable dispearred due to this issue)

This patch resolves this issue by discarding these "empty
ranges" during the parsing of debugging information.

Another approach in fixing this might be changing the
logic of "FindEntryThatContains" and let it try harder
if met "empty ranges".


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147606

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp


Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1314,10 +1314,11 @@
         for (size_t i = 0; i < num_ranges; ++i) {
           const DWARFRangeList::Entry &range = ranges.GetEntryRef(i);
           const addr_t range_base = range.GetRangeBase();
-          if (range_base >= subprogram_low_pc)
-            block->AddRange(Block::Range(range_base - subprogram_low_pc,
+          if (range_base >= subprogram_low_pc) {
+            if (range.IsValid())
+              block->AddRange(Block::Range(range_base - subprogram_low_pc,
                                          range.GetByteSize()));
-          else {
+          } else {
             GetObjectFile()->GetModule()->ReportError(
                 "{0:x8}: adding range [{1:x16}-{2:x16}) which has a base "
                 "that is less than the function's low PC {3:x16}. Please file "
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -1065,8 +1065,9 @@
 
   DWARFRangeList ranges;
   for (const llvm::DWARFAddressRange &llvm_range : *llvm_ranges) {
-    ranges.Append(DWARFRangeList::Entry(llvm_range.LowPC,
-                                        llvm_range.HighPC - llvm_range.LowPC));
+    if (llvm_range.HighPC - llvm_range.LowPC > 0)
+      ranges.Append(DWARFRangeList::Entry(llvm_range.LowPC,
+                                          llvm_range.HighPC - llvm_range.LowPC));
   }
   return ranges;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147606.511063.patch
Type: text/x-patch
Size: 1772 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230405/2a79122a/attachment.bin>


More information about the lldb-commits mailing list