#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVEENUMMODULES_H
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
-#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
#include "llvm/DebugInfo/PDB/PDBSymbol.h"
namespace llvm {
namespace pdb {
-class DbiModuleList;
class NativeSession;
class NativeEnumModules : public IPDBEnumChildren<PDBSymbol> {
public:
- NativeEnumModules(NativeSession &Session, const DbiModuleList &Modules,
- uint32_t Index = 0);
+ NativeEnumModules(NativeSession &Session, uint32_t Index = 0);
uint32_t getChildCount() const override;
std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const override;
private:
NativeSession &Session;
- const DbiModuleList &Modules;
uint32_t Index;
};
}
namespace llvm {
namespace pdb {
+class DbiStream;
+
class NativeExeSymbol : public NativeRawSymbol {
public:
NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId);
bool hasCTypes() const override;
bool hasPrivateSymbols() const override;
+ std::unique_ptr<PDBSymbolCompiland> getOrCreateCompiland(uint32_t Index);
+ uint32_t getNumCompilands() const;
+
private:
PDBFile &File;
+
+ DbiStream *Dbi = nullptr;
+
+ // EXE symbol is the authority on the various symbol types.
+ mutable std::vector<SymIndexId> Compilands;
};
} // namespace pdb
class NativeRawSymbol : public IPDBRawSymbol {
public:
- NativeRawSymbol(NativeSession &PDBSession, SymIndexId SymbolId);
+ NativeRawSymbol(NativeSession &PDBSession, PDB_SymType Tag,
+ SymIndexId SymbolId);
virtual std::unique_ptr<NativeRawSymbol> clone() const = 0;
protected:
NativeSession &Session;
+ PDB_SymType Tag;
SymIndexId SymbolId;
};
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
#include "llvm/DebugInfo/PDB/IPDBRawSymbol.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/NativeRawSymbol.h"
#include "llvm/Support/Allocator.h"
class MemoryBuffer;
namespace pdb {
class PDBFile;
+class NativeExeSymbol;
class NativeSession : public IPDBSession {
public:
static Error createFromExe(StringRef Path,
std::unique_ptr<IPDBSession> &Session);
- std::unique_ptr<PDBSymbolCompiland>
- createCompilandSymbol(DbiModuleDescriptor MI);
+ template <typename ConcreteSymbolT, typename... Args>
+ 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>
createEnumSymbol(codeview::TypeIndex Index);
PDBFile &getPDBFile() { return *Pdb; }
const PDBFile &getPDBFile() const { return *Pdb; }
+ NativeExeSymbol &getNativeGlobalScope();
+
private:
+ SymIndexId ExeSymbol = 0;
+
std::unique_ptr<PDBFile> Pdb;
std::unique_ptr<BumpPtrAllocator> Allocator;
std::vector<std::unique_ptr<NativeRawSymbol>> SymbolCache;
class IPDBSession;
#define DECLARE_PDB_SYMBOL_CONCRETE_TYPE(TagValue) \
+private: \
+ using PDBSymbol::PDBSymbol; \
+ friend class PDBSymbol; \
+ \
+public: \
static const PDB_SymType Tag = TagValue; \
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
/// types (e.g. functions, executables, vtables, etc). All concrete symbol
/// types inherit from PDBSymbol and expose the exact set of methods that are
/// reference "Lexical and Class Hierarchy of Symbol Types":
/// https://msdn.microsoft.com/en-us/library/370hs6k4.aspx
class PDBSymbol {
+ static std::unique_ptr<PDBSymbol> createSymbol(const IPDBSession &PDBSession,
+ PDB_SymType Tag);
+
protected:
- PDBSymbol(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> Symbol);
- PDBSymbol(PDBSymbol &Symbol);
+ explicit PDBSymbol(const IPDBSession &PDBSession);
+ PDBSymbol(PDBSymbol &&Other);
public:
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();
}
const IPDBSession &Session;
- std::unique_ptr<IPDBRawSymbol> RawSymbol;
+ std::unique_ptr<IPDBRawSymbol> OwnedRawSymbol;
+ IPDBRawSymbol *RawSymbol = nullptr;
};
} // namespace llvm
namespace pdb {
class PDBSymbolAnnotation : public PDBSymbol {
-public:
- PDBSymbolAnnotation(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> Symbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Annotation)
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAddressOffset)
namespace pdb {
class PDBSymbolBlock : public PDBSymbol {
-public:
- PDBSymbolBlock(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> Symbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Block)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAddressOffset)
namespace pdb {
class PDBSymbolCompiland : public PDBSymbol {
-public:
- PDBSymbolCompiland(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> CompilandSymbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Compiland)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(isEditAndContinueEnabled)
namespace pdb {
class PDBSymbolCompilandDetails : public PDBSymbol {
-public:
- PDBSymbolCompilandDetails(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> Symbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CompilandDetails)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
void getFrontEndVersion(VersionInfo &Version) const {
class raw_ostream;
namespace pdb {
class PDBSymbolCompilandEnv : public PDBSymbol {
-public:
- PDBSymbolCompilandEnv(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> Symbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CompilandEnv)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_ID_METHOD(getLexicalParent)
/// fit anywhere else in the lexical hierarchy.
/// https://msdn.microsoft.com/en-us/library/d88sf09h.aspx
class PDBSymbolCustom : public PDBSymbol {
-public:
- PDBSymbolCustom(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> CustomSymbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Custom)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
void getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes);
namespace pdb {
class PDBSymbolData : public PDBSymbol {
-public:
- PDBSymbolData(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> DataSymbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Data)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAccess)
namespace pdb {
class PDBSymbolExe : public PDBSymbol {
-public:
- PDBSymbolExe(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> ExeSymbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Exe)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAge)
namespace pdb {
class PDBSymbolFunc : public PDBSymbol {
+ DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Function)
public:
- PDBSymbolFunc(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> FuncSymbol);
-
void dump(PDBSymDumper &Dumper) const override;
bool isDestructor() const;
std::unique_ptr<IPDBEnumChildren<PDBSymbolData>> getArguments() const;
- DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Function)
-
FORWARD_SYMBOL_METHOD(getAccess)
FORWARD_SYMBOL_METHOD(getAddressOffset)
FORWARD_SYMBOL_METHOD(getAddressSection)
namespace pdb {
class PDBSymbolFuncDebugEnd : public PDBSymbol {
-public:
- PDBSymbolFuncDebugEnd(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> FuncDebugEndSymbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FuncDebugEnd)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAddressOffset)
namespace pdb {
class PDBSymbolFuncDebugStart : public PDBSymbol {
-public:
- PDBSymbolFuncDebugStart(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> FuncDebugStartSymbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FuncDebugStart)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAddressOffset)
namespace pdb {
class PDBSymbolLabel : public PDBSymbol {
-public:
- PDBSymbolLabel(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> LabelSymbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Label)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAddressOffset)
namespace pdb {
class PDBSymbolPublicSymbol : public PDBSymbol {
-public:
- PDBSymbolPublicSymbol(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> PublicSymbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::PublicSymbol)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAddressOffset)
namespace pdb {
class PDBSymbolThunk : public PDBSymbol {
-public:
- PDBSymbolThunk(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> ThunkSymbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Thunk)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAccess)
namespace pdb {
class PDBSymbolTypeArray : public PDBSymbol {
-public:
- PDBSymbolTypeArray(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> ArrayTypeSymbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::ArrayType)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
void dumpRight(PDBSymDumper &Dumper) const override;
namespace pdb {
class PDBSymbolTypeBaseClass : public PDBSymbol {
-public:
- PDBSymbolTypeBaseClass(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> Symbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::BaseClass)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAccess)
namespace pdb {
class PDBSymbolTypeBuiltin : public PDBSymbol {
-public:
- PDBSymbolTypeBuiltin(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> Symbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::BuiltinType)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getBuiltinType)
namespace pdb {
class PDBSymbolTypeCustom : public PDBSymbol {
-public:
- PDBSymbolTypeCustom(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> Symbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CustomType)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getOemId)
namespace pdb {
class PDBSymbolTypeDimension : public PDBSymbol {
-public:
- PDBSymbolTypeDimension(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> Symbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Dimension)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getLowerBoundId)
namespace pdb {
class PDBSymbolTypeEnum : public PDBSymbol {
-public:
- PDBSymbolTypeEnum(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> EnumTypeSymbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Enum)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getBuiltinType)
namespace pdb {
class PDBSymbolTypeFriend : public PDBSymbol {
-public:
- PDBSymbolTypeFriend(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> Symbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Friend)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_ID_METHOD(getClassParent)
namespace pdb {
class PDBSymbolTypeFunctionArg : public PDBSymbol {
-public:
- PDBSymbolTypeFunctionArg(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> Symbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FunctionArg)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_ID_METHOD(getClassParent)
namespace pdb {
class PDBSymbolTypeFunctionSig : public PDBSymbol {
-public:
- PDBSymbolTypeFunctionSig(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> Symbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FunctionSig)
-
+public:
std::unique_ptr<IPDBEnumSymbols> getArguments() const;
void dump(PDBSymDumper &Dumper) const override;
namespace pdb {
class PDBSymbolTypeManaged : public PDBSymbol {
-public:
- PDBSymbolTypeManaged(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> Symbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::ManagedType)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getName)
namespace pdb {
class PDBSymbolTypePointer : public PDBSymbol {
-public:
- PDBSymbolTypePointer(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> Symbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::PointerType)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
void dumpRight(PDBSymDumper &Dumper) const override;
namespace pdb {
class PDBSymbolTypeTypedef : public PDBSymbol {
-public:
- PDBSymbolTypeTypedef(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> Symbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Typedef)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getBuiltinType)
namespace pdb {
class PDBSymbolTypeUDT : public PDBSymbol {
+ DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::UDT)
public:
- PDBSymbolTypeUDT(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> UDTSymbol);
-
std::unique_ptr<PDBSymbolTypeUDT> clone() const {
return getSession().getConcreteSymbolById<PDBSymbolTypeUDT>(
getSymIndexId());
}
- DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::UDT)
-
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_ID_METHOD(getClassParent)
namespace pdb {
class PDBSymbolTypeVTable : public PDBSymbol {
-public:
- PDBSymbolTypeVTable(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> VtblSymbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::VTable)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_ID_METHOD(getClassParent)
namespace pdb {
class PDBSymbolTypeVTableShape : public PDBSymbol {
-public:
- PDBSymbolTypeVTableShape(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> VtblShapeSymbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::VTableShape)
-
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(isConstType)
namespace pdb {
class PDBSymbolUnknown : public PDBSymbol {
-public:
- PDBSymbolUnknown(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> UnknownSymbol);
+ DECLARE_PDB_SYMBOL_CUSTOM_TYPE(S->getSymTag() == PDB_SymType::None ||
+ S->getSymTag() >= PDB_SymType::Max)
+public:
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 pdb {
class PDBSymbolUsingNamespace : public PDBSymbol {
-public:
- PDBSymbolUsingNamespace(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> Symbol);
-
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::UsingNamespace)
+public:
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_ID_METHOD(getLexicalParent)
auto RawVT = llvm::make_unique<DIARawSymbol>(Session, TableType);
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 nullptr;
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>
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() {}
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;
#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++);
}
void NativeEnumModules::reset() { Index = 0; }
NativeEnumModules *NativeEnumModules::clone() const {
- return new NativeEnumModules(Session, Modules, Index);
+ return new NativeEnumModules(Session, Index);
}
}
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));
#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);
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:
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]);
+}
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 {}
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}}; }
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;
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>
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;
}
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]);
+}
using namespace llvm;
using namespace llvm::pdb;
-PDBSymbol::PDBSymbol(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> Symbol)
- : Session(PDBSession), RawSymbol(std::move(Symbol)) {}
+PDBSymbol::PDBSymbol(const IPDBSession &PDBSession) : Session(PDBSession) {}
-PDBSymbol::PDBSymbol(PDBSymbol &Symbol)
- : Session(Symbol.Session), RawSymbol(std::move(Symbol.RawSymbol)) {}
+PDBSymbol::PDBSymbol(PDBSymbol &&Other)
+ : Session(Other.Session), RawSymbol(std::move(Other.RawSymbol)) {}
PDBSymbol::~PDBSymbol() = default;
#define FACTORY_SYMTAG_CASE(Tag, Type) \
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>
-PDBSymbol::create(const IPDBSession &PDBSession,
- std::unique_ptr<IPDBRawSymbol> Symbol) {
- switch (Symbol->getSymTag()) {
+PDBSymbol::createSymbol(const IPDBSession &PDBSession, PDB_SymType Tag) {
+ switch (Tag) {
FACTORY_SYMTAG_CASE(Exe, PDBSymbolExe)
FACTORY_SYMTAG_CASE(Compiland, PDBSymbolCompiland)
FACTORY_SYMTAG_CASE(CompilandDetails, PDBSymbolCompilandDetails)
FACTORY_SYMTAG_CASE(ManagedType, PDBSymbolTypeManaged)
FACTORY_SYMTAG_CASE(Dimension, PDBSymbolTypeDimension)
default:
- return std::unique_ptr<PDBSymbol>(
- new PDBSymbolUnknown(PDBSession, std::move(Symbol)));
+ return std::unique_ptr<PDBSymbol>(new PDBSymbolUnknown(PDBSession));
}
}
+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 {
RawSymbol->dump(OS, Indent);
}
using namespace llvm;
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 {
Dumper.dump(*this);
}
using namespace llvm;
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); }
using namespace llvm;
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 {
Dumper.dump(*this);
}
using namespace llvm;
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 {
Dumper.dump(*this);
}
using namespace llvm;
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 {
Variant Value = RawSymbol->getValue();
if (Value.Type != PDB_VariantType::String)
using namespace llvm;
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) {
RawSymbol->getDataBytes(bytes);
}
using namespace llvm;
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); }
std::unique_ptr<IPDBEnumLineNumbers> PDBSymbolData::getLineNumbers() const {
using namespace llvm;
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); }
uint32_t PDBSymbolExe::getPointerByteSize() const {
};
}
-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>>
PDBSymbolFunc::getArguments() const {
return llvm::make_unique<FunctionArgEnumerator>(Session, *this);
using namespace llvm;
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 {
Dumper.dump(*this);
}
using namespace llvm;
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 {
Dumper.dump(*this);
}
using namespace llvm;
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); }
using namespace llvm;
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 {
Dumper.dump(*this);
}
using namespace llvm;
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); }
using namespace llvm;
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 {
Dumper.dump(*this);
}
using namespace llvm;
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 {
Dumper.dump(*this);
}
using namespace llvm;
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 {
Dumper.dump(*this);
}
using namespace llvm;
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 {
Dumper.dump(*this);
}
using namespace llvm;
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 {
Dumper.dump(*this);
}
using namespace llvm;
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); }
using namespace llvm;
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 {
Dumper.dump(*this);
}
using namespace llvm;
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 {
Dumper.dump(*this);
}
};
}
-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>
PDBSymbolTypeFunctionSig::getArguments() const {
return llvm::make_unique<FunctionArgEnumerator>(Session, *this);
using namespace llvm;
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 {
Dumper.dump(*this);
}
using namespace llvm;
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 {
Dumper.dump(*this);
}
using namespace llvm;
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 {
Dumper.dump(*this);
}
using namespace llvm;
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); }
using namespace llvm;
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 {
Dumper.dump(*this);
}
using namespace llvm;
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 {
Dumper.dump(*this);
}
using namespace llvm;
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); }
using namespace llvm;
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 {
Dumper.dump(*this);
}
Printer.NewLine();
WithColor(Printer, PDB_ColorItem::SectionHeader).get()
<< "---COMPILANDS---";
- if (auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>()) {
+ auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
+
+ if (Compilands) {
Printer.Indent();
CompilandDumper Dumper(Printer);
CompilandDumpFlags options = CompilandDumper::Flags::None;
add_llvm_unittest(DebugInfoPDBTests
HashTableTest.cpp
+ NativeSymbolReuseTest.cpp
StringTableBuilderTest.cpp
PDBApiTest.cpp
)
--- /dev/null
+//===- 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);
+ }
+}