LLVM  8.0.1
PDBSymbol.h
Go to the documentation of this file.
1 //===- PDBSymbol.h - base class for user-facing symbol types -----*- C++-*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOL_H
11 #define LLVM_DEBUGINFO_PDB_PDBSYMBOL_H
12 
14 #include "IPDBRawSymbol.h"
15 #include "PDBExtras.h"
16 #include "PDBTypes.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/Support/Casting.h"
19 
20 #define FORWARD_SYMBOL_METHOD(MethodName) \
21  auto MethodName() const->decltype(RawSymbol->MethodName()) { \
22  return RawSymbol->MethodName(); \
23  }
24 
25 #define FORWARD_CONCRETE_SYMBOL_ID_METHOD_WITH_NAME(ConcreteType, PrivateName, \
26  PublicName) \
27  auto PublicName##Id() const->decltype(RawSymbol->PrivateName##Id()) { \
28  return RawSymbol->PrivateName##Id(); \
29  } \
30  std::unique_ptr<ConcreteType> PublicName() const { \
31  uint32_t Id = PublicName##Id(); \
32  return getConcreteSymbolByIdHelper<ConcreteType>(Id); \
33  }
34 
35 #define FORWARD_SYMBOL_ID_METHOD_WITH_NAME(PrivateName, PublicName) \
36  FORWARD_CONCRETE_SYMBOL_ID_METHOD_WITH_NAME(PDBSymbol, PrivateName, \
37  PublicName)
38 
39 #define FORWARD_SYMBOL_ID_METHOD(MethodName) \
40  FORWARD_SYMBOL_ID_METHOD_WITH_NAME(MethodName, MethodName)
41 
42 namespace llvm {
43 
44 class StringRef;
45 class raw_ostream;
46 
47 namespace pdb {
48 class IPDBRawSymbol;
49 class IPDBSession;
50 
51 #define DECLARE_PDB_SYMBOL_CONCRETE_TYPE(TagValue) \
52 private: \
53  using PDBSymbol::PDBSymbol; \
54  friend class PDBSymbol; \
55  \
56 public: \
57  static const PDB_SymType Tag = TagValue; \
58  static bool classof(const PDBSymbol *S) { return S->getSymTag() == Tag; }
59 
60 #define DECLARE_PDB_SYMBOL_CUSTOM_TYPE(Condition) \
61 private: \
62  using PDBSymbol::PDBSymbol; \
63  friend class PDBSymbol; \
64  \
65 public: \
66  static bool classof(const PDBSymbol *S) { return Condition; }
67 
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
74 class PDBSymbol {
75  static std::unique_ptr<PDBSymbol> createSymbol(const IPDBSession &PDBSession,
76  PDB_SymType Tag);
77 
78 protected:
79  explicit PDBSymbol(const IPDBSession &PDBSession);
81 
82 public:
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);
88 
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));
95  }
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));
101  }
102 
103  virtual ~PDBSymbol();
104 
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;
110 
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 {}
114 
115  void defaultDump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowFlags,
116  PdbSymbolIdField RecurseFlags) const;
117  void dumpProperties() const;
118  void dumpChildStats() const;
119 
120  PDB_SymType getSymTag() const;
121  uint32_t getSymIndexId() const;
122 
123  template <typename T> std::unique_ptr<T> findOneChild() const {
124  auto Enumerator(findAllChildren<T>());
125  if (!Enumerator)
126  return nullptr;
127  return Enumerator->getNext();
128  }
129 
130  template <typename T>
131  std::unique_ptr<ConcreteSymbolEnumerator<T>> findAllChildren() const {
132  auto BaseIter = RawSymbol->findChildren(T::Tag);
133  if (!BaseIter)
134  return nullptr;
135  return llvm::make_unique<ConcreteSymbolEnumerator<T>>(std::move(BaseIter));
136  }
137  std::unique_ptr<IPDBEnumSymbols> findAllChildren(PDB_SymType Type) const;
138  std::unique_ptr<IPDBEnumSymbols> findAllChildren() const;
139 
140  std::unique_ptr<IPDBEnumSymbols>
142  PDB_NameSearchFlags Flags) const;
143  std::unique_ptr<IPDBEnumSymbols> findChildrenByRVA(PDB_SymType Type,
144  StringRef Name,
145  PDB_NameSearchFlags Flags,
146  uint32_t RVA) const;
147  std::unique_ptr<IPDBEnumSymbols> findInlineFramesByRVA(uint32_t RVA) const;
148 
149  const IPDBRawSymbol &getRawSymbol() const { return *RawSymbol; }
151 
152  const IPDBSession &getSession() const { return Session; }
153 
154  std::unique_ptr<IPDBEnumSymbols> getChildStats(TagStats &Stats) const;
155 
156 protected:
157  std::unique_ptr<PDBSymbol> getSymbolByIdHelper(uint32_t Id) const;
158 
159  template <typename ConcreteType>
160  std::unique_ptr<ConcreteType> getConcreteSymbolByIdHelper(uint32_t Id) const {
161  return unique_dyn_cast_or_null<ConcreteType>(getSymbolByIdHelper(Id));
162  }
163 
165  std::unique_ptr<IPDBRawSymbol> OwnedRawSymbol;
166  IPDBRawSymbol *RawSymbol = nullptr;
167 };
168 
169 } // namespace llvm
170 }
171 
172 #endif
IPDBSession defines an interface used to provide a context for querying debug information from a debu...
Definition: IPDBSession.h:26
IPDBRawSymbol * RawSymbol
Definition: PDBSymbol.h:166
This class represents lattice values for constants.
Definition: AllocatorList.h:24
const IPDBSession & getSession() const
Definition: PDBSymbol.h:152
virtual std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type) const =0
static std::unique_ptr< ConcreteT > createAs(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > RawSymbol)
Definition: PDBSymbol.h:91
virtual void dumpRight(PDBSymDumper &Dumper) const
For certain PDBSymbolTypes, dumps additional information for the type that normally goes on the right...
Definition: PDBSymbol.h:113
std::unique_ptr< IPDBRawSymbol > OwnedRawSymbol
Definition: PDBSymbol.h:165
PDB_NameSearchFlags
Defines flags used for enumerating child symbols.
Definition: PDBTypes.h:101
IPDBRawSymbol & getRawSymbol()
Definition: PDBSymbol.h:150
std::unique_ptr< T > findOneChild() const
Definition: PDBSymbol.h:123
std::unique_ptr< ConcreteSymbolEnumerator< T > > findAllChildren() const
Definition: PDBSymbol.h:131
amdgpu Simplify well known AMD library false Value Value const Twine & Name
std::unordered_map< PDB_SymType, int > TagStats
Definition: PDBExtras.h:25
block placement Basic Block Placement Stats
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:784
std::unique_ptr< IPDBEnumSymbols > getChildStats(TagStats &Stats) const
Definition: PDBSymbol.cpp:170
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn.microsoft.com/en-us/library/bkedss5f.aspx.
Definition: PDBTypes.h:183
void defaultDump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowFlags, PdbSymbolIdField RecurseFlags) const
Definition: PDBSymbol.cpp:118
std::unique_ptr< ConcreteType > getConcreteSymbolByIdHelper(uint32_t Id) const
Definition: PDBSymbol.h:160
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
IPDBRawSymbol defines an interface used to represent an arbitrary symbol.
Definition: IPDBRawSymbol.h:50
std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags) const
Definition: PDBSymbol.cpp:153
PDBSymbol(const IPDBSession &PDBSession)
Definition: PDBSymbol.cpp:53
std::unique_ptr< PDBSymbol > getSymbolByIdHelper(uint32_t Id) const
Definition: PDBSymbol.cpp:182
PDB_SymType getSymTag() const
Definition: PDBSymbol.cpp:140
PDBSymbol defines the base of the inheritance hierarchy for concrete symbol types (e...
Definition: PDBSymbol.h:74
const IPDBRawSymbol & getRawSymbol() const
Definition: PDBSymbol.h:149
virtual void dump(PDBSymDumper &Dumper) const =0
Dumps the contents of a symbol a raw_ostream.
static std::unique_ptr< ConcreteT > createAs(const IPDBSession &PDBSession, IPDBRawSymbol &RawSymbol)
Definition: PDBSymbol.h:97
const IPDBSession & Session
Definition: PDBSymbol.h:164
std::unique_ptr< IPDBEnumSymbols > findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, uint32_t RVA) const
Definition: PDBSymbol.cpp:159
void dumpProperties() const
Definition: PDBSymbol.cpp:124
std::unique_ptr< IPDBEnumSymbols > findInlineFramesByRVA(uint32_t RVA) const
Definition: PDBSymbol.cpp:165
uint32_t getSymIndexId() const
Definition: PDBSymbol.cpp:141
Definition: JSON.cpp:598
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
static std::unique_ptr< PDBSymbol > create(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > RawSymbol)
Definition: PDBSymbol.cpp:103
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
void dumpChildStats() const
Definition: PDBSymbol.cpp:130