mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 19:52:54 +01:00
[DWARF] DWARFDebugLine: replace Sequence::orderByLowPC with orderByHighPC
In a sorted list of non-overlapping [LowPC,HighPC) ranges, locating an address with upper_bound on HighPC is simpler than lower_bound on LowPC. llvm-svn: 358012
This commit is contained in:
parent
9bccbf9749
commit
851714ea16
@ -206,9 +206,9 @@ public:
|
||||
|
||||
void reset();
|
||||
|
||||
static bool orderByLowPC(const Sequence &LHS, const Sequence &RHS) {
|
||||
return std::tie(LHS.SectionIndex, LHS.LowPC) <
|
||||
std::tie(RHS.SectionIndex, RHS.LowPC);
|
||||
static bool orderByHighPC(const Sequence &LHS, const Sequence &RHS) {
|
||||
return std::tie(LHS.SectionIndex, LHS.HighPC) <
|
||||
std::tie(RHS.SectionIndex, RHS.HighPC);
|
||||
}
|
||||
|
||||
bool isValid() const {
|
||||
|
@ -842,7 +842,7 @@ Error DWARFDebugLine::LineTable::parse(
|
||||
|
||||
// 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.
|
||||
@ -919,31 +919,15 @@ uint32_t DWARFDebugLine::LineTable::lookupAddress(
|
||||
|
||||
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(
|
||||
@ -971,17 +955,11 @@ bool DWARFDebugLine::LineTable::lookupAddressRangeImpl(
|
||||
// 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;
|
||||
|
Loading…
Reference in New Issue
Block a user