summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo/PDB/Native
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2018-09-05 23:30:38 +0000
committerZachary Turner <zturner@google.com>2018-09-05 23:30:38 +0000
commit7999b4fa48b31f67efa3662443a5c78343eb6f19 (patch)
treed29f403f65f7959cb4fbc5b70c603a6f16f91c40 /llvm/lib/DebugInfo/PDB/Native
parente9f1df84af2f50a2cde01f7f2333f12ae326f3c1 (diff)
downloadbcm5719-llvm-7999b4fa48b31f67efa3662443a5c78343eb6f19.tar.gz
bcm5719-llvm-7999b4fa48b31f67efa3662443a5c78343eb6f19.zip
[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')
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/NativeBuiltinSymbol.cpp4
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/NativeCompilandSymbol.cpp2
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/NativeEnumModules.cpp21
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/NativeEnumSymbol.cpp2
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp50
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp9
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp35
7 files changed, 70 insertions, 53 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeBuiltinSymbol.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeBuiltinSymbol.cpp
index 4644ddcf24e..81e35e56601 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeBuiltinSymbol.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeBuiltinSymbol.cpp
@@ -16,8 +16,8 @@ namespace pdb {
NativeBuiltinSymbol::NativeBuiltinSymbol(NativeSession &PDBSession,
SymIndexId Id, PDB_BuiltinType T,
uint64_t L)
- : NativeRawSymbol(PDBSession, Id), Session(PDBSession), Type(T), Length(L) {
-}
+ : NativeRawSymbol(PDBSession, PDB_SymType::BuiltinType, Id),
+ Session(PDBSession), Type(T), Length(L) {}
NativeBuiltinSymbol::~NativeBuiltinSymbol() {}
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeCompilandSymbol.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeCompilandSymbol.cpp
index 7132a99a9f1..da22a0ed89d 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeCompilandSymbol.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeCompilandSymbol.cpp
@@ -17,7 +17,7 @@ namespace pdb {
NativeCompilandSymbol::NativeCompilandSymbol(NativeSession &Session,
SymIndexId SymbolId,
DbiModuleDescriptor MI)
- : NativeRawSymbol(Session, SymbolId), Module(MI) {}
+ : NativeRawSymbol(Session, PDB_SymType::Compiland, SymbolId), Module(MI) {}
PDB_SymType NativeCompilandSymbol::getSymTag() const {
return PDB_SymType::Compiland;
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeEnumModules.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeEnumModules.cpp
index a65782e2d4f..f54568865aa 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeEnumModules.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeEnumModules.cpp
@@ -10,33 +10,30 @@
#include "llvm/DebugInfo/PDB/Native/NativeEnumModules.h"
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
-#include "llvm/DebugInfo/PDB/Native/DbiModuleList.h"
#include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h"
+#include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h"
#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
#include "llvm/DebugInfo/PDB/PDBSymbol.h"
#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
+#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
namespace llvm {
namespace pdb {
-NativeEnumModules::NativeEnumModules(NativeSession &PDBSession,
- const DbiModuleList &Modules,
- uint32_t Index)
- : Session(PDBSession), Modules(Modules), Index(Index) {}
+NativeEnumModules::NativeEnumModules(NativeSession &PDBSession, uint32_t Index)
+ : Session(PDBSession), Index(Index) {}
uint32_t NativeEnumModules::getChildCount() const {
- return static_cast<uint32_t>(Modules.getModuleCount());
+ return Session.getNativeGlobalScope().getNumCompilands();
}
std::unique_ptr<PDBSymbol>
-NativeEnumModules::getChildAtIndex(uint32_t Index) const {
- if (Index >= Modules.getModuleCount())
- return nullptr;
- return Session.createCompilandSymbol(Modules.getModuleDescriptor(Index));
+NativeEnumModules::getChildAtIndex(uint32_t N) const {
+ return Session.getNativeGlobalScope().getOrCreateCompiland(N);
}
std::unique_ptr<PDBSymbol> NativeEnumModules::getNext() {
- if (Index >= Modules.getModuleCount())
+ if (Index >= getChildCount())
return nullptr;
return getChildAtIndex(Index++);
}
@@ -44,7 +41,7 @@ std::unique_ptr<PDBSymbol> NativeEnumModules::getNext() {
void NativeEnumModules::reset() { Index = 0; }
NativeEnumModules *NativeEnumModules::clone() const {
- return new NativeEnumModules(Session, Modules, Index);
+ return new NativeEnumModules(Session, Index);
}
}
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeEnumSymbol.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeEnumSymbol.cpp
index 38d65917306..5dbdff7e746 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeEnumSymbol.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeEnumSymbol.cpp
@@ -21,7 +21,7 @@ using namespace llvm::pdb;
NativeEnumSymbol::NativeEnumSymbol(NativeSession &Session, SymIndexId Id,
const codeview::CVType &CVT)
- : NativeRawSymbol(Session, Id), CV(CVT),
+ : NativeRawSymbol(Session, PDB_SymType::Enum, Id), CV(CVT),
Record(codeview::TypeRecordKind::Enum) {
assert(CV.kind() == codeview::TypeLeafKind::LF_ENUM);
cantFail(visitTypeRecord(CV, *this));
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp
index e8b06065fc6..35305708a95 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp
@@ -12,14 +12,25 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
+#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/PDBSymbolCompiland.h"
-namespace llvm {
-namespace pdb {
+using namespace llvm;
+using namespace llvm::pdb;
NativeExeSymbol::NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId)
- : NativeRawSymbol(Session, SymbolId), File(Session.getPDBFile()) {}
+ : 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());
+}
std::unique_ptr<NativeRawSymbol> NativeExeSymbol::clone() const {
return llvm::make_unique<NativeExeSymbol>(Session, SymbolId);
@@ -29,13 +40,7 @@ std::unique_ptr<IPDBEnumSymbols>
NativeExeSymbol::findChildren(PDB_SymType Type) const {
switch (Type) {
case PDB_SymType::Compiland: {
- auto Dbi = File.getPDBDbiStream();
- if (Dbi) {
- const DbiModuleList &Modules = Dbi->modules();
- return std::unique_ptr<IPDBEnumSymbols>(
- new NativeEnumModules(Session, Modules));
- }
- consumeError(Dbi.takeError());
+ return std::unique_ptr<IPDBEnumSymbols>(new NativeEnumModules(Session));
break;
}
case PDB_SymType::Enum:
@@ -82,5 +87,26 @@ bool NativeExeSymbol::hasPrivateSymbols() const {
return false;
}
-} // namespace pdb
-} // namespace llvm
+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]);
+}
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp
index fbe334823e0..21527100461 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp
@@ -14,8 +14,9 @@
using namespace llvm;
using namespace llvm::pdb;
-NativeRawSymbol::NativeRawSymbol(NativeSession &PDBSession, SymIndexId SymbolId)
- : Session(PDBSession), SymbolId(SymbolId) {}
+NativeRawSymbol::NativeRawSymbol(NativeSession &PDBSession, PDB_SymType Tag,
+ SymIndexId SymbolId)
+ : Session(PDBSession), Tag(Tag), SymbolId(SymbolId) {}
void NativeRawSymbol::dump(raw_ostream &OS, int Indent) const {}
@@ -374,9 +375,7 @@ PDB_DataKind NativeRawSymbol::getDataKind() const {
return PDB_DataKind::Unknown;
}
-PDB_SymType NativeRawSymbol::getSymTag() const {
- return PDB_SymType::None;
-}
+PDB_SymType NativeRawSymbol::getSymTag() const { return Tag; }
codeview::GUID NativeRawSymbol::getGuid() const { return codeview::GUID{{0}}; }
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
index bf66f1c3f42..f3de40811b1 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]);
+}
OpenPOWER on IntegriCloud