From 815d217552ddff77b3667a21e77a50e374bdfedf Mon Sep 17 00:00:00 2001 From: Dehao Chen Date: Wed, 19 Apr 2017 15:28:58 +0000 Subject: [PATCH] Revert r300697 which causes buildbot failure. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300708 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/DebugInfo/DWARF/DWARFDie.h | 7 +++ include/llvm/DebugInfo/DWARF/DWARFUnit.h | 13 +---- lib/DebugInfo/DWARF/DWARFDie.cpp | 26 ++++++++++ lib/DebugInfo/DWARF/DWARFUnit.cpp | 64 +++++++----------------- 4 files changed, 52 insertions(+), 58 deletions(-) diff --git a/include/llvm/DebugInfo/DWARF/DWARFDie.h b/include/llvm/DebugInfo/DWARF/DWARFDie.h index ee06125ea27..9b260c08198 100644 --- a/include/llvm/DebugInfo/DWARF/DWARFDie.h +++ b/include/llvm/DebugInfo/DWARF/DWARFDie.h @@ -252,6 +252,13 @@ public: void getCallerFrame(uint32_t &CallFile, uint32_t &CallLine, uint32_t &CallColumn, uint32_t &CallDiscriminator) const; + /// Get inlined chain for a given address, rooted at the current DIE. + /// Returns empty chain if address is not contained in address range + /// of current DIE. + void + getInlinedChainForAddress(const uint64_t Address, + SmallVectorImpl &InlinedChain) const; + class attribute_iterator; /// Get an iterator range to all attributes in the current DIE only. diff --git a/include/llvm/DebugInfo/DWARF/DWARFUnit.h b/include/llvm/DebugInfo/DWARF/DWARFUnit.h index 023a0f7b9fb..40eb4434bd6 100644 --- a/include/llvm/DebugInfo/DWARF/DWARFUnit.h +++ b/include/llvm/DebugInfo/DWARF/DWARFUnit.h @@ -31,7 +31,6 @@ #include #include #include -#include namespace llvm { @@ -135,11 +134,6 @@ class DWARFUnit { uint64_t BaseAddr; // The compile unit debug information entry items. std::vector DieArray; - - // Map from range's start address to end address and corresponding DIE. - // IntervalMap does not support range removal, as a result, we use the - // std::map::upper_bound for address range lookup. - std::map> AddrDieMap; typedef iterator_range::iterator> die_iterator_range; @@ -189,9 +183,6 @@ public: AddrOffsetSectionBase = Base; } - // Recursively update address to Die map. - void updateAddressDieMap(DWARFDie Die); - void setRangesSection(StringRef RS, uint32_t Base) { RangeSection = RS; RangeSectionBase = Base; @@ -348,10 +339,10 @@ private: /// it was actually constructed. bool parseDWO(); - /// getSubroutineForAddress - Returns subprogram DIE with address range + /// getSubprogramForAddress - Returns subprogram DIE with address range /// encompassing the provided address. The pointer is alive as long as parsed /// compile unit DIEs are not cleared. - DWARFDie getSubroutineForAddress(uint64_t Address); + DWARFDie getSubprogramForAddress(uint64_t Address); }; } // end namespace llvm diff --git a/lib/DebugInfo/DWARF/DWARFDie.cpp b/lib/DebugInfo/DWARF/DWARFDie.cpp index 24039eb3520..b88cc636d84 100644 --- a/lib/DebugInfo/DWARF/DWARFDie.cpp +++ b/lib/DebugInfo/DWARF/DWARFDie.cpp @@ -352,6 +352,32 @@ void DWARFDie::dump(raw_ostream &OS, unsigned RecurseDepth, } } +void DWARFDie::getInlinedChainForAddress( + const uint64_t Address, SmallVectorImpl &InlinedChain) const { + if (isNULL()) + return; + DWARFDie DIE(*this); + while (DIE) { + // Append current DIE to inlined chain only if it has correct tag + // (e.g. it is not a lexical block). + if (DIE.isSubroutineDIE()) + InlinedChain.push_back(DIE); + + // Try to get child which also contains provided address. + DWARFDie Child = DIE.getFirstChild(); + while (Child) { + if (Child.addressRangeContainsAddress(Address)) { + // Assume there is only one such child. + break; + } + Child = Child.getSibling(); + } + DIE = Child; + } + // Reverse the obtained chain to make the root of inlined chain last. + std::reverse(InlinedChain.begin(), InlinedChain.end()); +} + DWARFDie DWARFDie::getParent() const { if (isValid()) return U->getParent(Die); diff --git a/lib/DebugInfo/DWARF/DWARFUnit.cpp b/lib/DebugInfo/DWARF/DWARFUnit.cpp index 485e2f79e3f..4ee8e8f46d2 100644 --- a/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ b/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -343,66 +343,36 @@ void DWARFUnit::collectAddressRanges(DWARFAddressRangesVector &CURanges) { clearDIEs(true); } -void DWARFUnit::updateAddressDieMap(DWARFDie Die) { - if (Die.isSubroutineDIE()) { - for (const auto &R : Die.getAddressRanges()) { - // Ignore 0-sized ranges. - if (R.first == R.second) - continue; - auto B = AddrDieMap.upper_bound(R.first); - if (B != AddrDieMap.begin() && R.first < (--B)->second.first) { - // The range is a sub-range of existing ranges, we need to split the - // existing range. - if (R.second < B->second.first) - AddrDieMap[R.second] = B->second; - if (R.first > B->first) - AddrDieMap[B->first].first = R.first; - } - AddrDieMap[R.first] = std::make_pair(R.second, Die); +DWARFDie +DWARFUnit::getSubprogramForAddress(uint64_t Address) { + extractDIEsIfNeeded(false); + for (const DWARFDebugInfoEntry &D : DieArray) { + DWARFDie DIE(this, &D); + if (DIE.isSubprogramDIE() && + DIE.addressRangeContainsAddress(Address)) { + return DIE; } } - // Parent DIEs are added to the AddrDieMap prior to the Children DIEs to - // simplify the logic to update AddrDieMap. The child's range will always - // be equal or smaller than the parent's range. With this assumption, when - // adding one range into the map, it will at most split a range into 3 - // sub-ranges. - for (DWARFDie Child = Die.getFirstChild(); Child; Child = Child.getSibling()) - updateAddressDieMap(Child); -} - -DWARFDie DWARFUnit::getSubroutineForAddress(uint64_t Address) { - extractDIEsIfNeeded(false); - if (AddrDieMap.empty()) - updateAddressDieMap(getUnitDIE()); - auto R = AddrDieMap.upper_bound(Address); - if (R == AddrDieMap.begin()) - return DWARFDie(); - // upper_bound's previous item contains Address. - --R; - assert(Address <= R->second.first); - return R->second.second; + return DWARFDie(); } void DWARFUnit::getInlinedChainForAddress(uint64_t Address, SmallVectorImpl &InlinedChain) { - // First, find the subroutine that contains the given address (the leaf + // First, find a subprogram that contains the given address (the root // of inlined chain). - DWARFDie SubroutineDIE; + DWARFDie SubprogramDIE; // Try to look for subprogram DIEs in the DWO file. parseDWO(); if (DWO) - SubroutineDIE = DWO->getUnit()->getSubroutineForAddress(Address); + SubprogramDIE = DWO->getUnit()->getSubprogramForAddress(Address); else - SubroutineDIE = getSubroutineForAddress(Address); + SubprogramDIE = getSubprogramForAddress(Address); - if (SubroutineDIE) { - while (SubroutineDIE) { - if (SubroutineDIE.isSubroutineDIE()) - InlinedChain.push_back(SubroutineDIE); - SubroutineDIE = SubroutineDIE.getParent(); - } - } else + // Get inlined chain rooted at this subprogram DIE. + if (SubprogramDIE) + SubprogramDIE.getInlinedChainForAddress(Address, InlinedChain); + else InlinedChain.clear(); } -- 2.50.1