[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
This commit is contained in:
Zachary Turner 2018-09-05 23:30:38 +00:00
parent 8f68390df4
commit bcf0078c33
81 changed files with 327 additions and 422 deletions

View File

@ -11,18 +11,15 @@
#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVEENUMMODULES_H #define LLVM_DEBUGINFO_PDB_NATIVE_NATIVEENUMMODULES_H
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
#include "llvm/DebugInfo/PDB/PDBSymbol.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h"
namespace llvm { namespace llvm {
namespace pdb { namespace pdb {
class DbiModuleList;
class NativeSession; class NativeSession;
class NativeEnumModules : public IPDBEnumChildren<PDBSymbol> { class NativeEnumModules : public IPDBEnumChildren<PDBSymbol> {
public: public:
NativeEnumModules(NativeSession &Session, const DbiModuleList &Modules, NativeEnumModules(NativeSession &Session, uint32_t Index = 0);
uint32_t Index = 0);
uint32_t getChildCount() const override; uint32_t getChildCount() const override;
std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const override; std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const override;
@ -32,7 +29,6 @@ public:
private: private:
NativeSession &Session; NativeSession &Session;
const DbiModuleList &Modules;
uint32_t Index; uint32_t Index;
}; };
} }

View File

@ -16,6 +16,8 @@
namespace llvm { namespace llvm {
namespace pdb { namespace pdb {
class DbiStream;
class NativeExeSymbol : public NativeRawSymbol { class NativeExeSymbol : public NativeRawSymbol {
public: public:
NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId); NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId);
@ -31,8 +33,16 @@ public:
bool hasCTypes() const override; bool hasCTypes() const override;
bool hasPrivateSymbols() const override; bool hasPrivateSymbols() const override;
std::unique_ptr<PDBSymbolCompiland> getOrCreateCompiland(uint32_t Index);
uint32_t getNumCompilands() const;
private: private:
PDBFile &File; PDBFile &File;
DbiStream *Dbi = nullptr;
// EXE symbol is the authority on the various symbol types.
mutable std::vector<SymIndexId> Compilands;
}; };
} // namespace pdb } // namespace pdb

View File

@ -23,7 +23,8 @@ typedef uint32_t SymIndexId;
class NativeRawSymbol : public IPDBRawSymbol { class NativeRawSymbol : public IPDBRawSymbol {
public: public:
NativeRawSymbol(NativeSession &PDBSession, SymIndexId SymbolId); NativeRawSymbol(NativeSession &PDBSession, PDB_SymType Tag,
SymIndexId SymbolId);
virtual std::unique_ptr<NativeRawSymbol> clone() const = 0; virtual std::unique_ptr<NativeRawSymbol> clone() const = 0;
@ -230,6 +231,7 @@ public:
protected: protected:
NativeSession &Session; NativeSession &Session;
PDB_SymType Tag;
SymIndexId SymbolId; SymIndexId SymbolId;
}; };

View File

@ -15,7 +15,6 @@
#include "llvm/DebugInfo/CodeView/TypeIndex.h" #include "llvm/DebugInfo/CodeView/TypeIndex.h"
#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h" #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
#include "llvm/DebugInfo/PDB/IPDBSession.h" #include "llvm/DebugInfo/PDB/IPDBSession.h"
#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
#include "llvm/DebugInfo/PDB/Native/NativeBuiltinSymbol.h" #include "llvm/DebugInfo/PDB/Native/NativeBuiltinSymbol.h"
#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" #include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h"
#include "llvm/Support/Allocator.h" #include "llvm/Support/Allocator.h"
@ -25,6 +24,7 @@ namespace llvm {
class MemoryBuffer; class MemoryBuffer;
namespace pdb { namespace pdb {
class PDBFile; class PDBFile;
class NativeExeSymbol;
class NativeSession : public IPDBSession { class NativeSession : public IPDBSession {
public: public:
@ -37,8 +37,16 @@ public:
static Error createFromExe(StringRef Path, static Error createFromExe(StringRef Path,
std::unique_ptr<IPDBSession> &Session); std::unique_ptr<IPDBSession> &Session);
std::unique_ptr<PDBSymbolCompiland> template <typename ConcreteSymbolT, typename... Args>
createCompilandSymbol(DbiModuleDescriptor MI); SymIndexId createSymbol(Args &&... ConstructorArgs) {
SymIndexId Id = SymbolCache.size();
std::unique_ptr<ConcreteSymbolT> Symbol =
llvm::make_unique<ConcreteSymbolT>(
*this, Id, std::forward<Args>(ConstructorArgs)...);
std::unique_ptr<NativeRawSymbol> NRS = std::move(Symbol);
SymbolCache.push_back(std::move(NRS));
return Id;
}
std::unique_ptr<PDBSymbolTypeEnum> std::unique_ptr<PDBSymbolTypeEnum>
createEnumSymbol(codeview::TypeIndex Index); createEnumSymbol(codeview::TypeIndex Index);
@ -107,7 +115,11 @@ public:
PDBFile &getPDBFile() { return *Pdb; } PDBFile &getPDBFile() { return *Pdb; }
const PDBFile &getPDBFile() const { return *Pdb; } const PDBFile &getPDBFile() const { return *Pdb; }
NativeExeSymbol &getNativeGlobalScope();
private: private:
SymIndexId ExeSymbol = 0;
std::unique_ptr<PDBFile> Pdb; std::unique_ptr<PDBFile> Pdb;
std::unique_ptr<BumpPtrAllocator> Allocator; std::unique_ptr<BumpPtrAllocator> Allocator;
std::vector<std::unique_ptr<NativeRawSymbol>> SymbolCache; std::vector<std::unique_ptr<NativeRawSymbol>> SymbolCache;

View File

@ -49,9 +49,22 @@ class IPDBRawSymbol;
class IPDBSession; class IPDBSession;
#define DECLARE_PDB_SYMBOL_CONCRETE_TYPE(TagValue) \ #define DECLARE_PDB_SYMBOL_CONCRETE_TYPE(TagValue) \
private: \
using PDBSymbol::PDBSymbol; \
friend class PDBSymbol; \
\
public: \
static const PDB_SymType Tag = TagValue; \ static const PDB_SymType Tag = TagValue; \
static bool classof(const PDBSymbol *S) { return S->getSymTag() == Tag; } static bool classof(const PDBSymbol *S) { return S->getSymTag() == Tag; }
#define DECLARE_PDB_SYMBOL_CUSTOM_TYPE(Condition) \
private: \
using PDBSymbol::PDBSymbol; \
friend class PDBSymbol; \
\
public: \
static bool classof(const PDBSymbol *S) { return Condition; }
/// PDBSymbol defines the base of the inheritance hierarchy for concrete symbol /// PDBSymbol defines the base of the inheritance hierarchy for concrete symbol
/// types (e.g. functions, executables, vtables, etc). All concrete symbol /// types (e.g. functions, executables, vtables, etc). All concrete symbol
/// types inherit from PDBSymbol and expose the exact set of methods that are /// types inherit from PDBSymbol and expose the exact set of methods that are
@ -59,14 +72,33 @@ class IPDBSession;
/// reference "Lexical and Class Hierarchy of Symbol Types": /// reference "Lexical and Class Hierarchy of Symbol Types":
/// https://msdn.microsoft.com/en-us/library/370hs6k4.aspx /// https://msdn.microsoft.com/en-us/library/370hs6k4.aspx
class PDBSymbol { class PDBSymbol {
static std::unique_ptr<PDBSymbol> createSymbol(const IPDBSession &PDBSession,
PDB_SymType Tag);
protected: protected:
PDBSymbol(const IPDBSession &PDBSession, explicit PDBSymbol(const IPDBSession &PDBSession);
std::unique_ptr<IPDBRawSymbol> Symbol); PDBSymbol(PDBSymbol &&Other);
PDBSymbol(PDBSymbol &Symbol);
public: public:
static std::unique_ptr<PDBSymbol> static std::unique_ptr<PDBSymbol>
create(const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol); create(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> RawSymbol);
static std::unique_ptr<PDBSymbol> create(const IPDBSession &PDBSession,
IPDBRawSymbol &RawSymbol);
template <typename ConcreteT>
static std::unique_ptr<ConcreteT>
createAs(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> RawSymbol) {
std::unique_ptr<PDBSymbol> S = create(PDBSession, std::move(RawSymbol));
return unique_dyn_cast_or_null<ConcreteT>(std::move(S));
}
template <typename ConcreteT>
static std::unique_ptr<ConcreteT> createAs(const IPDBSession &PDBSession,
IPDBRawSymbol &RawSymbol) {
std::unique_ptr<PDBSymbol> S = create(PDBSession, RawSymbol);
return unique_dyn_cast_or_null<ConcreteT>(std::move(S));
}
virtual ~PDBSymbol(); virtual ~PDBSymbol();
@ -131,7 +163,8 @@ protected:
} }
const IPDBSession &Session; const IPDBSession &Session;
std::unique_ptr<IPDBRawSymbol> RawSymbol; std::unique_ptr<IPDBRawSymbol> OwnedRawSymbol;
IPDBRawSymbol *RawSymbol = nullptr;
}; };
} // namespace llvm } // namespace llvm

View File

@ -18,12 +18,9 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolAnnotation : public PDBSymbol { class PDBSymbolAnnotation : public PDBSymbol {
public:
PDBSymbolAnnotation(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Annotation) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Annotation)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAddressOffset) FORWARD_SYMBOL_METHOD(getAddressOffset)

View File

@ -19,12 +19,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolBlock : public PDBSymbol { class PDBSymbolBlock : public PDBSymbol {
public:
PDBSymbolBlock(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Block) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Block)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAddressOffset) FORWARD_SYMBOL_METHOD(getAddressOffset)

View File

@ -20,12 +20,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolCompiland : public PDBSymbol { class PDBSymbolCompiland : public PDBSymbol {
public:
PDBSymbolCompiland(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> CompilandSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Compiland) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Compiland)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(isEditAndContinueEnabled) FORWARD_SYMBOL_METHOD(isEditAndContinueEnabled)

View File

@ -19,12 +19,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolCompilandDetails : public PDBSymbol { class PDBSymbolCompilandDetails : public PDBSymbol {
public:
PDBSymbolCompilandDetails(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CompilandDetails) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CompilandDetails)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
void getFrontEndVersion(VersionInfo &Version) const { void getFrontEndVersion(VersionInfo &Version) const {

View File

@ -18,12 +18,8 @@ namespace llvm {
class raw_ostream; class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolCompilandEnv : public PDBSymbol { class PDBSymbolCompilandEnv : public PDBSymbol {
public:
PDBSymbolCompilandEnv(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CompilandEnv) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CompilandEnv)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_ID_METHOD(getLexicalParent) FORWARD_SYMBOL_ID_METHOD(getLexicalParent)

View File

@ -23,12 +23,8 @@ namespace pdb {
/// fit anywhere else in the lexical hierarchy. /// fit anywhere else in the lexical hierarchy.
/// https://msdn.microsoft.com/en-us/library/d88sf09h.aspx /// https://msdn.microsoft.com/en-us/library/d88sf09h.aspx
class PDBSymbolCustom : public PDBSymbol { class PDBSymbolCustom : public PDBSymbol {
public:
PDBSymbolCustom(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> CustomSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Custom) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Custom)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
void getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes); void getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes);

View File

@ -21,12 +21,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolData : public PDBSymbol { class PDBSymbolData : public PDBSymbol {
public:
PDBSymbolData(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> DataSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Data) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Data)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAccess) FORWARD_SYMBOL_METHOD(getAccess)

View File

@ -20,12 +20,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolExe : public PDBSymbol { class PDBSymbolExe : public PDBSymbol {
public:
PDBSymbolExe(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> ExeSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Exe) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Exe)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAge) FORWARD_SYMBOL_METHOD(getAge)

View File

@ -22,18 +22,14 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolFunc : public PDBSymbol { class PDBSymbolFunc : public PDBSymbol {
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Function)
public: public:
PDBSymbolFunc(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> FuncSymbol);
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
bool isDestructor() const; bool isDestructor() const;
std::unique_ptr<IPDBEnumChildren<PDBSymbolData>> getArguments() const; std::unique_ptr<IPDBEnumChildren<PDBSymbolData>> getArguments() const;
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Function)
FORWARD_SYMBOL_METHOD(getAccess) FORWARD_SYMBOL_METHOD(getAccess)
FORWARD_SYMBOL_METHOD(getAddressOffset) FORWARD_SYMBOL_METHOD(getAddressOffset)
FORWARD_SYMBOL_METHOD(getAddressSection) FORWARD_SYMBOL_METHOD(getAddressSection)

View File

@ -20,12 +20,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolFuncDebugEnd : public PDBSymbol { class PDBSymbolFuncDebugEnd : public PDBSymbol {
public:
PDBSymbolFuncDebugEnd(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> FuncDebugEndSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FuncDebugEnd) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FuncDebugEnd)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAddressOffset) FORWARD_SYMBOL_METHOD(getAddressOffset)

View File

@ -19,12 +19,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolFuncDebugStart : public PDBSymbol { class PDBSymbolFuncDebugStart : public PDBSymbol {
public:
PDBSymbolFuncDebugStart(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> FuncDebugStartSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FuncDebugStart) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FuncDebugStart)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAddressOffset) FORWARD_SYMBOL_METHOD(getAddressOffset)

View File

@ -19,12 +19,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolLabel : public PDBSymbol { class PDBSymbolLabel : public PDBSymbol {
public:
PDBSymbolLabel(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> LabelSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Label) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Label)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAddressOffset) FORWARD_SYMBOL_METHOD(getAddressOffset)

View File

@ -19,12 +19,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolPublicSymbol : public PDBSymbol { class PDBSymbolPublicSymbol : public PDBSymbol {
public:
PDBSymbolPublicSymbol(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> PublicSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::PublicSymbol) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::PublicSymbol)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAddressOffset) FORWARD_SYMBOL_METHOD(getAddressOffset)

View File

@ -19,12 +19,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolThunk : public PDBSymbol { class PDBSymbolThunk : public PDBSymbol {
public:
PDBSymbolThunk(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> ThunkSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Thunk) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Thunk)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAccess) FORWARD_SYMBOL_METHOD(getAccess)

View File

@ -19,12 +19,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolTypeArray : public PDBSymbol { class PDBSymbolTypeArray : public PDBSymbol {
public:
PDBSymbolTypeArray(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> ArrayTypeSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::ArrayType) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::ArrayType)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
void dumpRight(PDBSymDumper &Dumper) const override; void dumpRight(PDBSymDumper &Dumper) const override;

View File

@ -22,12 +22,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolTypeBaseClass : public PDBSymbol { class PDBSymbolTypeBaseClass : public PDBSymbol {
public:
PDBSymbolTypeBaseClass(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::BaseClass) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::BaseClass)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAccess) FORWARD_SYMBOL_METHOD(getAccess)

View File

@ -19,12 +19,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolTypeBuiltin : public PDBSymbol { class PDBSymbolTypeBuiltin : public PDBSymbol {
public:
PDBSymbolTypeBuiltin(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::BuiltinType) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::BuiltinType)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getBuiltinType) FORWARD_SYMBOL_METHOD(getBuiltinType)

View File

@ -19,12 +19,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolTypeCustom : public PDBSymbol { class PDBSymbolTypeCustom : public PDBSymbol {
public:
PDBSymbolTypeCustom(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CustomType) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CustomType)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getOemId) FORWARD_SYMBOL_METHOD(getOemId)

View File

@ -19,12 +19,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolTypeDimension : public PDBSymbol { class PDBSymbolTypeDimension : public PDBSymbol {
public:
PDBSymbolTypeDimension(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Dimension) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Dimension)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getLowerBoundId) FORWARD_SYMBOL_METHOD(getLowerBoundId)

View File

@ -21,12 +21,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolTypeEnum : public PDBSymbol { class PDBSymbolTypeEnum : public PDBSymbol {
public:
PDBSymbolTypeEnum(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> EnumTypeSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Enum) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Enum)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getBuiltinType) FORWARD_SYMBOL_METHOD(getBuiltinType)

View File

@ -19,12 +19,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolTypeFriend : public PDBSymbol { class PDBSymbolTypeFriend : public PDBSymbol {
public:
PDBSymbolTypeFriend(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Friend) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Friend)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_ID_METHOD(getClassParent) FORWARD_SYMBOL_ID_METHOD(getClassParent)

View File

@ -19,12 +19,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolTypeFunctionArg : public PDBSymbol { class PDBSymbolTypeFunctionArg : public PDBSymbol {
public:
PDBSymbolTypeFunctionArg(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FunctionArg) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FunctionArg)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_ID_METHOD(getClassParent) FORWARD_SYMBOL_ID_METHOD(getClassParent)

View File

@ -19,12 +19,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolTypeFunctionSig : public PDBSymbol { class PDBSymbolTypeFunctionSig : public PDBSymbol {
public:
PDBSymbolTypeFunctionSig(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FunctionSig) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FunctionSig)
public:
std::unique_ptr<IPDBEnumSymbols> getArguments() const; std::unique_ptr<IPDBEnumSymbols> getArguments() const;
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;

View File

@ -19,12 +19,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolTypeManaged : public PDBSymbol { class PDBSymbolTypeManaged : public PDBSymbol {
public:
PDBSymbolTypeManaged(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::ManagedType) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::ManagedType)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getName) FORWARD_SYMBOL_METHOD(getName)

View File

@ -19,12 +19,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolTypePointer : public PDBSymbol { class PDBSymbolTypePointer : public PDBSymbol {
public:
PDBSymbolTypePointer(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::PointerType) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::PointerType)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
void dumpRight(PDBSymDumper &Dumper) const override; void dumpRight(PDBSymDumper &Dumper) const override;

View File

@ -19,12 +19,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolTypeTypedef : public PDBSymbol { class PDBSymbolTypeTypedef : public PDBSymbol {
public:
PDBSymbolTypeTypedef(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Typedef) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Typedef)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getBuiltinType) FORWARD_SYMBOL_METHOD(getBuiltinType)

View File

@ -23,17 +23,13 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolTypeUDT : public PDBSymbol { class PDBSymbolTypeUDT : public PDBSymbol {
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::UDT)
public: public:
PDBSymbolTypeUDT(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> UDTSymbol);
std::unique_ptr<PDBSymbolTypeUDT> clone() const { std::unique_ptr<PDBSymbolTypeUDT> clone() const {
return getSession().getConcreteSymbolById<PDBSymbolTypeUDT>( return getSession().getConcreteSymbolById<PDBSymbolTypeUDT>(
getSymIndexId()); getSymIndexId());
} }
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::UDT)
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_ID_METHOD(getClassParent) FORWARD_SYMBOL_ID_METHOD(getClassParent)

View File

@ -19,12 +19,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolTypeVTable : public PDBSymbol { class PDBSymbolTypeVTable : public PDBSymbol {
public:
PDBSymbolTypeVTable(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> VtblSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::VTable) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::VTable)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_ID_METHOD(getClassParent) FORWARD_SYMBOL_ID_METHOD(getClassParent)

View File

@ -19,12 +19,8 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolTypeVTableShape : public PDBSymbol { class PDBSymbolTypeVTableShape : public PDBSymbol {
public:
PDBSymbolTypeVTableShape(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> VtblShapeSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::VTableShape) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::VTableShape)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(isConstType) FORWARD_SYMBOL_METHOD(isConstType)

View File

@ -18,16 +18,11 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolUnknown : public PDBSymbol { class PDBSymbolUnknown : public PDBSymbol {
DECLARE_PDB_SYMBOL_CUSTOM_TYPE(S->getSymTag() == PDB_SymType::None ||
S->getSymTag() >= PDB_SymType::Max)
public: public:
PDBSymbolUnknown(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> UnknownSymbol);
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
static bool classof(const PDBSymbol *S) {
return (S->getSymTag() == PDB_SymType::None ||
S->getSymTag() >= PDB_SymType::Max);
}
}; };
} // namespace llvm } // namespace llvm

View File

@ -19,12 +19,9 @@ class raw_ostream;
namespace pdb { namespace pdb {
class PDBSymbolUsingNamespace : public PDBSymbol { class PDBSymbolUsingNamespace : public PDBSymbol {
public:
PDBSymbolUsingNamespace(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::UsingNamespace) DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::UsingNamespace)
public:
void dump(PDBSymDumper &Dumper) const override; void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_ID_METHOD(getLexicalParent) FORWARD_SYMBOL_ID_METHOD(getLexicalParent)

View File

@ -852,7 +852,7 @@ DIARawSymbol::getVirtualBaseTableType() const {
auto RawVT = llvm::make_unique<DIARawSymbol>(Session, TableType); auto RawVT = llvm::make_unique<DIARawSymbol>(Session, TableType);
auto Pointer = auto Pointer =
llvm::make_unique<PDBSymbolTypePointer>(Session, std::move(RawVT)); PDBSymbol::createAs<PDBSymbolTypePointer>(Session, std::move(RawVT));
return unique_dyn_cast<PDBSymbolTypeBuiltin>(Pointer->getPointeeType()); return unique_dyn_cast<PDBSymbolTypeBuiltin>(Pointer->getPointeeType());
} }

View File

@ -25,7 +25,7 @@ std::unique_ptr<PDBSymbolCompiland> DIASectionContrib::getCompiland() const {
return nullptr; return nullptr;
auto RawSymbol = llvm::make_unique<DIARawSymbol>(Session, Symbol); auto RawSymbol = llvm::make_unique<DIARawSymbol>(Session, Symbol);
return llvm::make_unique<PDBSymbolCompiland>(Session, std::move(RawSymbol)); return PDBSymbol::createAs<PDBSymbolCompiland>(Session, std::move(RawSymbol));
} }
template <typename ArgType> template <typename ArgType>

View File

@ -16,8 +16,8 @@ namespace pdb {
NativeBuiltinSymbol::NativeBuiltinSymbol(NativeSession &PDBSession, NativeBuiltinSymbol::NativeBuiltinSymbol(NativeSession &PDBSession,
SymIndexId Id, PDB_BuiltinType T, SymIndexId Id, PDB_BuiltinType T,
uint64_t L) 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() {} NativeBuiltinSymbol::~NativeBuiltinSymbol() {}

View File

@ -17,7 +17,7 @@ namespace pdb {
NativeCompilandSymbol::NativeCompilandSymbol(NativeSession &Session, NativeCompilandSymbol::NativeCompilandSymbol(NativeSession &Session,
SymIndexId SymbolId, SymIndexId SymbolId,
DbiModuleDescriptor MI) DbiModuleDescriptor MI)
: NativeRawSymbol(Session, SymbolId), Module(MI) {} : NativeRawSymbol(Session, PDB_SymType::Compiland, SymbolId), Module(MI) {}
PDB_SymType NativeCompilandSymbol::getSymTag() const { PDB_SymType NativeCompilandSymbol::getSymTag() const {
return PDB_SymType::Compiland; return PDB_SymType::Compiland;

View File

@ -10,33 +10,30 @@
#include "llvm/DebugInfo/PDB/Native/NativeEnumModules.h" #include "llvm/DebugInfo/PDB/Native/NativeEnumModules.h"
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.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/NativeCompilandSymbol.h"
#include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h"
#include "llvm/DebugInfo/PDB/Native/NativeSession.h" #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
#include "llvm/DebugInfo/PDB/PDBSymbol.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h"
#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
namespace llvm { namespace llvm {
namespace pdb { namespace pdb {
NativeEnumModules::NativeEnumModules(NativeSession &PDBSession, NativeEnumModules::NativeEnumModules(NativeSession &PDBSession, uint32_t Index)
const DbiModuleList &Modules, : Session(PDBSession), Index(Index) {}
uint32_t Index)
: Session(PDBSession), Modules(Modules), Index(Index) {}
uint32_t NativeEnumModules::getChildCount() const { uint32_t NativeEnumModules::getChildCount() const {
return static_cast<uint32_t>(Modules.getModuleCount()); return Session.getNativeGlobalScope().getNumCompilands();
} }
std::unique_ptr<PDBSymbol> std::unique_ptr<PDBSymbol>
NativeEnumModules::getChildAtIndex(uint32_t Index) const { NativeEnumModules::getChildAtIndex(uint32_t N) const {
if (Index >= Modules.getModuleCount()) return Session.getNativeGlobalScope().getOrCreateCompiland(N);
return nullptr;
return Session.createCompilandSymbol(Modules.getModuleDescriptor(Index));
} }
std::unique_ptr<PDBSymbol> NativeEnumModules::getNext() { std::unique_ptr<PDBSymbol> NativeEnumModules::getNext() {
if (Index >= Modules.getModuleCount()) if (Index >= getChildCount())
return nullptr; return nullptr;
return getChildAtIndex(Index++); return getChildAtIndex(Index++);
} }
@ -44,7 +41,7 @@ std::unique_ptr<PDBSymbol> NativeEnumModules::getNext() {
void NativeEnumModules::reset() { Index = 0; } void NativeEnumModules::reset() { Index = 0; }
NativeEnumModules *NativeEnumModules::clone() const { NativeEnumModules *NativeEnumModules::clone() const {
return new NativeEnumModules(Session, Modules, Index); return new NativeEnumModules(Session, Index);
} }
} }

View File

@ -21,7 +21,7 @@ using namespace llvm::pdb;
NativeEnumSymbol::NativeEnumSymbol(NativeSession &Session, SymIndexId Id, NativeEnumSymbol::NativeEnumSymbol(NativeSession &Session, SymIndexId Id,
const codeview::CVType &CVT) const codeview::CVType &CVT)
: NativeRawSymbol(Session, Id), CV(CVT), : NativeRawSymbol(Session, PDB_SymType::Enum, Id), CV(CVT),
Record(codeview::TypeRecordKind::Enum) { Record(codeview::TypeRecordKind::Enum) {
assert(CV.kind() == codeview::TypeLeafKind::LF_ENUM); assert(CV.kind() == codeview::TypeLeafKind::LF_ENUM);
cantFail(visitTypeRecord(CV, *this)); cantFail(visitTypeRecord(CV, *this));

View File

@ -12,14 +12,25 @@
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/DebugInfo/PDB/Native/DbiStream.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
#include "llvm/DebugInfo/PDB/Native/InfoStream.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/NativeEnumModules.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
namespace llvm { using namespace llvm;
namespace pdb { using namespace llvm::pdb;
NativeExeSymbol::NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId) 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 { std::unique_ptr<NativeRawSymbol> NativeExeSymbol::clone() const {
return llvm::make_unique<NativeExeSymbol>(Session, SymbolId); return llvm::make_unique<NativeExeSymbol>(Session, SymbolId);
@ -29,13 +40,7 @@ std::unique_ptr<IPDBEnumSymbols>
NativeExeSymbol::findChildren(PDB_SymType Type) const { NativeExeSymbol::findChildren(PDB_SymType Type) const {
switch (Type) { switch (Type) {
case PDB_SymType::Compiland: { case PDB_SymType::Compiland: {
auto Dbi = File.getPDBDbiStream(); return std::unique_ptr<IPDBEnumSymbols>(new NativeEnumModules(Session));
if (Dbi) {
const DbiModuleList &Modules = Dbi->modules();
return std::unique_ptr<IPDBEnumSymbols>(
new NativeEnumModules(Session, Modules));
}
consumeError(Dbi.takeError());
break; break;
} }
case PDB_SymType::Enum: case PDB_SymType::Enum:
@ -82,5 +87,26 @@ bool NativeExeSymbol::hasPrivateSymbols() const {
return false; return false;
} }
} // namespace pdb uint32_t NativeExeSymbol::getNumCompilands() const {
} // namespace llvm 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]);
}

View File

@ -14,8 +14,9 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
NativeRawSymbol::NativeRawSymbol(NativeSession &PDBSession, SymIndexId SymbolId) NativeRawSymbol::NativeRawSymbol(NativeSession &PDBSession, PDB_SymType Tag,
: Session(PDBSession), SymbolId(SymbolId) {} SymIndexId SymbolId)
: Session(PDBSession), Tag(Tag), SymbolId(SymbolId) {}
void NativeRawSymbol::dump(raw_ostream &OS, int Indent) const {} void NativeRawSymbol::dump(raw_ostream &OS, int Indent) const {}
@ -374,9 +375,7 @@ PDB_DataKind NativeRawSymbol::getDataKind() const {
return PDB_DataKind::Unknown; return PDB_DataKind::Unknown;
} }
PDB_SymType NativeRawSymbol::getSymTag() const { PDB_SymType NativeRawSymbol::getSymTag() const { return Tag; }
return PDB_SymType::None;
}
codeview::GUID NativeRawSymbol::getGuid() const { return codeview::GUID{{0}}; } codeview::GUID NativeRawSymbol::getGuid() const { return codeview::GUID{{0}}; }

View File

@ -63,7 +63,10 @@ static const struct BuiltinTypeEntry {
NativeSession::NativeSession(std::unique_ptr<PDBFile> PdbFile, NativeSession::NativeSession(std::unique_ptr<PDBFile> PdbFile,
std::unique_ptr<BumpPtrAllocator> Allocator) 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; NativeSession::~NativeSession() = default;
@ -91,20 +94,10 @@ Error NativeSession::createFromExe(StringRef Path,
return make_error<RawError>(raw_error_code::feature_unsupported); 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> std::unique_ptr<PDBSymbolTypeEnum>
NativeSession::createEnumSymbol(codeview::TypeIndex Index) { NativeSession::createEnumSymbol(codeview::TypeIndex Index) {
const auto Id = findSymbolByTypeIndex(Index); const auto Id = findSymbolByTypeIndex(Index);
return llvm::make_unique<PDBSymbolTypeEnum>( return PDBSymbol::createAs<PDBSymbolTypeEnum>(*this, *SymbolCache[Id]);
*this, std::unique_ptr<IPDBRawSymbol>(SymbolCache[Id]->clone()));
} }
std::unique_ptr<IPDBEnumSymbols> std::unique_ptr<IPDBEnumSymbols>
@ -167,20 +160,14 @@ uint64_t NativeSession::getLoadAddress() const { return 0; }
bool NativeSession::setLoadAddress(uint64_t Address) { return false; } bool NativeSession::setLoadAddress(uint64_t Address) { return false; }
std::unique_ptr<PDBSymbolExe> NativeSession::getGlobalScope() { std::unique_ptr<PDBSymbolExe> NativeSession::getGlobalScope() {
const auto Id = static_cast<SymIndexId>(SymbolCache.size()); return PDBSymbol::createAs<PDBSymbolExe>(*this, getNativeGlobalScope());
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;
} }
std::unique_ptr<PDBSymbol> std::unique_ptr<PDBSymbol>
NativeSession::getSymbolById(uint32_t SymbolId) const { NativeSession::getSymbolById(uint32_t SymbolId) const {
// If the caller has a SymbolId, it'd better be in our SymbolCache. // If the caller has a SymbolId, it'd better be in our SymbolCache.
return SymbolId < SymbolCache.size() return SymbolId < SymbolCache.size()
? PDBSymbol::create(*this, SymbolCache[SymbolId]->clone()) ? PDBSymbol::create(*this, *SymbolCache[SymbolId])
: nullptr; : nullptr;
} }
@ -290,3 +277,11 @@ std::unique_ptr<IPDBEnumSectionContribs>
NativeSession::getSectionContribs() const { NativeSession::getSectionContribs() const {
return nullptr; 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]);
}

View File

@ -50,23 +50,20 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbol::PDBSymbol(const IPDBSession &PDBSession, PDBSymbol::PDBSymbol(const IPDBSession &PDBSession) : Session(PDBSession) {}
std::unique_ptr<IPDBRawSymbol> Symbol)
: Session(PDBSession), RawSymbol(std::move(Symbol)) {}
PDBSymbol::PDBSymbol(PDBSymbol &Symbol) PDBSymbol::PDBSymbol(PDBSymbol &&Other)
: Session(Symbol.Session), RawSymbol(std::move(Symbol.RawSymbol)) {} : Session(Other.Session), RawSymbol(std::move(Other.RawSymbol)) {}
PDBSymbol::~PDBSymbol() = default; PDBSymbol::~PDBSymbol() = default;
#define FACTORY_SYMTAG_CASE(Tag, Type) \ #define FACTORY_SYMTAG_CASE(Tag, Type) \
case PDB_SymType::Tag: \ case PDB_SymType::Tag: \
return std::unique_ptr<PDBSymbol>(new Type(PDBSession, std::move(Symbol))); return std::unique_ptr<PDBSymbol>(new Type(PDBSession));
std::unique_ptr<PDBSymbol> std::unique_ptr<PDBSymbol>
PDBSymbol::create(const IPDBSession &PDBSession, PDBSymbol::createSymbol(const IPDBSession &PDBSession, PDB_SymType Tag) {
std::unique_ptr<IPDBRawSymbol> Symbol) { switch (Tag) {
switch (Symbol->getSymTag()) {
FACTORY_SYMTAG_CASE(Exe, PDBSymbolExe) FACTORY_SYMTAG_CASE(Exe, PDBSymbolExe)
FACTORY_SYMTAG_CASE(Compiland, PDBSymbolCompiland) FACTORY_SYMTAG_CASE(Compiland, PDBSymbolCompiland)
FACTORY_SYMTAG_CASE(CompilandDetails, PDBSymbolCompilandDetails) FACTORY_SYMTAG_CASE(CompilandDetails, PDBSymbolCompilandDetails)
@ -98,11 +95,26 @@ PDBSymbol::create(const IPDBSession &PDBSession,
FACTORY_SYMTAG_CASE(ManagedType, PDBSymbolTypeManaged) FACTORY_SYMTAG_CASE(ManagedType, PDBSymbolTypeManaged)
FACTORY_SYMTAG_CASE(Dimension, PDBSymbolTypeDimension) FACTORY_SYMTAG_CASE(Dimension, PDBSymbolTypeDimension)
default: default:
return std::unique_ptr<PDBSymbol>( return std::unique_ptr<PDBSymbol>(new PDBSymbolUnknown(PDBSession));
new PDBSymbolUnknown(PDBSession, std::move(Symbol)));
} }
} }
std::unique_ptr<PDBSymbol>
PDBSymbol::create(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> RawSymbol) {
auto SymbolPtr = createSymbol(PDBSession, RawSymbol->getSymTag());
SymbolPtr->RawSymbol = RawSymbol.get();
SymbolPtr->OwnedRawSymbol = std::move(RawSymbol);
return std::move(SymbolPtr);
}
std::unique_ptr<PDBSymbol> PDBSymbol::create(const IPDBSession &PDBSession,
IPDBRawSymbol &RawSymbol) {
auto SymbolPtr = createSymbol(PDBSession, RawSymbol.getSymTag());
SymbolPtr->RawSymbol = &RawSymbol;
return std::move(SymbolPtr);
}
void PDBSymbol::defaultDump(raw_ostream &OS, int Indent) const { void PDBSymbol::defaultDump(raw_ostream &OS, int Indent) const {
RawSymbol->dump(OS, Indent); RawSymbol->dump(OS, Indent);
} }

View File

@ -16,12 +16,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolAnnotation::PDBSymbolAnnotation(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::Annotation);
}
void PDBSymbolAnnotation::dump(PDBSymDumper &Dumper) const { void PDBSymbolAnnotation::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -17,10 +17,4 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolBlock::PDBSymbolBlock(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::Block);
}
void PDBSymbolBlock::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); } void PDBSymbolBlock::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }

View File

@ -22,12 +22,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolCompiland::PDBSymbolCompiland(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::Compiland);
}
void PDBSymbolCompiland::dump(PDBSymDumper &Dumper) const { void PDBSymbolCompiland::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -17,12 +17,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolCompilandDetails::PDBSymbolCompilandDetails(
const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::CompilandDetails);
}
void PDBSymbolCompilandDetails::dump(PDBSymDumper &Dumper) const { void PDBSymbolCompilandDetails::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -18,12 +18,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolCompilandEnv::PDBSymbolCompilandEnv(
const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::CompilandEnv);
}
std::string PDBSymbolCompilandEnv::getValue() const { std::string PDBSymbolCompilandEnv::getValue() const {
Variant Value = RawSymbol->getValue(); Variant Value = RawSymbol->getValue();
if (Value.Type != PDB_VariantType::String) if (Value.Type != PDB_VariantType::String)

View File

@ -18,12 +18,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolCustom::PDBSymbolCustom(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> CustomSymbol)
: PDBSymbol(PDBSession, std::move(CustomSymbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::Custom);
}
void PDBSymbolCustom::getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes) { void PDBSymbolCustom::getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes) {
RawSymbol->getDataBytes(bytes); RawSymbol->getDataBytes(bytes);
} }

View File

@ -17,12 +17,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolData::PDBSymbolData(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> DataSymbol)
: PDBSymbol(PDBSession, std::move(DataSymbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::Data);
}
void PDBSymbolData::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); } void PDBSymbolData::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
std::unique_ptr<IPDBEnumLineNumbers> PDBSymbolData::getLineNumbers() const { std::unique_ptr<IPDBEnumLineNumbers> PDBSymbolData::getLineNumbers() const {

View File

@ -17,12 +17,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolExe::PDBSymbolExe(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::Exe);
}
void PDBSymbolExe::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); } void PDBSymbolExe::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
uint32_t PDBSymbolExe::getPointerByteSize() const { uint32_t PDBSymbolExe::getPointerByteSize() const {

View File

@ -82,12 +82,6 @@ private:
}; };
} }
PDBSymbolFunc::PDBSymbolFunc(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::Function);
}
std::unique_ptr<IPDBEnumChildren<PDBSymbolData>> std::unique_ptr<IPDBEnumChildren<PDBSymbolData>>
PDBSymbolFunc::getArguments() const { PDBSymbolFunc::getArguments() const {
return llvm::make_unique<FunctionArgEnumerator>(Session, *this); return llvm::make_unique<FunctionArgEnumerator>(Session, *this);

View File

@ -17,12 +17,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolFuncDebugEnd::PDBSymbolFuncDebugEnd(
const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::FuncDebugEnd);
}
void PDBSymbolFuncDebugEnd::dump(PDBSymDumper &Dumper) const { void PDBSymbolFuncDebugEnd::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -17,12 +17,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolFuncDebugStart::PDBSymbolFuncDebugStart(
const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::FuncDebugStart);
}
void PDBSymbolFuncDebugStart::dump(PDBSymDumper &Dumper) const { void PDBSymbolFuncDebugStart::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -16,10 +16,4 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolLabel::PDBSymbolLabel(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::Label);
}
void PDBSymbolLabel::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); } void PDBSymbolLabel::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }

View File

@ -17,12 +17,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolPublicSymbol::PDBSymbolPublicSymbol(
const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::PublicSymbol);
}
void PDBSymbolPublicSymbol::dump(PDBSymDumper &Dumper) const { void PDBSymbolPublicSymbol::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -16,10 +16,4 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolThunk::PDBSymbolThunk(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::Thunk);
}
void PDBSymbolThunk::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); } void PDBSymbolThunk::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }

View File

@ -16,12 +16,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolTypeArray::PDBSymbolTypeArray(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::ArrayType);
}
void PDBSymbolTypeArray::dump(PDBSymDumper &Dumper) const { void PDBSymbolTypeArray::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -17,12 +17,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolTypeBaseClass::PDBSymbolTypeBaseClass(
const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::BaseClass);
}
void PDBSymbolTypeBaseClass::dump(PDBSymDumper &Dumper) const { void PDBSymbolTypeBaseClass::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -16,12 +16,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolTypeBuiltin::PDBSymbolTypeBuiltin(
const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::BuiltinType);
}
void PDBSymbolTypeBuiltin::dump(PDBSymDumper &Dumper) const { void PDBSymbolTypeBuiltin::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -17,12 +17,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolTypeCustom::PDBSymbolTypeCustom(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::CustomType);
}
void PDBSymbolTypeCustom::dump(PDBSymDumper &Dumper) const { void PDBSymbolTypeCustom::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -17,13 +17,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolTypeDimension::PDBSymbolTypeDimension(
const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::Dimension);
}
void PDBSymbolTypeDimension::dump(PDBSymDumper &Dumper) const { void PDBSymbolTypeDimension::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -17,10 +17,4 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolTypeEnum::PDBSymbolTypeEnum(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::Enum);
}
void PDBSymbolTypeEnum::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); } void PDBSymbolTypeEnum::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }

View File

@ -17,12 +17,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolTypeFriend::PDBSymbolTypeFriend(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::Friend);
}
void PDBSymbolTypeFriend::dump(PDBSymDumper &Dumper) const { void PDBSymbolTypeFriend::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -16,12 +16,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolTypeFunctionArg::PDBSymbolTypeFunctionArg(
const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::FunctionArg);
}
void PDBSymbolTypeFunctionArg::dump(PDBSymDumper &Dumper) const { void PDBSymbolTypeFunctionArg::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -67,12 +67,6 @@ private:
}; };
} }
PDBSymbolTypeFunctionSig::PDBSymbolTypeFunctionSig(
const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::FunctionSig);
}
std::unique_ptr<IPDBEnumSymbols> std::unique_ptr<IPDBEnumSymbols>
PDBSymbolTypeFunctionSig::getArguments() const { PDBSymbolTypeFunctionSig::getArguments() const {
return llvm::make_unique<FunctionArgEnumerator>(Session, *this); return llvm::make_unique<FunctionArgEnumerator>(Session, *this);

View File

@ -17,12 +17,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolTypeManaged::PDBSymbolTypeManaged(
const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::ManagedType);
}
void PDBSymbolTypeManaged::dump(PDBSymDumper &Dumper) const { void PDBSymbolTypeManaged::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -17,12 +17,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolTypePointer::PDBSymbolTypePointer(
const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::PointerType);
}
void PDBSymbolTypePointer::dump(PDBSymDumper &Dumper) const { void PDBSymbolTypePointer::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -16,12 +16,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolTypeTypedef::PDBSymbolTypeTypedef(
const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::Typedef);
}
void PDBSymbolTypeTypedef::dump(PDBSymDumper &Dumper) const { void PDBSymbolTypeTypedef::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -23,10 +23,4 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolTypeUDT::PDBSymbolTypeUDT(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::UDT);
}
void PDBSymbolTypeUDT::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); } void PDBSymbolTypeUDT::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }

View File

@ -16,12 +16,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolTypeVTable::PDBSymbolTypeVTable(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::VTable);
}
void PDBSymbolTypeVTable::dump(PDBSymDumper &Dumper) const { void PDBSymbolTypeVTable::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -17,12 +17,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolTypeVTableShape::PDBSymbolTypeVTableShape(
const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::VTableShape);
}
void PDBSymbolTypeVTableShape::dump(PDBSymDumper &Dumper) const { void PDBSymbolTypeVTableShape::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -17,8 +17,4 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolUnknown::PDBSymbolUnknown(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {}
void PDBSymbolUnknown::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); } void PDBSymbolUnknown::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }

View File

@ -17,12 +17,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::pdb; using namespace llvm::pdb;
PDBSymbolUsingNamespace::PDBSymbolUsingNamespace(
const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
: PDBSymbol(PDBSession, std::move(Symbol)) {
assert(RawSymbol->getSymTag() == PDB_SymType::UsingNamespace);
}
void PDBSymbolUsingNamespace::dump(PDBSymDumper &Dumper) const { void PDBSymbolUsingNamespace::dump(PDBSymDumper &Dumper) const {
Dumper.dump(*this); Dumper.dump(*this);
} }

View File

@ -1054,7 +1054,9 @@ static void dumpPretty(StringRef Path) {
Printer.NewLine(); Printer.NewLine();
WithColor(Printer, PDB_ColorItem::SectionHeader).get() WithColor(Printer, PDB_ColorItem::SectionHeader).get()
<< "---COMPILANDS---"; << "---COMPILANDS---";
if (auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>()) { auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
if (Compilands) {
Printer.Indent(); Printer.Indent();
CompilandDumper Dumper(Printer); CompilandDumper Dumper(Printer);
CompilandDumpFlags options = CompilandDumper::Flags::None; CompilandDumpFlags options = CompilandDumper::Flags::None;

View File

@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS
add_llvm_unittest(DebugInfoPDBTests add_llvm_unittest(DebugInfoPDBTests
HashTableTest.cpp HashTableTest.cpp
NativeSymbolReuseTest.cpp
StringTableBuilderTest.cpp StringTableBuilderTest.cpp
PDBApiTest.cpp PDBApiTest.cpp
) )

Binary file not shown.

View File

@ -0,0 +1,128 @@
//===- NativeSymbolReuseTest.cpp ------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/DebugInfo/PDB/PDB.h"
#include "llvm/DebugInfo/PDB/IPDBSession.h"
#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
#include "llvm/Support/Path.h"
#include "llvm/Testing/Support/Error.h"
#include "llvm/Testing/Support/SupportHelpers.h"
#include "gtest/gtest.h"
using namespace llvm;
using namespace llvm::pdb;
TEST(NativeSymbolReuseTest, GlobalSymbolReuse) {
SmallString<128> InputsDir = unittest::getInputFileDirectory();
llvm::sys::path::append(InputsDir, "empty.pdb");
std::unique_ptr<IPDBSession> S;
Error E = pdb::loadDataForPDB(PDB_ReaderType::Native, InputsDir, S);
ASSERT_THAT_ERROR(std::move(E), Succeeded());
SymIndexId GlobalId;
{
auto GS1 = S->getGlobalScope();
auto GS2 = S->getGlobalScope();
GlobalId = GS1->getSymIndexId();
SymIndexId Id2 = GS1->getSymIndexId();
EXPECT_EQ(GlobalId, Id2);
}
{
auto GS3 = S->getGlobalScope();
SymIndexId Id3 = GS3->getSymIndexId();
EXPECT_EQ(GlobalId, Id3);
}
}
TEST(NativeSymbolReuseTest, CompilandSymbolReuse) {
SmallString<128> InputsDir = unittest::getInputFileDirectory();
llvm::sys::path::append(InputsDir, "empty.pdb");
std::unique_ptr<IPDBSession> S;
Error E = pdb::loadDataForPDB(PDB_ReaderType::Native, InputsDir, S);
ASSERT_THAT_ERROR(std::move(E), Succeeded());
auto GS = S->getGlobalScope();
std::vector<SymIndexId> CompilandIds;
{
auto Compilands = GS->findAllChildren<PDBSymbolCompiland>();
ASSERT_NE(nullptr, Compilands);
ASSERT_EQ(2, Compilands->getChildCount());
std::vector<SymIndexId> Ids2;
// First try resetting the enumerator, then try destroying the enumerator
// and constructing another one.
while (auto Compiland = Compilands->getNext())
CompilandIds.push_back(Compiland->getSymIndexId());
Compilands->reset();
while (auto Compiland = Compilands->getNext())
Ids2.push_back(Compiland->getSymIndexId());
EXPECT_EQ(CompilandIds, Ids2);
}
{
auto Compilands = GS->findAllChildren<PDBSymbolCompiland>();
ASSERT_NE(nullptr, Compilands);
ASSERT_EQ(2U, Compilands->getChildCount());
std::vector<SymIndexId> Ids3;
while (auto Compiland = Compilands->getNext())
Ids3.push_back(Compiland->getSymIndexId());
EXPECT_EQ(CompilandIds, Ids3);
}
}
TEST(NativeSymbolReuseTest, CompilandSymbolReuseBackwards) {
SmallString<128> InputsDir = unittest::getInputFileDirectory();
llvm::sys::path::append(InputsDir, "empty.pdb");
std::unique_ptr<IPDBSession> S;
Error E = pdb::loadDataForPDB(PDB_ReaderType::Native, InputsDir, S);
ASSERT_THAT_ERROR(std::move(E), Succeeded());
auto GS = S->getGlobalScope();
// This time do the first iteration backwards, and make sure that when you
// then iterate them forwards, the IDs come out in reverse.
std::vector<SymIndexId> CompilandIds;
{
auto Compilands = GS->findAllChildren<PDBSymbolCompiland>();
ASSERT_NE(nullptr, Compilands);
ASSERT_EQ(2U, Compilands->getChildCount());
std::vector<SymIndexId> Ids2;
for (int I = Compilands->getChildCount() - 1; I >= 0; --I) {
auto Compiland = Compilands->getChildAtIndex(I);
CompilandIds.push_back(Compiland->getSymIndexId());
}
while (auto Compiland = Compilands->getNext())
Ids2.push_back(Compiland->getSymIndexId());
auto ReversedIter = llvm::reverse(Ids2);
std::vector<SymIndexId> Reversed{ReversedIter.begin(), ReversedIter.end()};
EXPECT_EQ(CompilandIds, Reversed);
}
}