[lld] [llvm] [Symbolizer] Support for Missing Line Numbers. (PR #82240)
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 6 17:55:48 PST 2024
================
@@ -1296,32 +1296,58 @@ 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,
+ DILineInfoSpecifier::ApproximateLineKind LineKind) const {
// Search for relocatable addresses
- uint32_t Result = lookupAddressImpl(Address);
+ std::pair<uint32_t, bool> Result = lookupAddressImpl(Address, LineKind);
- 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, LineKind);
}
-uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
- object::SectionedAddress Address) const {
+std::pair<uint32_t, bool> DWARFDebugLine::LineTable::lookupAddressImpl(
+ object::SectionedAddress Address,
+ DILineInfoSpecifier::ApproximateLineKind LineKind) 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 = UnknownRowIndex;
+ bool SecondAttempt = false;
+ if (LineKind == DILineInfoSpecifier::ApproximateLineKind::Before) {
+ for (auto SeqInst = Sequence.HighPC; SeqInst >= It->LowPC;) {
+ RowIndex = findRowInSeq(*It, Address);
+ if (Rows[RowIndex].Line)
+ break;
+ if (!SecondAttempt)
+ SecondAttempt = true;
+ Address.Address = --SeqInst;
+ }
+ } else if (LineKind == DILineInfoSpecifier::ApproximateLineKind::After) {
+ for (auto SeqInst = Sequence.HighPC; SeqInst <= It->HighPC;) {
+ RowIndex = findRowInSeq(*It, Address);
+ if (Rows[RowIndex].Line)
+ break;
+ if (!SecondAttempt)
+ SecondAttempt = true;
+ Address.Address = ++SeqInst;
+ }
----------------
dwblaikie wrote:
Perhaps these loops would be simpler if they were:
```
for (Address.Address <= It->HighPC; ++Address.Address) {
...
}
```
? maybe?
The body of the loop could be pulled into a lambda, since it's identical between the forwards and backwards directions, but it might be shorte enough (especially removing the conditional on SecondAttempt/Approximated).
https://github.com/llvm/llvm-project/pull/82240
More information about the llvm-commits
mailing list