1 //===- PDBSymbol.h - base class for user-facing symbol types -----*- C++-*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOL_H
11 #define LLVM_DEBUGINFO_PDB_PDBSYMBOL_H
13 #include "ConcreteSymbolEnumerator.h"
14 #include "IPDBRawSymbol.h"
15 #include "PDBExtras.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/Support/Casting.h"
20 #define FORWARD_SYMBOL_METHOD(MethodName) \
21 auto MethodName() const->decltype(RawSymbol->MethodName()) { \
22 return RawSymbol->MethodName(); \
25 #define FORWARD_CONCRETE_SYMBOL_ID_METHOD_WITH_NAME(ConcreteType, PrivateName, \
27 auto PublicName##Id() const->decltype(RawSymbol->PrivateName##Id()) { \
28 return RawSymbol->PrivateName##Id(); \
30 std::unique_ptr<ConcreteType> PublicName() const { \
31 uint32_t Id = PublicName##Id(); \
32 return getConcreteSymbolByIdHelper<ConcreteType>(Id); \
35 #define FORWARD_SYMBOL_ID_METHOD_WITH_NAME(PrivateName, PublicName) \
36 FORWARD_CONCRETE_SYMBOL_ID_METHOD_WITH_NAME(PDBSymbol, PrivateName, \
39 #define FORWARD_SYMBOL_ID_METHOD(MethodName) \
40 FORWARD_SYMBOL_ID_METHOD_WITH_NAME(MethodName, MethodName)
51 #define DECLARE_PDB_SYMBOL_CONCRETE_TYPE(TagValue) \
53 using PDBSymbol::PDBSymbol; \
54 friend class PDBSymbol; \
57 static const PDB_SymType Tag = TagValue; \
58 static bool classof(const PDBSymbol *S) { return S->getSymTag() == Tag; }
60 #define DECLARE_PDB_SYMBOL_CUSTOM_TYPE(Condition) \
62 using PDBSymbol::PDBSymbol; \
63 friend class PDBSymbol; \
66 static bool classof(const PDBSymbol *S) { return Condition; }
68 /// PDBSymbol defines the base of the inheritance hierarchy for concrete symbol
69 /// types (e.g. functions, executables, vtables, etc). All concrete symbol
70 /// types inherit from PDBSymbol and expose the exact set of methods that are
71 /// valid for that particular symbol type, as described in the Microsoft
72 /// reference "Lexical and Class Hierarchy of Symbol Types":
73 /// https://msdn.microsoft.com/en-us/library/370hs6k4.aspx
75 static std::unique_ptr<PDBSymbol> createSymbol(const IPDBSession &PDBSession,
79 explicit PDBSymbol(const IPDBSession &PDBSession);
80 PDBSymbol(PDBSymbol &&Other);
83 static std::unique_ptr<PDBSymbol>
84 create(const IPDBSession &PDBSession,
85 std::unique_ptr<IPDBRawSymbol> RawSymbol);
86 static std::unique_ptr<PDBSymbol> create(const IPDBSession &PDBSession,
87 IPDBRawSymbol &RawSymbol);
89 template <typename ConcreteT>
90 static std::unique_ptr<ConcreteT>
91 createAs(const IPDBSession &PDBSession,
92 std::unique_ptr<IPDBRawSymbol> RawSymbol) {
93 std::unique_ptr<PDBSymbol> S = create(PDBSession, std::move(RawSymbol));
94 return unique_dyn_cast_or_null<ConcreteT>(std::move(S));
96 template <typename ConcreteT>
97 static std::unique_ptr<ConcreteT> createAs(const IPDBSession &PDBSession,
98 IPDBRawSymbol &RawSymbol) {
99 std::unique_ptr<PDBSymbol> S = create(PDBSession, RawSymbol);
100 return unique_dyn_cast_or_null<ConcreteT>(std::move(S));
103 virtual ~PDBSymbol();
105 /// Dumps the contents of a symbol a raw_ostream. By default this will just
106 /// call dump() on the underlying RawSymbol, which allows us to discover
107 /// unknown properties, but individual implementations of PDBSymbol may
108 /// override the behavior to only dump known fields.
109 virtual void dump(PDBSymDumper &Dumper) const = 0;
111 /// For certain PDBSymbolTypes, dumps additional information for the type that
112 /// normally goes on the right side of the symbol.
113 virtual void dumpRight(PDBSymDumper &Dumper) const {}
115 void defaultDump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowFlags,
116 PdbSymbolIdField RecurseFlags) const;
117 void dumpProperties() const;
118 void dumpChildStats() const;
120 PDB_SymType getSymTag() const;
121 uint32_t getSymIndexId() const;
123 template <typename T> std::unique_ptr<T> findOneChild() const {
124 auto Enumerator(findAllChildren<T>());
127 return Enumerator->getNext();
130 template <typename T>
131 std::unique_ptr<ConcreteSymbolEnumerator<T>> findAllChildren() const {
132 auto BaseIter = RawSymbol->findChildren(T::Tag);
135 return llvm::make_unique<ConcreteSymbolEnumerator<T>>(std::move(BaseIter));
137 std::unique_ptr<IPDBEnumSymbols> findAllChildren(PDB_SymType Type) const;
138 std::unique_ptr<IPDBEnumSymbols> findAllChildren() const;
140 std::unique_ptr<IPDBEnumSymbols>
141 findChildren(PDB_SymType Type, StringRef Name,
142 PDB_NameSearchFlags Flags) const;
143 std::unique_ptr<IPDBEnumSymbols> findChildrenByRVA(PDB_SymType Type,
145 PDB_NameSearchFlags Flags,
147 std::unique_ptr<IPDBEnumSymbols> findInlineFramesByRVA(uint32_t RVA) const;
149 const IPDBRawSymbol &getRawSymbol() const { return *RawSymbol; }
150 IPDBRawSymbol &getRawSymbol() { return *RawSymbol; }
152 const IPDBSession &getSession() const { return Session; }
154 std::unique_ptr<IPDBEnumSymbols> getChildStats(TagStats &Stats) const;
157 std::unique_ptr<PDBSymbol> getSymbolByIdHelper(uint32_t Id) const;
159 template <typename ConcreteType>
160 std::unique_ptr<ConcreteType> getConcreteSymbolByIdHelper(uint32_t Id) const {
161 return unique_dyn_cast_or_null<ConcreteType>(getSymbolByIdHelper(Id));
164 const IPDBSession &Session;
165 std::unique_ptr<IPDBRawSymbol> OwnedRawSymbol;
166 IPDBRawSymbol *RawSymbol = nullptr;