[llvm] r341889 - llvm-symbolizer: Fix bug related to TUs interfering with symbolizing
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 10 19:04:46 PDT 2018
Author: dblaikie
Date: Mon Sep 10 19:04:45 2018
New Revision: 341889
URL: http://llvm.org/viewvc/llvm-project?rev=341889&view=rev
Log:
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.
Added:
llvm/trunk/test/DebugInfo/Inputs/llvm-symbolizer-tu.elf-x86-64
llvm/trunk/test/DebugInfo/llvm-symbolizer-tu.test
Modified:
llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h
llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h?rev=341889&r1=341888&r2=341889&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h Mon Sep 10 19:04:45 2018
@@ -110,7 +110,7 @@ class DWARFUnitVector final : public Sma
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(); }
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp?rev=341889&r1=341888&r2=341889&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp Mon Sep 10 19:04:45 2018
@@ -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(co
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(co
auto *NewCU = U.get();
this->insert(CU, std::move(U));
+ ++NumInfoUnits;
return NewCU;
}
Added: llvm/trunk/test/DebugInfo/Inputs/llvm-symbolizer-tu.elf-x86-64
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Inputs/llvm-symbolizer-tu.elf-x86-64?rev=341889&view=auto
==============================================================================
Binary files llvm/trunk/test/DebugInfo/Inputs/llvm-symbolizer-tu.elf-x86-64 (added) and llvm/trunk/test/DebugInfo/Inputs/llvm-symbolizer-tu.elf-x86-64 Mon Sep 10 19:04:45 2018 differ
Added: llvm/trunk/test/DebugInfo/llvm-symbolizer-tu.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/llvm-symbolizer-tu.test?rev=341889&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/llvm-symbolizer-tu.test (added)
+++ llvm/trunk/test/DebugInfo/llvm-symbolizer-tu.test Mon Sep 10 19:04:45 2018
@@ -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
More information about the llvm-commits
mailing list