[lld] [llvm] [Symbolizer] Support for Missing Line Numbers. (PR #82240)

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 29 21:32:00 PDT 2024


================
@@ -1312,32 +1312,52 @@ uint32_t DWARFDebugLine::LineTable::findRowInSeq(
   return RowPos - Rows.begin();
 }
 
-uint32_t DWARFDebugLine::LineTable::lookupAddress(
-    object::SectionedAddress Address) const {
+std::pair<uint32_t, bool>
+DWARFDebugLine::LineTable::lookupAddress(object::SectionedAddress Address,
+                                         bool ApproximateLine) const {
 
   // Search for relocatable addresses
-  uint32_t Result = lookupAddressImpl(Address);
+  std::pair<uint32_t, bool> Result =
+      lookupAddressImpl(Address, ApproximateLine);
 
-  if (Result != UnknownRowIndex ||
+  if (Result.first != UnknownRowIndex ||
       Address.SectionIndex == object::SectionedAddress::UndefSection)
     return Result;
 
   // Search for absolute addresses
   Address.SectionIndex = object::SectionedAddress::UndefSection;
-  return lookupAddressImpl(Address);
+  return lookupAddressImpl(Address, ApproximateLine);
 }
 
-uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
-    object::SectionedAddress Address) const {
+std::pair<uint32_t, bool>
+DWARFDebugLine::LineTable::lookupAddressImpl(object::SectionedAddress Address,
+                                             bool ApproximateLine) const {
   // First, find an instruction sequence containing the given address.
   DWARFDebugLine::Sequence Sequence;
   Sequence.SectionIndex = Address.SectionIndex;
   Sequence.HighPC = Address.Address;
   SequenceIter It = llvm::upper_bound(Sequences, Sequence,
                                       DWARFDebugLine::Sequence::orderByHighPC);
   if (It == Sequences.end() || It->SectionIndex != Address.SectionIndex)
-    return UnknownRowIndex;
-  return findRowInSeq(*It, Address);
+    return {UnknownRowIndex, false};
+
+  uint32_t RowIndex = findRowInSeq(*It, Address);
+  bool IsApproximate = false;
+  if (ApproximateLine) {
+    uint32_t ApproxRowIndex = RowIndex;
+    while (ApproxRowIndex >= It->FirstRowIndex) {
+      if (ApproxRowIndex != UnknownRowIndex && Rows[ApproxRowIndex].Line)
+        break;
+      IsApproximate = true;
+      if (ApproxRowIndex != UnknownRowIndex &&
+          (Rows[ApproxRowIndex].BasicBlock | Rows[ApproxRowIndex].PrologueEnd))
----------------
dwblaikie wrote:

I don't think prologue end or basic block should be relevant here - or, if they are, it does complicate the specification of this behavior somewhat. It's simpler to specify if the behavior is "as if line zero entries didn't exist at all" - in which case the line table would walk backwards through prologue end and basic block boundaries.

The concession I would make is that we shouldn't walk across sequence boundaries - those are more complicated/more clearly bogus to walk past.

I'm not adamant we /don't/ check BB or end prologue, but I am a bit concerned/avoidant of complicating the feature too much, making it harder to explain to users what's going on.

Also, LLVM doesn't produce the BB flag in the line table, right? So this might be a bit hard to test (would need some hand-crafted assembly of a line table containing a BB flag)

https://github.com/llvm/llvm-project/pull/82240


More information about the llvm-commits mailing list