diff options
author | Amy Huang <akhuang@google.com> | 2020-09-15 09:38:42 -0700 |
---|---|---|
committer | Amy Huang <akhuang@google.com> | 2020-11-17 13:19:13 -0800 |
commit | bc9803404042aa45417cf4f6925fb06b44f1ad93 (patch) | |
tree | c2d77fef64822c78451ebbfb8a72fd45fefd6b08 /llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp | |
parent | eced4a8e6fe3041b699bd22b5b89bea47c84c51a (diff) | |
download | llvm-bc9803404042aa45417cf4f6925fb06b44f1ad93.zip llvm-bc9803404042aa45417cf4f6925fb06b44f1ad93.tar.gz llvm-bc9803404042aa45417cf4f6925fb06b44f1ad93.tar.bz2 |
[llvm-symbolizer] Add inline stack traces for Windows.
This adds inline stack frames for symbolizing on Windows.
Differential Revision: https://reviews.llvm.org/D88988
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp index acd2902..5d7946c 100644 --- a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp @@ -13,6 +13,7 @@ #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" #include "llvm/DebugInfo/PDB/IPDBSourceFile.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h" +#include "llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h" #include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h" #include "llvm/DebugInfo/PDB/Native/NativeEnumInjectedSources.h" #include "llvm/DebugInfo/PDB/Native/NativeEnumTypes.h" @@ -56,7 +57,7 @@ static DbiStream *getDbiStreamPtr(PDBFile &File) { NativeSession::NativeSession(std::unique_ptr<PDBFile> PdbFile, std::unique_ptr<BumpPtrAllocator> Allocator) : Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)), - Cache(*this, getDbiStreamPtr(*Pdb)) {} + Cache(*this, getDbiStreamPtr(*Pdb)), AddrToModuleIndex(IMapAllocator) {} NativeSession::~NativeSession() = default; @@ -255,6 +256,9 @@ std::unique_ptr<PDBSymbol> NativeSession::findSymbolByRVA(uint32_t RVA, std::unique_ptr<PDBSymbol> NativeSession::findSymbolBySectOffset(uint32_t Sect, uint32_t Offset, PDB_SymType Type) { + if (AddrToModuleIndex.empty()) + parseSectionContribs(); + return Cache.findSymbolBySectOffset(Sect, Offset, Type); } @@ -386,3 +390,74 @@ uint64_t NativeSession::getVAFromSectOffset(uint32_t Section, uint32_t Offset) const { return LoadAddress + getRVAFromSectOffset(Section, Offset); } + +bool NativeSession::moduleIndexForVA(uint64_t VA, uint16_t &ModuleIndex) const { + ModuleIndex = 0; + auto Iter = AddrToModuleIndex.find(VA); + if (Iter == AddrToModuleIndex.end()) + return false; + ModuleIndex = Iter.value(); + return true; +} + +bool NativeSession::moduleIndexForSectOffset(uint32_t Sect, uint32_t Offset, + uint16_t &ModuleIndex) const { + ModuleIndex = 0; + auto Iter = AddrToModuleIndex.find(getVAFromSectOffset(Sect, Offset)); + if (Iter == AddrToModuleIndex.end()) + return false; + ModuleIndex = Iter.value(); + return true; +} + +void NativeSession::parseSectionContribs() { + auto Dbi = Pdb->getPDBDbiStream(); + if (!Dbi) + return; + + class Visitor : public ISectionContribVisitor { + NativeSession &Session; + IMap &AddrMap; + + public: + Visitor(NativeSession &Session, IMap &AddrMap) + : Session(Session), AddrMap(AddrMap) {} + void visit(const SectionContrib &C) override { + if (C.Size == 0) + return; + + uint64_t VA = Session.getVAFromSectOffset(C.ISect, C.Off); + uint64_t End = VA + C.Size; + + // Ignore overlapping sections based on the assumption that a valid + // PDB file should not have overlaps. + if (!AddrMap.overlaps(VA, End)) + AddrMap.insert(VA, End, C.Imod); + } + void visit(const SectionContrib2 &C) override { visit(C.Base); } + }; + + Visitor V(*this, AddrToModuleIndex); + Dbi->visitSectionContributions(V); +} + +Expected<ModuleDebugStreamRef> +NativeSession::getModuleDebugStream(uint32_t Index) const { + auto *Dbi = getDbiStreamPtr(*Pdb); + assert(Dbi && "Dbi stream not present"); + + DbiModuleDescriptor Modi = Dbi->modules().getModuleDescriptor(Index); + + uint16_t ModiStream = Modi.getModuleStreamIndex(); + if (ModiStream == kInvalidStreamIndex) + return make_error<RawError>("Module stream not present"); + + std::unique_ptr<msf::MappedBlockStream> ModStreamData = + Pdb->createIndexedStream(ModiStream); + + ModuleDebugStreamRef ModS(Modi, std::move(ModStreamData)); + if (auto EC = ModS.reload()) + return std::move(EC); + + return std::move(ModS); +} |