diff options
author | Zachary Turner <zturner@google.com> | 2018-09-05 23:30:38 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2018-09-05 23:30:38 +0000 |
commit | 7999b4fa48b31f67efa3662443a5c78343eb6f19 (patch) | |
tree | d29f403f65f7959cb4fbc5b70c603a6f16f91c40 /llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp | |
parent | e9f1df84af2f50a2cde01f7f2333f12ae326f3c1 (diff) | |
download | llvm-7999b4fa48b31f67efa3662443a5c78343eb6f19.zip llvm-7999b4fa48b31f67efa3662443a5c78343eb6f19.tar.gz llvm-7999b4fa48b31f67efa3662443a5c78343eb6f19.tar.bz2 |
[PDB] Refactor the PDB symbol classes to fix a reuse bug.
The way DIA SDK works is that when you request a symbol, it
gets assigned an internal identifier that is unique for the
life of the session. You can then use this identifier to
get back the same symbol, with all of the same internal state
that it had before, even if you "destroyed" the original
copy of the object you had.
This didn't work properly in our native implementation, and
if you destroyed an object for a particular symbol, then
requested the same symbol again, it would get assigned a new
ID and you'd get a fresh copy of the object. In order to fix
this some refactoring had to happen to properly reuse cached
objects. Some unittests are added to verify that symbol
reuse is taking place, making use of the new unittest input
feature.
llvm-svn: 341503
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp index bf66f1c..f3de408 100644 --- a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp @@ -63,7 +63,10 @@ static const struct BuiltinTypeEntry { NativeSession::NativeSession(std::unique_ptr<PDBFile> PdbFile, std::unique_ptr<BumpPtrAllocator> Allocator) - : Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)) {} + : Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)) { + // Id 0 is reserved for the invalid symbol. + SymbolCache.push_back(nullptr); +} NativeSession::~NativeSession() = default; @@ -91,20 +94,10 @@ Error NativeSession::createFromExe(StringRef Path, return make_error<RawError>(raw_error_code::feature_unsupported); } -std::unique_ptr<PDBSymbolCompiland> -NativeSession::createCompilandSymbol(DbiModuleDescriptor MI) { - const auto Id = static_cast<SymIndexId>(SymbolCache.size()); - SymbolCache.push_back( - llvm::make_unique<NativeCompilandSymbol>(*this, Id, MI)); - return llvm::make_unique<PDBSymbolCompiland>( - *this, std::unique_ptr<IPDBRawSymbol>(SymbolCache[Id]->clone())); -} - std::unique_ptr<PDBSymbolTypeEnum> NativeSession::createEnumSymbol(codeview::TypeIndex Index) { const auto Id = findSymbolByTypeIndex(Index); - return llvm::make_unique<PDBSymbolTypeEnum>( - *this, std::unique_ptr<IPDBRawSymbol>(SymbolCache[Id]->clone())); + return PDBSymbol::createAs<PDBSymbolTypeEnum>(*this, *SymbolCache[Id]); } std::unique_ptr<IPDBEnumSymbols> @@ -167,20 +160,14 @@ uint64_t NativeSession::getLoadAddress() const { return 0; } bool NativeSession::setLoadAddress(uint64_t Address) { return false; } std::unique_ptr<PDBSymbolExe> NativeSession::getGlobalScope() { - const auto Id = static_cast<SymIndexId>(SymbolCache.size()); - SymbolCache.push_back(llvm::make_unique<NativeExeSymbol>(*this, Id)); - auto RawSymbol = SymbolCache[Id]->clone(); - auto PdbSymbol(PDBSymbol::create(*this, std::move(RawSymbol))); - std::unique_ptr<PDBSymbolExe> ExeSymbol( - static_cast<PDBSymbolExe *>(PdbSymbol.release())); - return ExeSymbol; + return PDBSymbol::createAs<PDBSymbolExe>(*this, getNativeGlobalScope()); } std::unique_ptr<PDBSymbol> NativeSession::getSymbolById(uint32_t SymbolId) const { // If the caller has a SymbolId, it'd better be in our SymbolCache. return SymbolId < SymbolCache.size() - ? PDBSymbol::create(*this, SymbolCache[SymbolId]->clone()) + ? PDBSymbol::create(*this, *SymbolCache[SymbolId]) : nullptr; } @@ -290,3 +277,11 @@ std::unique_ptr<IPDBEnumSectionContribs> NativeSession::getSectionContribs() const { return nullptr; } + +NativeExeSymbol &NativeSession::getNativeGlobalScope() { + if (ExeSymbol == 0) { + ExeSymbol = static_cast<SymIndexId>(SymbolCache.size()); + SymbolCache.push_back(llvm::make_unique<NativeExeSymbol>(*this, ExeSymbol)); + } + return static_cast<NativeExeSymbol &>(*SymbolCache[ExeSymbol]); +} |