// Sort all sequences so that address lookup will work faster.
if (!Sequences.empty()) {
- llvm::sort(Sequences, Sequence::orderByLowPC);
+ llvm::sort(Sequences, Sequence::orderByHighPC);
// Note: actually, instruction address ranges of sequences should not
// overlap (in shared objects and executables). If they do, the address
// lookup would still work, though, but result would be ambiguous.
uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
object::SectionedAddress Address) const {
- if (Sequences.empty())
- return UnknownRowIndex;
// First, find an instruction sequence containing the given address.
DWARFDebugLine::Sequence Sequence;
Sequence.SectionIndex = Address.SectionIndex;
- Sequence.LowPC = Address.Address;
- SequenceIter FirstSeq = Sequences.begin();
- SequenceIter LastSeq = Sequences.end();
- SequenceIter SeqPos = std::lower_bound(
- FirstSeq, LastSeq, Sequence, DWARFDebugLine::Sequence::orderByLowPC);
- DWARFDebugLine::Sequence FoundSeq;
-
- if (SeqPos == LastSeq) {
- FoundSeq = Sequences.back();
- } else if (SeqPos->LowPC == Address.Address &&
- SeqPos->SectionIndex == Address.SectionIndex) {
- FoundSeq = *SeqPos;
- } else {
- if (SeqPos == FirstSeq)
- return UnknownRowIndex;
- FoundSeq = *(SeqPos - 1);
- }
- if (FoundSeq.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(FoundSeq, Address);
+ return findRowInSeq(*It, Address);
}
bool DWARFDebugLine::LineTable::lookupAddressRange(
// First, find an instruction sequence containing the given address.
DWARFDebugLine::Sequence Sequence;
Sequence.SectionIndex = Address.SectionIndex;
- Sequence.LowPC = Address.Address;
- SequenceIter FirstSeq = Sequences.begin();
+ Sequence.HighPC = Address.Address;
SequenceIter LastSeq = Sequences.end();
- SequenceIter SeqPos = std::lower_bound(
- FirstSeq, LastSeq, Sequence, DWARFDebugLine::Sequence::orderByLowPC);
- if (SeqPos == LastSeq || !SeqPos->containsPC(Address)) {
- if (SeqPos == FirstSeq)
- return false;
- SeqPos--;
- }
- if (!SeqPos->containsPC(Address))
+ SequenceIter SeqPos = llvm::upper_bound(
+ Sequences, Sequence, DWARFDebugLine::Sequence::orderByHighPC);
+ if (SeqPos == LastSeq || !SeqPos->containsPC(Address))
return false;
SequenceIter StartPos = SeqPos;