diff options
author | Zachary Turner <zturner@google.com> | 2018-09-07 00:12:34 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2018-09-07 00:12:34 +0000 |
commit | 8ab7dd6028ed5084db849206bddc1b50987749d8 (patch) | |
tree | 723034959637514fbd62860d496a44a3d0cc7b8a /llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp | |
parent | f0954dd27597d202229a3a9f97a0c36d33c09223 (diff) | |
download | bcm5719-llvm-8ab7dd6028ed5084db849206bddc1b50987749d8.tar.gz bcm5719-llvm-8ab7dd6028ed5084db849206bddc1b50987749d8.zip |
[PDB] Create a SymbolCache class.
Part of the responsibility of the native PDB reader is to cache
symbols the first time they are accessed, so they can then be
looked up by an ID. Furthermore, we need to resolve type indices
to records that we vend to the user, and other things. Previously
this code was all thrown together a bit haphazardly in the native
session class, but it makes sense to collect all of this into a
single class whose sole responsibility is to manage the collection
of known symbols.
llvm-svn: 341608
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp | 56 |
1 files changed, 17 insertions, 39 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp index 35305708a95..59eaf3e8d49 100644 --- a/llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp @@ -15,22 +15,24 @@ #include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h" #include "llvm/DebugInfo/PDB/Native/NativeEnumModules.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" +#include "llvm/DebugInfo/PDB/Native/SymbolCache.h" #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" using namespace llvm; using namespace llvm::pdb; +static DbiStream *getDbiStreamPtr(NativeSession &Session) { + Expected<DbiStream &> DbiS = Session.getPDBFile().getPDBDbiStream(); + if (DbiS) + return &DbiS.get(); + + consumeError(DbiS.takeError()); + return nullptr; +} + NativeExeSymbol::NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId) : NativeRawSymbol(Session, PDB_SymType::Exe, SymbolId), - File(Session.getPDBFile()) { - Expected<DbiStream &> DbiS = File.getPDBDbiStream(); - if (!DbiS) { - consumeError(DbiS.takeError()); - return; - } - Dbi = &DbiS.get(); - Compilands.resize(Dbi->modules().getModuleCount()); -} + Dbi(getDbiStreamPtr(Session)) {} std::unique_ptr<NativeRawSymbol> NativeExeSymbol::clone() const { return llvm::make_unique<NativeExeSymbol>(Session, SymbolId); @@ -44,7 +46,7 @@ NativeExeSymbol::findChildren(PDB_SymType Type) const { break; } case PDB_SymType::Enum: - return Session.createTypeEnumerator(codeview::LF_ENUM); + return Session.getSymbolCache().createTypeEnumerator(codeview::LF_ENUM); default: break; } @@ -52,7 +54,7 @@ NativeExeSymbol::findChildren(PDB_SymType Type) const { } uint32_t NativeExeSymbol::getAge() const { - auto IS = File.getPDBInfoStream(); + auto IS = Session.getPDBFile().getPDBInfoStream(); if (IS) return IS->getAge(); consumeError(IS.takeError()); @@ -60,11 +62,11 @@ uint32_t NativeExeSymbol::getAge() const { } std::string NativeExeSymbol::getSymbolsFileName() const { - return File.getFilePath(); + return Session.getPDBFile().getFilePath(); } codeview::GUID NativeExeSymbol::getGuid() const { - auto IS = File.getPDBInfoStream(); + auto IS = Session.getPDBFile().getPDBInfoStream(); if (IS) return IS->getGuid(); consumeError(IS.takeError()); @@ -72,7 +74,7 @@ codeview::GUID NativeExeSymbol::getGuid() const { } bool NativeExeSymbol::hasCTypes() const { - auto Dbi = File.getPDBDbiStream(); + auto Dbi = Session.getPDBFile().getPDBDbiStream(); if (Dbi) return Dbi->hasCTypes(); consumeError(Dbi.takeError()); @@ -80,33 +82,9 @@ bool NativeExeSymbol::hasCTypes() const { } bool NativeExeSymbol::hasPrivateSymbols() const { - auto Dbi = File.getPDBDbiStream(); + auto Dbi = Session.getPDBFile().getPDBDbiStream(); if (Dbi) return !Dbi->isStripped(); consumeError(Dbi.takeError()); return false; } - -uint32_t NativeExeSymbol::getNumCompilands() const { - if (!Dbi) - return 0; - - return Dbi->modules().getModuleCount(); -} - -std::unique_ptr<PDBSymbolCompiland> -NativeExeSymbol::getOrCreateCompiland(uint32_t Index) { - if (!Dbi) - return nullptr; - - if (Index >= Compilands.size()) - return nullptr; - - if (Compilands[Index] == 0) { - const DbiModuleList &Modules = Dbi->modules(); - Compilands[Index] = Session.createSymbol<NativeCompilandSymbol>( - Modules.getModuleDescriptor(Index)); - } - - return Session.getConcreteSymbolById<PDBSymbolCompiland>(Compilands[Index]); -} |