llvm-symbolizer: Fix bug related to TUs interfering with symbolizing

With the merge of TUs and CUs into a single container, some code that
relied on the CU range having an ordered range of contiguous addresses
(for locating a CU at a given offset) broke. But the units from
debug_info (currently only CUs, but CUs and TUs in DWARFv5) are in a
contiguous sub-range of that container - searching only through that
subrange is still valid & so do that.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@341889 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie 2018-09-11 02:04:45 +00:00
parent b59662095b
commit 2da88b084c
4 changed files with 29 additions and 16 deletions

View File

@ -110,7 +110,7 @@ class DWARFUnitVector final : public SmallVector<std::unique_ptr<DWARFUnit>, 1>
std::function<std::unique_ptr<DWARFUnit>(uint32_t, DWARFSectionKind,
const DWARFSection *)>
Parser;
unsigned NumInfoUnits = 0;
int NumInfoUnits = -1;
public:
using UnitVector = SmallVectorImpl<std::unique_ptr<DWARFUnit>>;
@ -135,11 +135,13 @@ public:
DWARFSectionKind SectionKind, bool Lazy = false);
/// Returns number of all units held by this instance.
unsigned getNumUnits() { return size(); }
unsigned getNumUnits() const { return size(); }
/// Returns number of units from all .debug_info[.dwo] sections.
unsigned getNumInfoUnits() { return NumInfoUnits; }
unsigned getNumInfoUnits() const {
return NumInfoUnits == -1 ? size() : NumInfoUnits;
}
/// Returns number of units from all .debug_types[.dwo] sections.
unsigned getNumTypesUnits() { return size() - NumInfoUnits; }
unsigned getNumTypesUnits() const { return size() - NumInfoUnits; }
/// Indicate that parsing .debug_info[.dwo] is done, and remaining units
/// will be from .debug_types[.dwo].
void finishedInfoUnits() { NumInfoUnits = size(); }

View File

@ -113,12 +113,13 @@ void DWARFUnitVector::addUnitsImpl(
}
DWARFUnit *DWARFUnitVector::getUnitForOffset(uint32_t Offset) const {
auto *CU = std::upper_bound(
this->begin(), this->end(), Offset,
[](uint32_t LHS, const std::unique_ptr<DWARFUnit> &RHS) {
return LHS < RHS->getNextUnitOffset();
});
if (CU != this->end() && (*CU)->getOffset() <= Offset)
auto end = begin() + getNumInfoUnits();
auto *CU =
std::upper_bound(begin(), end, Offset,
[](uint32_t LHS, const std::unique_ptr<DWARFUnit> &RHS) {
return LHS < RHS->getNextUnitOffset();
});
if (CU != end && (*CU)->getOffset() <= Offset)
return CU->get();
return nullptr;
}
@ -130,13 +131,14 @@ DWARFUnitVector::getUnitForIndexEntry(const DWARFUnitIndex::Entry &E) {
return nullptr;
auto Offset = CUOff->Offset;
auto end = begin() + getNumInfoUnits();
auto *CU = std::upper_bound(
this->begin(), this->end(), CUOff->Offset,
[](uint32_t LHS, const std::unique_ptr<DWARFUnit> &RHS) {
return LHS < RHS->getNextUnitOffset();
});
if (CU != this->end() && (*CU)->getOffset() <= Offset)
auto *CU =
std::upper_bound(begin(), end, CUOff->Offset,
[](uint32_t LHS, const std::unique_ptr<DWARFUnit> &RHS) {
return LHS < RHS->getNextUnitOffset();
});
if (CU != end && (*CU)->getOffset() <= Offset)
return CU->get();
if (!Parser)
@ -148,6 +150,7 @@ DWARFUnitVector::getUnitForIndexEntry(const DWARFUnitIndex::Entry &E) {
auto *NewCU = U.get();
this->insert(CU, std::move(U));
++NumInfoUnits;
return NewCU;
}

Binary file not shown.

View File

@ -0,0 +1,8 @@
RUN: echo "%p/Inputs/llvm-symbolizer-tu.elf-x86-64 0x0" \
RUN: | llvm-symbolizer | FileCheck %s
Built from the following source:
...
CHECK: b.cpp:3:0