llvm.org GIT mirror llvm / af026c1
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@341503 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 1 year, 13 days ago
81 changed file(s) with 327 addition(s) and 422 deletion(s). Raw diff Collapse all Expand all
1010 #define LLVM_DEBUGINFO_PDB_NATIVE_NATIVEENUMMODULES_H
1111
1212 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
13 #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
1413 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
1514 namespace llvm {
1615 namespace pdb {
1716
18 class DbiModuleList;
1917 class NativeSession;
2018
2119 class NativeEnumModules : public IPDBEnumChildren {
2220 public:
23 NativeEnumModules(NativeSession &Session, const DbiModuleList &Modules,
24 uint32_t Index = 0);
21 NativeEnumModules(NativeSession &Session, uint32_t Index = 0);
2522
2623 uint32_t getChildCount() const override;
2724 std::unique_ptr getChildAtIndex(uint32_t Index) const override;
3128
3229 private:
3330 NativeSession &Session;
34 const DbiModuleList &Modules;
3531 uint32_t Index;
3632 };
3733 }
1515 namespace llvm {
1616 namespace pdb {
1717
18 class DbiStream;
19
1820 class NativeExeSymbol : public NativeRawSymbol {
1921 public:
2022 NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId);
3032 bool hasCTypes() const override;
3133 bool hasPrivateSymbols() const override;
3234
35 std::unique_ptr getOrCreateCompiland(uint32_t Index);
36 uint32_t getNumCompilands() const;
37
3338 private:
3439 PDBFile &File;
40
41 DbiStream *Dbi = nullptr;
42
43 // EXE symbol is the authority on the various symbol types.
44 mutable std::vector Compilands;
3545 };
3646
3747 } // namespace pdb
2222
2323 class NativeRawSymbol : public IPDBRawSymbol {
2424 public:
25 NativeRawSymbol(NativeSession &PDBSession, SymIndexId SymbolId);
25 NativeRawSymbol(NativeSession &PDBSession, PDB_SymType Tag,
26 SymIndexId SymbolId);
2627
2728 virtual std::unique_ptr clone() const = 0;
2829
229230
230231 protected:
231232 NativeSession &Session;
233 PDB_SymType Tag;
232234 SymIndexId SymbolId;
233235 };
234236
1414 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
1515 #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
1616 #include "llvm/DebugInfo/PDB/IPDBSession.h"
17 #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
1817 #include "llvm/DebugInfo/PDB/Native/NativeBuiltinSymbol.h"
1918 #include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h"
2019 #include "llvm/Support/Allocator.h"
2423 class MemoryBuffer;
2524 namespace pdb {
2625 class PDBFile;
26 class NativeExeSymbol;
2727
2828 class NativeSession : public IPDBSession {
2929 public:
3636 static Error createFromExe(StringRef Path,
3737 std::unique_ptr &Session);
3838
39 std::unique_ptr
40 createCompilandSymbol(DbiModuleDescriptor MI);
39 template
40 SymIndexId createSymbol(Args &&... ConstructorArgs) {
41 SymIndexId Id = SymbolCache.size();
42 std::unique_ptr Symbol =
43 llvm::make_unique(
44 *this, Id, std::forward(ConstructorArgs)...);
45 std::unique_ptr NRS = std::move(Symbol);
46 SymbolCache.push_back(std::move(NRS));
47 return Id;
48 }
4149
4250 std::unique_ptr
4351 createEnumSymbol(codeview::TypeIndex Index);
106114 PDBFile &getPDBFile() { return *Pdb; }
107115 const PDBFile &getPDBFile() const { return *Pdb; }
108116
117 NativeExeSymbol &getNativeGlobalScope();
118
109119 private:
120 SymIndexId ExeSymbol = 0;
121
110122 std::unique_ptr Pdb;
111123 std::unique_ptr Allocator;
112124 std::vector> SymbolCache;
4848 class IPDBSession;
4949
5050 #define DECLARE_PDB_SYMBOL_CONCRETE_TYPE(TagValue) \
51 private: \
52 using PDBSymbol::PDBSymbol; \
53 friend class PDBSymbol; \
54 \
55 public: \
5156 static const PDB_SymType Tag = TagValue; \
5257 static bool classof(const PDBSymbol *S) { return S->getSymTag() == Tag; }
58
59 #define DECLARE_PDB_SYMBOL_CUSTOM_TYPE(Condition) \
60 private: \
61 using PDBSymbol::PDBSymbol; \
62 friend class PDBSymbol; \
63 \
64 public: \
65 static bool classof(const PDBSymbol *S) { return Condition; }
5366
5467 /// PDBSymbol defines the base of the inheritance hierarchy for concrete symbol
5568 /// types (e.g. functions, executables, vtables, etc). All concrete symbol
5871 /// reference "Lexical and Class Hierarchy of Symbol Types":
5972 /// https://msdn.microsoft.com/en-us/library/370hs6k4.aspx
6073 class PDBSymbol {
74 static std::unique_ptr createSymbol(const IPDBSession &PDBSession,
75 PDB_SymType Tag);
76
6177 protected:
62 PDBSymbol(const IPDBSession &PDBSession,
63 std::unique_ptr Symbol);
64 PDBSymbol(PDBSymbol &Symbol);
78 explicit PDBSymbol(const IPDBSession &PDBSession);
79 PDBSymbol(PDBSymbol &&Other);
6580
6681 public:
6782 static std::unique_ptr
68 create(const IPDBSession &PDBSession, std::unique_ptr Symbol);
83 create(const IPDBSession &PDBSession,
84 std::unique_ptr RawSymbol);
85 static std::unique_ptr create(const IPDBSession &PDBSession,
86 IPDBRawSymbol &RawSymbol);
87
88 template
89 static std::unique_ptr
90 createAs(const IPDBSession &PDBSession,
91 std::unique_ptr RawSymbol) {
92 std::unique_ptr S = create(PDBSession, std::move(RawSymbol));
93 return unique_dyn_cast_or_null(std::move(S));
94 }
95 template
96 static std::unique_ptr createAs(const IPDBSession &PDBSession,
97 IPDBRawSymbol &RawSymbol) {
98 std::unique_ptr S = create(PDBSession, RawSymbol);
99 return unique_dyn_cast_or_null(std::move(S));
100 }
69101
70102 virtual ~PDBSymbol();
71103
130162 }
131163
132164 const IPDBSession &Session;
133 std::unique_ptr RawSymbol;
165 std::unique_ptr OwnedRawSymbol;
166 IPDBRawSymbol *RawSymbol = nullptr;
134167 };
135168
136169 } // namespace llvm
1717 namespace pdb {
1818
1919 class PDBSymbolAnnotation : public PDBSymbol {
20 public:
21 PDBSymbolAnnotation(const IPDBSession &PDBSession,
22 std::unique_ptr Symbol);
23
2420 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Annotation)
2521
22 public:
2623 void dump(PDBSymDumper &Dumper) const override;
2724
2825 FORWARD_SYMBOL_METHOD(getAddressOffset)
1818 namespace pdb {
1919
2020 class PDBSymbolBlock : public PDBSymbol {
21 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Block)
2122 public:
22 PDBSymbolBlock(const IPDBSession &PDBSession,
23 std::unique_ptr Symbol);
24
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Block)
26
2723 void dump(PDBSymDumper &Dumper) const override;
2824
2925 FORWARD_SYMBOL_METHOD(getAddressOffset)
1919 namespace pdb {
2020
2121 class PDBSymbolCompiland : public PDBSymbol {
22 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Compiland)
2223 public:
23 PDBSymbolCompiland(const IPDBSession &PDBSession,
24 std::unique_ptr CompilandSymbol);
25
26 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Compiland)
27
2824 void dump(PDBSymDumper &Dumper) const override;
2925
3026 FORWARD_SYMBOL_METHOD(isEditAndContinueEnabled)
1818 namespace pdb {
1919
2020 class PDBSymbolCompilandDetails : public PDBSymbol {
21 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CompilandDetails)
2122 public:
22 PDBSymbolCompilandDetails(const IPDBSession &PDBSession,
23 std::unique_ptr Symbol);
24
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CompilandDetails)
26
2723 void dump(PDBSymDumper &Dumper) const override;
2824
2925 void getFrontEndVersion(VersionInfo &Version) const {
1717 class raw_ostream;
1818 namespace pdb {
1919 class PDBSymbolCompilandEnv : public PDBSymbol {
20 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CompilandEnv)
2021 public:
21 PDBSymbolCompilandEnv(const IPDBSession &PDBSession,
22 std::unique_ptr Symbol);
23
24 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CompilandEnv)
25
2622 void dump(PDBSymDumper &Dumper) const override;
2723
2824 FORWARD_SYMBOL_ID_METHOD(getLexicalParent)
2222 /// fit anywhere else in the lexical hierarchy.
2323 /// https://msdn.microsoft.com/en-us/library/d88sf09h.aspx
2424 class PDBSymbolCustom : public PDBSymbol {
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Custom)
2526 public:
26 PDBSymbolCustom(const IPDBSession &PDBSession,
27 std::unique_ptr CustomSymbol);
28
29 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Custom)
30
3127 void dump(PDBSymDumper &Dumper) const override;
3228
3329 void getDataBytes(llvm::SmallVector &bytes);
2020 namespace pdb {
2121
2222 class PDBSymbolData : public PDBSymbol {
23 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Data)
2324 public:
24 PDBSymbolData(const IPDBSession &PDBSession,
25 std::unique_ptr DataSymbol);
26
27 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Data)
28
2925 void dump(PDBSymDumper &Dumper) const override;
3026
3127 FORWARD_SYMBOL_METHOD(getAccess)
1919 namespace pdb {
2020
2121 class PDBSymbolExe : public PDBSymbol {
22 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Exe)
2223 public:
23 PDBSymbolExe(const IPDBSession &PDBSession,
24 std::unique_ptr ExeSymbol);
25
26 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Exe)
27
2824 void dump(PDBSymDumper &Dumper) const override;
2925
3026 FORWARD_SYMBOL_METHOD(getAge)
2121 namespace pdb {
2222
2323 class PDBSymbolFunc : public PDBSymbol {
24 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Function)
2425 public:
25 PDBSymbolFunc(const IPDBSession &PDBSession,
26 std::unique_ptr FuncSymbol);
27
2826 void dump(PDBSymDumper &Dumper) const override;
2927
3028 bool isDestructor() const;
3129
3230 std::unique_ptr> getArguments() const;
33
34 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Function)
3531
3632 FORWARD_SYMBOL_METHOD(getAccess)
3733 FORWARD_SYMBOL_METHOD(getAddressOffset)
1919 namespace pdb {
2020
2121 class PDBSymbolFuncDebugEnd : public PDBSymbol {
22 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FuncDebugEnd)
2223 public:
23 PDBSymbolFuncDebugEnd(const IPDBSession &PDBSession,
24 std::unique_ptr FuncDebugEndSymbol);
25
26 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FuncDebugEnd)
27
2824 void dump(PDBSymDumper &Dumper) const override;
2925
3026 FORWARD_SYMBOL_METHOD(getAddressOffset)
1818 namespace pdb {
1919
2020 class PDBSymbolFuncDebugStart : public PDBSymbol {
21 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FuncDebugStart)
2122 public:
22 PDBSymbolFuncDebugStart(const IPDBSession &PDBSession,
23 std::unique_ptr FuncDebugStartSymbol);
24
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FuncDebugStart)
26
2723 void dump(PDBSymDumper &Dumper) const override;
2824
2925 FORWARD_SYMBOL_METHOD(getAddressOffset)
1818 namespace pdb {
1919
2020 class PDBSymbolLabel : public PDBSymbol {
21 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Label)
2122 public:
22 PDBSymbolLabel(const IPDBSession &PDBSession,
23 std::unique_ptr LabelSymbol);
24
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Label)
26
2723 void dump(PDBSymDumper &Dumper) const override;
2824
2925 FORWARD_SYMBOL_METHOD(getAddressOffset)
1818 namespace pdb {
1919
2020 class PDBSymbolPublicSymbol : public PDBSymbol {
21 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::PublicSymbol)
2122 public:
22 PDBSymbolPublicSymbol(const IPDBSession &PDBSession,
23 std::unique_ptr PublicSymbol);
24
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::PublicSymbol)
26
2723 void dump(PDBSymDumper &Dumper) const override;
2824
2925 FORWARD_SYMBOL_METHOD(getAddressOffset)
1818 namespace pdb {
1919
2020 class PDBSymbolThunk : public PDBSymbol {
21 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Thunk)
2122 public:
22 PDBSymbolThunk(const IPDBSession &PDBSession,
23 std::unique_ptr ThunkSymbol);
24
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Thunk)
26
2723 void dump(PDBSymDumper &Dumper) const override;
2824
2925 FORWARD_SYMBOL_METHOD(getAccess)
1818 namespace pdb {
1919
2020 class PDBSymbolTypeArray : public PDBSymbol {
21 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::ArrayType)
2122 public:
22 PDBSymbolTypeArray(const IPDBSession &PDBSession,
23 std::unique_ptr ArrayTypeSymbol);
24
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::ArrayType)
26
2723 void dump(PDBSymDumper &Dumper) const override;
2824 void dumpRight(PDBSymDumper &Dumper) const override;
2925
2121 namespace pdb {
2222
2323 class PDBSymbolTypeBaseClass : public PDBSymbol {
24 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::BaseClass)
2425 public:
25 PDBSymbolTypeBaseClass(const IPDBSession &PDBSession,
26 std::unique_ptr Symbol);
27
28 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::BaseClass)
29
3026 void dump(PDBSymDumper &Dumper) const override;
3127
3228 FORWARD_SYMBOL_METHOD(getAccess)
1818 namespace pdb {
1919
2020 class PDBSymbolTypeBuiltin : public PDBSymbol {
21 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::BuiltinType)
2122 public:
22 PDBSymbolTypeBuiltin(const IPDBSession &PDBSession,
23 std::unique_ptr Symbol);
24
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::BuiltinType)
26
2723 void dump(PDBSymDumper &Dumper) const override;
2824
2925 FORWARD_SYMBOL_METHOD(getBuiltinType)
1818 namespace pdb {
1919
2020 class PDBSymbolTypeCustom : public PDBSymbol {
21 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CustomType)
2122 public:
22 PDBSymbolTypeCustom(const IPDBSession &PDBSession,
23 std::unique_ptr Symbol);
24
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CustomType)
26
2723 void dump(PDBSymDumper &Dumper) const override;
2824
2925 FORWARD_SYMBOL_METHOD(getOemId)
1818 namespace pdb {
1919
2020 class PDBSymbolTypeDimension : public PDBSymbol {
21 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Dimension)
2122 public:
22 PDBSymbolTypeDimension(const IPDBSession &PDBSession,
23 std::unique_ptr Symbol);
24
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Dimension)
26
2723 void dump(PDBSymDumper &Dumper) const override;
2824
2925 FORWARD_SYMBOL_METHOD(getLowerBoundId)
2020 namespace pdb {
2121
2222 class PDBSymbolTypeEnum : public PDBSymbol {
23 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Enum)
2324 public:
24 PDBSymbolTypeEnum(const IPDBSession &PDBSession,
25 std::unique_ptr EnumTypeSymbol);
26
27 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Enum)
28
2925 void dump(PDBSymDumper &Dumper) const override;
3026
3127 FORWARD_SYMBOL_METHOD(getBuiltinType)
1818 namespace pdb {
1919
2020 class PDBSymbolTypeFriend : public PDBSymbol {
21 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Friend)
2122 public:
22 PDBSymbolTypeFriend(const IPDBSession &PDBSession,
23 std::unique_ptr Symbol);
24
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Friend)
26
2723 void dump(PDBSymDumper &Dumper) const override;
2824
2925 FORWARD_SYMBOL_ID_METHOD(getClassParent)
1818 namespace pdb {
1919
2020 class PDBSymbolTypeFunctionArg : public PDBSymbol {
21 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FunctionArg)
2122 public:
22 PDBSymbolTypeFunctionArg(const IPDBSession &PDBSession,
23 std::unique_ptr Symbol);
24
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FunctionArg)
26
2723 void dump(PDBSymDumper &Dumper) const override;
2824
2925 FORWARD_SYMBOL_ID_METHOD(getClassParent)
1818 namespace pdb {
1919
2020 class PDBSymbolTypeFunctionSig : public PDBSymbol {
21 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FunctionSig)
2122 public:
22 PDBSymbolTypeFunctionSig(const IPDBSession &PDBSession,
23 std::unique_ptr Symbol);
24
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FunctionSig)
26
2723 std::unique_ptr getArguments() const;
2824
2925 void dump(PDBSymDumper &Dumper) const override;
1818 namespace pdb {
1919
2020 class PDBSymbolTypeManaged : public PDBSymbol {
21 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::ManagedType)
2122 public:
22 PDBSymbolTypeManaged(const IPDBSession &PDBSession,
23 std::unique_ptr Symbol);
24
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::ManagedType)
26
2723 void dump(PDBSymDumper &Dumper) const override;
2824
2925 FORWARD_SYMBOL_METHOD(getName)
1818 namespace pdb {
1919
2020 class PDBSymbolTypePointer : public PDBSymbol {
21 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::PointerType)
2122 public:
22 PDBSymbolTypePointer(const IPDBSession &PDBSession,
23 std::unique_ptr Symbol);
24
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::PointerType)
26
2723 void dump(PDBSymDumper &Dumper) const override;
2824 void dumpRight(PDBSymDumper &Dumper) const override;
2925
1818 namespace pdb {
1919
2020 class PDBSymbolTypeTypedef : public PDBSymbol {
21 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Typedef)
2122 public:
22 PDBSymbolTypeTypedef(const IPDBSession &PDBSession,
23 std::unique_ptr Symbol);
24
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Typedef)
26
2723 void dump(PDBSymDumper &Dumper) const override;
2824
2925 FORWARD_SYMBOL_METHOD(getBuiltinType)
2222 namespace pdb {
2323
2424 class PDBSymbolTypeUDT : public PDBSymbol {
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::UDT)
2526 public:
26 PDBSymbolTypeUDT(const IPDBSession &PDBSession,
27 std::unique_ptr UDTSymbol);
28
2927 std::unique_ptr clone() const {
3028 return getSession().getConcreteSymbolById(
3129 getSymIndexId());
3230 }
33
34 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::UDT)
3531
3632 void dump(PDBSymDumper &Dumper) const override;
3733
1818 namespace pdb {
1919
2020 class PDBSymbolTypeVTable : public PDBSymbol {
21 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::VTable)
2122 public:
22 PDBSymbolTypeVTable(const IPDBSession &PDBSession,
23 std::unique_ptr VtblSymbol);
24
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::VTable)
26
2723 void dump(PDBSymDumper &Dumper) const override;
2824
2925 FORWARD_SYMBOL_ID_METHOD(getClassParent)
1818 namespace pdb {
1919
2020 class PDBSymbolTypeVTableShape : public PDBSymbol {
21 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::VTableShape)
2122 public:
22 PDBSymbolTypeVTableShape(const IPDBSession &PDBSession,
23 std::unique_ptr VtblShapeSymbol);
24
25 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::VTableShape)
26
2723 void dump(PDBSymDumper &Dumper) const override;
2824
2925 FORWARD_SYMBOL_METHOD(isConstType)
1717 namespace pdb {
1818
1919 class PDBSymbolUnknown : public PDBSymbol {
20 DECLARE_PDB_SYMBOL_CUSTOM_TYPE(S->getSymTag() == PDB_SymType::None ||
21 S->getSymTag() >= PDB_SymType::Max)
22
2023 public:
21 PDBSymbolUnknown(const IPDBSession &PDBSession,
22 std::unique_ptr UnknownSymbol);
23
2424 void dump(PDBSymDumper &Dumper) const override;
25
26 static bool classof(const PDBSymbol *S) {
27 return (S->getSymTag() == PDB_SymType::None ||
28 S->getSymTag() >= PDB_SymType::Max);
29 }
3025 };
3126
3227 } // namespace llvm
1818 namespace pdb {
1919
2020 class PDBSymbolUsingNamespace : public PDBSymbol {
21 public:
22 PDBSymbolUsingNamespace(const IPDBSession &PDBSession,
23 std::unique_ptr Symbol);
24
2521 DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::UsingNamespace)
2622
23 public:
2724 void dump(PDBSymDumper &Dumper) const override;
2825
2926 FORWARD_SYMBOL_ID_METHOD(getLexicalParent)
851851
852852 auto RawVT = llvm::make_unique(Session, TableType);
853853 auto Pointer =
854 llvm::make_unique(Session, std::move(RawVT));
854 PDBSymbol::createAs(Session, std::move(RawVT));
855855 return unique_dyn_cast(Pointer->getPointeeType());
856856 }
857857
2424 return nullptr;
2525
2626 auto RawSymbol = llvm::make_unique(Session, Symbol);
27 return llvm::make_unique(Session, std::move(RawSymbol));
27 return PDBSymbol::createAs(Session, std::move(RawSymbol));
2828 }
2929
3030 template
1515 NativeBuiltinSymbol::NativeBuiltinSymbol(NativeSession &PDBSession,
1616 SymIndexId Id, PDB_BuiltinType T,
1717 uint64_t L)
18 : NativeRawSymbol(PDBSession, Id), Session(PDBSession), Type(T), Length(L) {
19 }
18 : NativeRawSymbol(PDBSession, PDB_SymType::BuiltinType, Id),
19 Session(PDBSession), Type(T), Length(L) {}
2020
2121 NativeBuiltinSymbol::~NativeBuiltinSymbol() {}
2222
1616 NativeCompilandSymbol::NativeCompilandSymbol(NativeSession &Session,
1717 SymIndexId SymbolId,
1818 DbiModuleDescriptor MI)
19 : NativeRawSymbol(Session, SymbolId), Module(MI) {}
19 : NativeRawSymbol(Session, PDB_SymType::Compiland, SymbolId), Module(MI) {}
2020
2121 PDB_SymType NativeCompilandSymbol::getSymTag() const {
2222 return PDB_SymType::Compiland;
99 #include "llvm/DebugInfo/PDB/Native/NativeEnumModules.h"
1010
1111 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
12 #include "llvm/DebugInfo/PDB/Native/DbiModuleList.h"
1312 #include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h"
13 #include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h"
1414 #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
1515 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
1616 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
1718
1819 namespace llvm {
1920 namespace pdb {
2021
21 NativeEnumModules::NativeEnumModules(NativeSession &PDBSession,
22 const DbiModuleList &Modules,
23 uint32_t Index)
24 : Session(PDBSession), Modules(Modules), Index(Index) {}
22 NativeEnumModules::NativeEnumModules(NativeSession &PDBSession, uint32_t Index)
23 : Session(PDBSession), Index(Index) {}
2524
2625 uint32_t NativeEnumModules::getChildCount() const {
27 return static_cast(Modules.getModuleCount());
26 return Session.getNativeGlobalScope().getNumCompilands();
2827 }
2928
3029 std::unique_ptr
31 NativeEnumModules::getChildAtIndex(uint32_t Index) const {
32 if (Index >= Modules.getModuleCount())
33 return nullptr;
34 return Session.createCompilandSymbol(Modules.getModuleDescriptor(Index));
30 NativeEnumModules::getChildAtIndex(uint32_t N) const {
31 return Session.getNativeGlobalScope().getOrCreateCompiland(N);
3532 }
3633
3734 std::unique_ptr NativeEnumModules::getNext() {
38 if (Index >= Modules.getModuleCount())
35 if (Index >= getChildCount())
3936 return nullptr;
4037 return getChildAtIndex(Index++);
4138 }
4340 void NativeEnumModules::reset() { Index = 0; }
4441
4542 NativeEnumModules *NativeEnumModules::clone() const {
46 return new NativeEnumModules(Session, Modules, Index);
43 return new NativeEnumModules(Session, Index);
4744 }
4845
4946 }
2020
2121 NativeEnumSymbol::NativeEnumSymbol(NativeSession &Session, SymIndexId Id,
2222 const codeview::CVType &CVT)
23 : NativeRawSymbol(Session, Id), CV(CVT),
23 : NativeRawSymbol(Session, PDB_SymType::Enum, Id), CV(CVT),
2424 Record(codeview::TypeRecordKind::Enum) {
2525 assert(CV.kind() == codeview::TypeLeafKind::LF_ENUM);
2626 cantFail(visitTypeRecord(CV, *this));
1111 #include "llvm/ADT/STLExtras.h"
1212 #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
1313 #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
14 #include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h"
1415 #include "llvm/DebugInfo/PDB/Native/NativeEnumModules.h"
1516 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
1618
17 namespace llvm {
18 namespace pdb {
19 using namespace llvm;
20 using namespace llvm::pdb;
1921
2022 NativeExeSymbol::NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId)
21 : NativeRawSymbol(Session, SymbolId), File(Session.getPDBFile()) {}
23 : NativeRawSymbol(Session, PDB_SymType::Exe, SymbolId),
24 File(Session.getPDBFile()) {
25 Expected DbiS = File.getPDBDbiStream();
26 if (!DbiS) {
27 consumeError(DbiS.takeError());
28 return;
29 }
30 Dbi = &DbiS.get();
31 Compilands.resize(Dbi->modules().getModuleCount());
32 }
2233
2334 std::unique_ptr NativeExeSymbol::clone() const {
2435 return llvm::make_unique(Session, SymbolId);
2839 NativeExeSymbol::findChildren(PDB_SymType Type) const {
2940 switch (Type) {
3041 case PDB_SymType::Compiland: {
31 auto Dbi = File.getPDBDbiStream();
32 if (Dbi) {
33 const DbiModuleList &Modules = Dbi->modules();
34 return std::unique_ptr(
35 new NativeEnumModules(Session, Modules));
36 }
37 consumeError(Dbi.takeError());
42 return std::unique_ptr(new NativeEnumModules(Session));
3843 break;
3944 }
4045 case PDB_SymType::Enum:
8186 return false;
8287 }
8388
84 } // namespace pdb
85 } // namespace llvm
89 uint32_t NativeExeSymbol::getNumCompilands() const {
90 if (!Dbi)
91 return 0;
92
93 return Dbi->modules().getModuleCount();
94 }
95
96 std::unique_ptr
97 NativeExeSymbol::getOrCreateCompiland(uint32_t Index) {
98 if (!Dbi)
99 return nullptr;
100
101 if (Index >= Compilands.size())
102 return nullptr;
103
104 if (Compilands[Index] == 0) {
105 const DbiModuleList &Modules = Dbi->modules();
106 Compilands[Index] = Session.createSymbol(
107 Modules.getModuleDescriptor(Index));
108 }
109
110 return Session.getConcreteSymbolById(Compilands[Index]);
111 }
1313 using namespace llvm;
1414 using namespace llvm::pdb;
1515
16 NativeRawSymbol::NativeRawSymbol(NativeSession &PDBSession, SymIndexId SymbolId)
17 : Session(PDBSession), SymbolId(SymbolId) {}
16 NativeRawSymbol::NativeRawSymbol(NativeSession &PDBSession, PDB_SymType Tag,
17 SymIndexId SymbolId)
18 : Session(PDBSession), Tag(Tag), SymbolId(SymbolId) {}
1819
1920 void NativeRawSymbol::dump(raw_ostream &OS, int Indent) const {}
2021
373374 return PDB_DataKind::Unknown;
374375 }
375376
376 PDB_SymType NativeRawSymbol::getSymTag() const {
377 return PDB_SymType::None;
378 }
377 PDB_SymType NativeRawSymbol::getSymTag() const { return Tag; }
379378
380379 codeview::GUID NativeRawSymbol::getGuid() const { return codeview::GUID{{0}}; }
381380
6262
6363 NativeSession::NativeSession(std::unique_ptr PdbFile,
6464 std::unique_ptr Allocator)
65 : Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)) {}
65 : Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)) {
66 // Id 0 is reserved for the invalid symbol.
67 SymbolCache.push_back(nullptr);
68 }
6669
6770 NativeSession::~NativeSession() = default;
6871
9093 return make_error(raw_error_code::feature_unsupported);
9194 }
9295
93 std::unique_ptr
94 NativeSession::createCompilandSymbol(DbiModuleDescriptor MI) {
95 const auto Id = static_cast(SymbolCache.size());
96 SymbolCache.push_back(
97 llvm::make_unique(*this, Id, MI));
98 return llvm::make_unique(
99 *this, std::unique_ptr(SymbolCache[Id]->clone()));
100 }
101
10296 std::unique_ptr
10397 NativeSession::createEnumSymbol(codeview::TypeIndex Index) {
10498 const auto Id = findSymbolByTypeIndex(Index);
105 return llvm::make_unique(
106 *this, std::unique_ptr(SymbolCache[Id]->clone()));
99 return PDBSymbol::createAs(*this, *SymbolCache[Id]);
107100 }
108101
109102 std::unique_ptr
166159 bool NativeSession::setLoadAddress(uint64_t Address) { return false; }
167160
168161 std::unique_ptr NativeSession::getGlobalScope() {
169 const auto Id = static_cast(SymbolCache.size());
170 SymbolCache.push_back(llvm::make_unique(*this, Id));
171 auto RawSymbol = SymbolCache[Id]->clone();
172 auto PdbSymbol(PDBSymbol::create(*this, std::move(RawSymbol)));
173 std::unique_ptr ExeSymbol(
174 static_cast(PdbSymbol.release()));
175 return ExeSymbol;
162 return PDBSymbol::createAs(*this, getNativeGlobalScope());
176163 }
177164
178165 std::unique_ptr
179166 NativeSession::getSymbolById(uint32_t SymbolId) const {
180167 // If the caller has a SymbolId, it'd better be in our SymbolCache.
181168 return SymbolId < SymbolCache.size()
182 ? PDBSymbol::create(*this, SymbolCache[SymbolId]->clone())
169 ? PDBSymbol::create(*this, *SymbolCache[SymbolId])
183170 : nullptr;
184171 }
185172
289276 NativeSession::getSectionContribs() const {
290277 return nullptr;
291278 }
279
280 NativeExeSymbol &NativeSession::getNativeGlobalScope() {
281 if (ExeSymbol == 0) {
282 ExeSymbol = static_cast(SymbolCache.size());
283 SymbolCache.push_back(llvm::make_unique(*this, ExeSymbol));
284 }
285 return static_cast(*SymbolCache[ExeSymbol]);
286 }
4949 using namespace llvm;
5050 using namespace llvm::pdb;
5151
52 PDBSymbol::PDBSymbol(const IPDBSession &PDBSession,
53 std::unique_ptr Symbol)
54 : Session(PDBSession), RawSymbol(std::move(Symbol)) {}
52 PDBSymbol::PDBSymbol(const IPDBSession &PDBSession) : Session(PDBSession) {}
5553
56 PDBSymbol::PDBSymbol(PDBSymbol &Symbol)
57 : Session(Symbol.Session), RawSymbol(std::move(Symbol.RawSymbol)) {}
54 PDBSymbol::PDBSymbol(PDBSymbol &&Other)
55 : Session(Other.Session), RawSymbol(std::move(Other.RawSymbol)) {}
5856
5957 PDBSymbol::~PDBSymbol() = default;
6058
6159 #define FACTORY_SYMTAG_CASE(Tag, Type) \
6260 case PDB_SymType::Tag: \
63 return std::unique_ptr(new Type(PDBSession, std::move(Symbol)));
61 return std::unique_ptr(new Type(PDBSession));
6462
6563 std::unique_ptr
66 PDBSymbol::create(const IPDBSession &PDBSession,
67 std::unique_ptr Symbol) {
68 switch (Symbol->getSymTag()) {
64 PDBSymbol::createSymbol(const IPDBSession &PDBSession, PDB_SymType Tag) {
65 switch (Tag) {
6966 FACTORY_SYMTAG_CASE(Exe, PDBSymbolExe)
7067 FACTORY_SYMTAG_CASE(Compiland, PDBSymbolCompiland)
7168 FACTORY_SYMTAG_CASE(CompilandDetails, PDBSymbolCompilandDetails)
9794 FACTORY_SYMTAG_CASE(ManagedType, PDBSymbolTypeManaged)
9895 FACTORY_SYMTAG_CASE(Dimension, PDBSymbolTypeDimension)
9996 default:
100 return std::unique_ptr(
101 new PDBSymbolUnknown(PDBSession, std::move(Symbol)));
97 return std::unique_ptr(new PDBSymbolUnknown(PDBSession));
10298 }
99 }
100
101 std::unique_ptr
102 PDBSymbol::create(const IPDBSession &PDBSession,
103 std::unique_ptr RawSymbol) {
104 auto SymbolPtr = createSymbol(PDBSession, RawSymbol->getSymTag());
105 SymbolPtr->RawSymbol = RawSymbol.get();
106 SymbolPtr->OwnedRawSymbol = std::move(RawSymbol);
107 return std::move(SymbolPtr);
108 }
109
110 std::unique_ptr PDBSymbol::create(const IPDBSession &PDBSession,
111 IPDBRawSymbol &RawSymbol) {
112 auto SymbolPtr = createSymbol(PDBSession, RawSymbol.getSymTag());
113 SymbolPtr->RawSymbol = &RawSymbol;
114 return std::move(SymbolPtr);
103115 }
104116
105117 void PDBSymbol::defaultDump(raw_ostream &OS, int Indent) const {
1515 using namespace llvm;
1616 using namespace llvm::pdb;
1717
18 PDBSymbolAnnotation::PDBSymbolAnnotation(const IPDBSession &PDBSession,
19 std::unique_ptr Symbol)
20 : PDBSymbol(PDBSession, std::move(Symbol)) {
21 assert(RawSymbol->getSymTag() == PDB_SymType::Annotation);
22 }
23
2418 void PDBSymbolAnnotation::dump(PDBSymDumper &Dumper) const {
2519 Dumper.dump(*this);
2620 }
1616 using namespace llvm;
1717 using namespace llvm::pdb;
1818
19 PDBSymbolBlock::PDBSymbolBlock(const IPDBSession &PDBSession,
20 std::unique_ptr Symbol)
21 : PDBSymbol(PDBSession, std::move(Symbol)) {
22 assert(RawSymbol->getSymTag() == PDB_SymType::Block);
23 }
24
2519 void PDBSymbolBlock::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
2020
2121 using namespace llvm;
2222 using namespace llvm::pdb;
23
24 PDBSymbolCompiland::PDBSymbolCompiland(const IPDBSession &PDBSession,
25 std::unique_ptr Symbol)
26 : PDBSymbol(PDBSession, std::move(Symbol)) {
27 assert(RawSymbol->getSymTag() == PDB_SymType::Compiland);
28 }
2923
3024 void PDBSymbolCompiland::dump(PDBSymDumper &Dumper) const {
3125 Dumper.dump(*this);
1616 using namespace llvm;
1717 using namespace llvm::pdb;
1818
19 PDBSymbolCompilandDetails::PDBSymbolCompilandDetails(
20 const IPDBSession &PDBSession, std::unique_ptr Symbol)
21 : PDBSymbol(PDBSession, std::move(Symbol)) {
22 assert(RawSymbol->getSymTag() == PDB_SymType::CompilandDetails);
23 }
24
2519 void PDBSymbolCompilandDetails::dump(PDBSymDumper &Dumper) const {
2620 Dumper.dump(*this);
2721 }
1717 using namespace llvm;
1818 using namespace llvm::pdb;
1919
20 PDBSymbolCompilandEnv::PDBSymbolCompilandEnv(
21 const IPDBSession &PDBSession, std::unique_ptr Symbol)
22 : PDBSymbol(PDBSession, std::move(Symbol)) {
23 assert(RawSymbol->getSymTag() == PDB_SymType::CompilandEnv);
24 }
25
2620 std::string PDBSymbolCompilandEnv::getValue() const {
2721 Variant Value = RawSymbol->getValue();
2822 if (Value.Type != PDB_VariantType::String)
1717 using namespace llvm;
1818 using namespace llvm::pdb;
1919
20 PDBSymbolCustom::PDBSymbolCustom(const IPDBSession &PDBSession,
21 std::unique_ptr CustomSymbol)
22 : PDBSymbol(PDBSession, std::move(CustomSymbol)) {
23 assert(RawSymbol->getSymTag() == PDB_SymType::Custom);
24 }
25
2620 void PDBSymbolCustom::getDataBytes(llvm::SmallVector &bytes) {
2721 RawSymbol->getDataBytes(bytes);
2822 }
1515
1616 using namespace llvm;
1717 using namespace llvm::pdb;
18
19 PDBSymbolData::PDBSymbolData(const IPDBSession &PDBSession,
20 std::unique_ptr DataSymbol)
21 : PDBSymbol(PDBSession, std::move(DataSymbol)) {
22 assert(RawSymbol->getSymTag() == PDB_SymType::Data);
23 }
2418
2519 void PDBSymbolData::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
2620
1616 using namespace llvm;
1717 using namespace llvm::pdb;
1818
19 PDBSymbolExe::PDBSymbolExe(const IPDBSession &PDBSession,
20 std::unique_ptr Symbol)
21 : PDBSymbol(PDBSession, std::move(Symbol)) {
22 assert(RawSymbol->getSymTag() == PDB_SymType::Exe);
23 }
24
2519 void PDBSymbolExe::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
2620
2721 uint32_t PDBSymbolExe::getPointerByteSize() const {
8181 };
8282 }
8383
84 PDBSymbolFunc::PDBSymbolFunc(const IPDBSession &PDBSession,
85 std::unique_ptr Symbol)
86 : PDBSymbol(PDBSession, std::move(Symbol)) {
87 assert(RawSymbol->getSymTag() == PDB_SymType::Function);
88 }
89
9084 std::unique_ptr>
9185 PDBSymbolFunc::getArguments() const {
9286 return llvm::make_unique(Session, *this);
1616 using namespace llvm;
1717 using namespace llvm::pdb;
1818
19 PDBSymbolFuncDebugEnd::PDBSymbolFuncDebugEnd(
20 const IPDBSession &PDBSession, std::unique_ptr Symbol)
21 : PDBSymbol(PDBSession, std::move(Symbol)) {
22 assert(RawSymbol->getSymTag() == PDB_SymType::FuncDebugEnd);
23 }
24
2519 void PDBSymbolFuncDebugEnd::dump(PDBSymDumper &Dumper) const {
2620 Dumper.dump(*this);
2721 }
1616 using namespace llvm;
1717 using namespace llvm::pdb;
1818
19 PDBSymbolFuncDebugStart::PDBSymbolFuncDebugStart(
20 const IPDBSession &PDBSession, std::unique_ptr Symbol)
21 : PDBSymbol(PDBSession, std::move(Symbol)) {
22 assert(RawSymbol->getSymTag() == PDB_SymType::FuncDebugStart);
23 }
24
2519 void PDBSymbolFuncDebugStart::dump(PDBSymDumper &Dumper) const {
2620 Dumper.dump(*this);
2721 }
1515 using namespace llvm;
1616 using namespace llvm::pdb;
1717
18 PDBSymbolLabel::PDBSymbolLabel(const IPDBSession &PDBSession,
19 std::unique_ptr Symbol)
20 : PDBSymbol(PDBSession, std::move(Symbol)) {
21 assert(RawSymbol->getSymTag() == PDB_SymType::Label);
22 }
23
2418 void PDBSymbolLabel::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
1616 using namespace llvm;
1717 using namespace llvm::pdb;
1818
19 PDBSymbolPublicSymbol::PDBSymbolPublicSymbol(
20 const IPDBSession &PDBSession, std::unique_ptr Symbol)
21 : PDBSymbol(PDBSession, std::move(Symbol)) {
22 assert(RawSymbol->getSymTag() == PDB_SymType::PublicSymbol);
23 }
24
2519 void PDBSymbolPublicSymbol::dump(PDBSymDumper &Dumper) const {
2620 Dumper.dump(*this);
2721 }
1515 using namespace llvm;
1616 using namespace llvm::pdb;
1717
18 PDBSymbolThunk::PDBSymbolThunk(const IPDBSession &PDBSession,
19 std::unique_ptr Symbol)
20 : PDBSymbol(PDBSession, std::move(Symbol)) {
21 assert(RawSymbol->getSymTag() == PDB_SymType::Thunk);
22 }
23
2418 void PDBSymbolThunk::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
1515 using namespace llvm;
1616 using namespace llvm::pdb;
1717
18 PDBSymbolTypeArray::PDBSymbolTypeArray(const IPDBSession &PDBSession,
19 std::unique_ptr Symbol)
20 : PDBSymbol(PDBSession, std::move(Symbol)) {
21 assert(RawSymbol->getSymTag() == PDB_SymType::ArrayType);
22 }
23
2418 void PDBSymbolTypeArray::dump(PDBSymDumper &Dumper) const {
2519 Dumper.dump(*this);
2620 }
1616 using namespace llvm;
1717 using namespace llvm::pdb;
1818
19 PDBSymbolTypeBaseClass::PDBSymbolTypeBaseClass(
20 const IPDBSession &PDBSession, std::unique_ptr Symbol)
21 : PDBSymbol(PDBSession, std::move(Symbol)) {
22 assert(RawSymbol->getSymTag() == PDB_SymType::BaseClass);
23 }
24
2519 void PDBSymbolTypeBaseClass::dump(PDBSymDumper &Dumper) const {
2620 Dumper.dump(*this);
2721 }
1515 using namespace llvm;
1616 using namespace llvm::pdb;
1717
18 PDBSymbolTypeBuiltin::PDBSymbolTypeBuiltin(
19 const IPDBSession &PDBSession, std::unique_ptr Symbol)
20 : PDBSymbol(PDBSession, std::move(Symbol)) {
21 assert(RawSymbol->getSymTag() == PDB_SymType::BuiltinType);
22 }
23
2418 void PDBSymbolTypeBuiltin::dump(PDBSymDumper &Dumper) const {
2519 Dumper.dump(*this);
2620 }
1616 using namespace llvm;
1717 using namespace llvm::pdb;
1818
19 PDBSymbolTypeCustom::PDBSymbolTypeCustom(const IPDBSession &PDBSession,
20 std::unique_ptr Symbol)
21 : PDBSymbol(PDBSession, std::move(Symbol)) {
22 assert(RawSymbol->getSymTag() == PDB_SymType::CustomType);
23 }
24
2519 void PDBSymbolTypeCustom::dump(PDBSymDumper &Dumper) const {
2620 Dumper.dump(*this);
2721 }
1616
1717 using namespace llvm;
1818 using namespace llvm::pdb;
19
20 PDBSymbolTypeDimension::PDBSymbolTypeDimension(
21 const IPDBSession &PDBSession, std::unique_ptr Symbol)
22 : PDBSymbol(PDBSession, std::move(Symbol)) {
23 assert(RawSymbol->getSymTag() == PDB_SymType::Dimension);
24 }
25
2619 void PDBSymbolTypeDimension::dump(PDBSymDumper &Dumper) const {
2720 Dumper.dump(*this);
2821 }
1616 using namespace llvm;
1717 using namespace llvm::pdb;
1818
19 PDBSymbolTypeEnum::PDBSymbolTypeEnum(const IPDBSession &PDBSession,
20 std::unique_ptr Symbol)
21 : PDBSymbol(PDBSession, std::move(Symbol)) {
22 assert(RawSymbol->getSymTag() == PDB_SymType::Enum);
23 }
24
2519 void PDBSymbolTypeEnum::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
1616 using namespace llvm;
1717 using namespace llvm::pdb;
1818
19 PDBSymbolTypeFriend::PDBSymbolTypeFriend(const IPDBSession &PDBSession,
20 std::unique_ptr Symbol)
21 : PDBSymbol(PDBSession, std::move(Symbol)) {
22 assert(RawSymbol->getSymTag() == PDB_SymType::Friend);
23 }
24
2519 void PDBSymbolTypeFriend::dump(PDBSymDumper &Dumper) const {
2620 Dumper.dump(*this);
2721 }
1515 using namespace llvm;
1616 using namespace llvm::pdb;
1717
18 PDBSymbolTypeFunctionArg::PDBSymbolTypeFunctionArg(
19 const IPDBSession &PDBSession, std::unique_ptr Symbol)
20 : PDBSymbol(PDBSession, std::move(Symbol)) {
21 assert(RawSymbol->getSymTag() == PDB_SymType::FunctionArg);
22 }
23
2418 void PDBSymbolTypeFunctionArg::dump(PDBSymDumper &Dumper) const {
2519 Dumper.dump(*this);
2620 }
6666 };
6767 }
6868
69 PDBSymbolTypeFunctionSig::PDBSymbolTypeFunctionSig(
70 const IPDBSession &PDBSession, std::unique_ptr Symbol)
71 : PDBSymbol(PDBSession, std::move(Symbol)) {
72 assert(RawSymbol->getSymTag() == PDB_SymType::FunctionSig);
73 }
74
7569 std::unique_ptr
7670 PDBSymbolTypeFunctionSig::getArguments() const {
7771 return llvm::make_unique(Session, *this);
1616 using namespace llvm;
1717 using namespace llvm::pdb;
1818
19 PDBSymbolTypeManaged::PDBSymbolTypeManaged(
20 const IPDBSession &PDBSession, std::unique_ptr Symbol)
21 : PDBSymbol(PDBSession, std::move(Symbol)) {
22 assert(RawSymbol->getSymTag() == PDB_SymType::ManagedType);
23 }
24
2519 void PDBSymbolTypeManaged::dump(PDBSymDumper &Dumper) const {
2620 Dumper.dump(*this);
2721 }
1616 using namespace llvm;
1717 using namespace llvm::pdb;
1818
19 PDBSymbolTypePointer::PDBSymbolTypePointer(
20 const IPDBSession &PDBSession, std::unique_ptr Symbol)
21 : PDBSymbol(PDBSession, std::move(Symbol)) {
22 assert(RawSymbol->getSymTag() == PDB_SymType::PointerType);
23 }
24
2519 void PDBSymbolTypePointer::dump(PDBSymDumper &Dumper) const {
2620 Dumper.dump(*this);
2721 }
1515 using namespace llvm;
1616 using namespace llvm::pdb;
1717
18 PDBSymbolTypeTypedef::PDBSymbolTypeTypedef(
19 const IPDBSession &PDBSession, std::unique_ptr Symbol)
20 : PDBSymbol(PDBSession, std::move(Symbol)) {
21 assert(RawSymbol->getSymTag() == PDB_SymType::Typedef);
22 }
23
2418 void PDBSymbolTypeTypedef::dump(PDBSymDumper &Dumper) const {
2519 Dumper.dump(*this);
2620 }
2222 using namespace llvm;
2323 using namespace llvm::pdb;
2424
25 PDBSymbolTypeUDT::PDBSymbolTypeUDT(const IPDBSession &PDBSession,
26 std::unique_ptr Symbol)
27 : PDBSymbol(PDBSession, std::move(Symbol)) {
28 assert(RawSymbol->getSymTag() == PDB_SymType::UDT);
29 }
30
3125 void PDBSymbolTypeUDT::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
1515 using namespace llvm;
1616 using namespace llvm::pdb;
1717
18 PDBSymbolTypeVTable::PDBSymbolTypeVTable(const IPDBSession &PDBSession,
19 std::unique_ptr Symbol)
20 : PDBSymbol(PDBSession, std::move(Symbol)) {
21 assert(RawSymbol->getSymTag() == PDB_SymType::VTable);
22 }
23
2418 void PDBSymbolTypeVTable::dump(PDBSymDumper &Dumper) const {
2519 Dumper.dump(*this);
2620 }
1616 using namespace llvm;
1717 using namespace llvm::pdb;
1818
19 PDBSymbolTypeVTableShape::PDBSymbolTypeVTableShape(
20 const IPDBSession &PDBSession, std::unique_ptr Symbol)
21 : PDBSymbol(PDBSession, std::move(Symbol)) {
22 assert(RawSymbol->getSymTag() == PDB_SymType::VTableShape);
23 }
24
2519 void PDBSymbolTypeVTableShape::dump(PDBSymDumper &Dumper) const {
2620 Dumper.dump(*this);
2721 }
1616 using namespace llvm;
1717 using namespace llvm::pdb;
1818
19 PDBSymbolUnknown::PDBSymbolUnknown(const IPDBSession &PDBSession,
20 std::unique_ptr Symbol)
21 : PDBSymbol(PDBSession, std::move(Symbol)) {}
22
2319 void PDBSymbolUnknown::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
1616 using namespace llvm;
1717 using namespace llvm::pdb;
1818
19 PDBSymbolUsingNamespace::PDBSymbolUsingNamespace(
20 const IPDBSession &PDBSession, std::unique_ptr Symbol)
21 : PDBSymbol(PDBSession, std::move(Symbol)) {
22 assert(RawSymbol->getSymTag() == PDB_SymType::UsingNamespace);
23 }
24
2519 void PDBSymbolUsingNamespace::dump(PDBSymDumper &Dumper) const {
2620 Dumper.dump(*this);
2721 }
10531053 Printer.NewLine();
10541054 WithColor(Printer, PDB_ColorItem::SectionHeader).get()
10551055 << "---COMPILANDS---";
1056 if (auto Compilands = GlobalScope->findAllChildren()) {
1056 auto Compilands = GlobalScope->findAllChildren();
1057
1058 if (Compilands) {
10571059 Printer.Indent();
10581060 CompilandDumper Dumper(Printer);
10591061 CompilandDumpFlags options = CompilandDumper::Flags::None;
55
66 add_llvm_unittest(DebugInfoPDBTests
77 HashTableTest.cpp
8 NativeSymbolReuseTest.cpp
89 StringTableBuilderTest.cpp
910 PDBApiTest.cpp
1011 )
0 //===- NativeSymbolReuseTest.cpp ------------------------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/DebugInfo/PDB/PDB.h"
10
11 #include "llvm/DebugInfo/PDB/IPDBSession.h"
12 #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
13 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
14 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
15 #include "llvm/Support/Path.h"
16
17 #include "llvm/Testing/Support/Error.h"
18 #include "llvm/Testing/Support/SupportHelpers.h"
19
20 #include "gtest/gtest.h"
21
22 using namespace llvm;
23 using namespace llvm::pdb;
24
25 TEST(NativeSymbolReuseTest, GlobalSymbolReuse) {
26 SmallString<128> InputsDir = unittest::getInputFileDirectory();
27 llvm::sys::path::append(InputsDir, "empty.pdb");
28
29 std::unique_ptr S;
30 Error E = pdb::loadDataForPDB(PDB_ReaderType::Native, InputsDir, S);
31
32 ASSERT_THAT_ERROR(std::move(E), Succeeded());
33
34 SymIndexId GlobalId;
35 {
36 auto GS1 = S->getGlobalScope();
37 auto GS2 = S->getGlobalScope();
38
39 GlobalId = GS1->getSymIndexId();
40 SymIndexId Id2 = GS1->getSymIndexId();
41 EXPECT_EQ(GlobalId, Id2);
42 }
43
44 {
45 auto GS3 = S->getGlobalScope();
46
47 SymIndexId Id3 = GS3->getSymIndexId();
48 EXPECT_EQ(GlobalId, Id3);
49 }
50 }
51
52 TEST(NativeSymbolReuseTest, CompilandSymbolReuse) {
53 SmallString<128> InputsDir = unittest::getInputFileDirectory();
54 llvm::sys::path::append(InputsDir, "empty.pdb");
55
56 std::unique_ptr S;
57 Error E = pdb::loadDataForPDB(PDB_ReaderType::Native, InputsDir, S);
58
59 ASSERT_THAT_ERROR(std::move(E), Succeeded());
60
61 auto GS = S->getGlobalScope();
62
63 std::vector CompilandIds;
64 {
65 auto Compilands = GS->findAllChildren();
66 ASSERT_NE(nullptr, Compilands);
67 ASSERT_EQ(2, Compilands->getChildCount());
68 std::vector Ids2;
69
70 // First try resetting the enumerator, then try destroying the enumerator
71 // and constructing another one.
72 while (auto Compiland = Compilands->getNext())
73 CompilandIds.push_back(Compiland->getSymIndexId());
74 Compilands->reset();
75 while (auto Compiland = Compilands->getNext())
76 Ids2.push_back(Compiland->getSymIndexId());
77
78 EXPECT_EQ(CompilandIds, Ids2);
79 }
80
81 {
82 auto Compilands = GS->findAllChildren();
83 ASSERT_NE(nullptr, Compilands);
84 ASSERT_EQ(2U, Compilands->getChildCount());
85
86 std::vector Ids3;
87 while (auto Compiland = Compilands->getNext())
88 Ids3.push_back(Compiland->getSymIndexId());
89
90 EXPECT_EQ(CompilandIds, Ids3);
91 }
92 }
93
94 TEST(NativeSymbolReuseTest, CompilandSymbolReuseBackwards) {
95 SmallString<128> InputsDir = unittest::getInputFileDirectory();
96 llvm::sys::path::append(InputsDir, "empty.pdb");
97
98 std::unique_ptr S;
99 Error E = pdb::loadDataForPDB(PDB_ReaderType::Native, InputsDir, S);
100
101 ASSERT_THAT_ERROR(std::move(E), Succeeded());
102
103 auto GS = S->getGlobalScope();
104
105 // This time do the first iteration backwards, and make sure that when you
106 // then iterate them forwards, the IDs come out in reverse.
107 std::vector CompilandIds;
108 {
109 auto Compilands = GS->findAllChildren();
110 ASSERT_NE(nullptr, Compilands);
111 ASSERT_EQ(2U, Compilands->getChildCount());
112
113 std::vector Ids2;
114
115 for (int I = Compilands->getChildCount() - 1; I >= 0; --I) {
116 auto Compiland = Compilands->getChildAtIndex(I);
117 CompilandIds.push_back(Compiland->getSymIndexId());
118 }
119
120 while (auto Compiland = Compilands->getNext())
121 Ids2.push_back(Compiland->getSymIndexId());
122
123 auto ReversedIter = llvm::reverse(Ids2);
124 std::vector Reversed{ReversedIter.begin(), ReversedIter.end()};
125 EXPECT_EQ(CompilandIds, Reversed);
126 }
127 }