LLVM  10.0.0svn
PDBSymbol.h
Go to the documentation of this file.
1 //===- PDBSymbol.h - base class for user-facing symbol types -----*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOL_H
10 #define LLVM_DEBUGINFO_PDB_PDBSYMBOL_H
11 
13 #include "IPDBRawSymbol.h"
14 #include "PDBExtras.h"
15 #include "PDBTypes.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/Support/Casting.h"
18 
19 #define FORWARD_SYMBOL_METHOD(MethodName) \
20  auto MethodName() const->decltype(RawSymbol->MethodName()) { \
21  return RawSymbol->MethodName(); \
22  }
23 
24 #define FORWARD_CONCRETE_SYMBOL_ID_METHOD_WITH_NAME(ConcreteType, PrivateName, \
25  PublicName) \
26  auto PublicName##Id() const->decltype(RawSymbol->PrivateName##Id()) { \
27  return RawSymbol->PrivateName##Id(); \
28  } \
29  std::unique_ptr<ConcreteType> PublicName() const { \
30  uint32_t Id = PublicName##Id(); \
31  return getConcreteSymbolByIdHelper<ConcreteType>(Id); \
32  }
33 
34 #define FORWARD_SYMBOL_ID_METHOD_WITH_NAME(PrivateName, PublicName) \
35  FORWARD_CONCRETE_SYMBOL_ID_METHOD_WITH_NAME(PDBSymbol, PrivateName, \
36  PublicName)
37 
38 #define FORWARD_SYMBOL_ID_METHOD(MethodName) \
39  FORWARD_SYMBOL_ID_METHOD_WITH_NAME(MethodName, MethodName)
40 
41 namespace llvm {
42 
43 class StringRef;
44 class raw_ostream;
45 
46 namespace pdb {
47 class IPDBRawSymbol;
48 class IPDBSession;
49 
50 #define DECLARE_PDB_SYMBOL_CONCRETE_TYPE(TagValue) \
51 private: \
52  using PDBSymbol::PDBSymbol; \
53  friend class PDBSymbol; \
54  \
55 public: \
56  static const PDB_SymType Tag = TagValue; \
57  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; }
66 
67 /// PDBSymbol defines the base of the inheritance hierarchy for concrete symbol
68 /// types (e.g. functions, executables, vtables, etc). All concrete symbol
69 /// types inherit from PDBSymbol and expose the exact set of methods that are
70 /// valid for that particular symbol type, as described in the Microsoft
71 /// reference "Lexical and Class Hierarchy of Symbol Types":
72 /// https://msdn.microsoft.com/en-us/library/370hs6k4.aspx
73 class PDBSymbol {
74  static std::unique_ptr<PDBSymbol> createSymbol(const IPDBSession &PDBSession,
75  PDB_SymType Tag);
76 
77 protected:
78  explicit PDBSymbol(const IPDBSession &PDBSession);
80 
81 public:
82  static std::unique_ptr<PDBSymbol>
83  create(const IPDBSession &PDBSession,
84  std::unique_ptr<IPDBRawSymbol> RawSymbol);
85  static std::unique_ptr<PDBSymbol> create(const IPDBSession &PDBSession,
86  IPDBRawSymbol &RawSymbol);
87 
88  template <typename ConcreteT>
89  static std::unique_ptr<ConcreteT>
90  createAs(const IPDBSession &PDBSession,
91  std::unique_ptr<IPDBRawSymbol> RawSymbol) {
92  std::unique_ptr<PDBSymbol> S = create(PDBSession, std::move(RawSymbol));
93  return unique_dyn_cast_or_null<ConcreteT>(std::move(S));
94  }
95  template <typename ConcreteT>
96  static std::unique_ptr<ConcreteT> createAs(const IPDBSession &PDBSession,
97  IPDBRawSymbol &RawSymbol) {
98  std::unique_ptr<PDBSymbol> S = create(PDBSession, RawSymbol);
99  return unique_dyn_cast_or_null<ConcreteT>(std::move(S));
100  }
101 
102  virtual ~PDBSymbol();
103 
104  /// Dumps the contents of a symbol a raw_ostream. By default this will just
105  /// call dump() on the underlying RawSymbol, which allows us to discover
106  /// unknown properties, but individual implementations of PDBSymbol may
107  /// override the behavior to only dump known fields.
108  virtual void dump(PDBSymDumper &Dumper) const = 0;
109 
110  /// For certain PDBSymbolTypes, dumps additional information for the type that
111  /// normally goes on the right side of the symbol.
112  virtual void dumpRight(PDBSymDumper &Dumper) const {}
113 
114  void defaultDump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowFlags,
115  PdbSymbolIdField RecurseFlags) const;
116  void dumpProperties() const;
117  void dumpChildStats() const;
118 
119  PDB_SymType getSymTag() const;
120  uint32_t getSymIndexId() const;
121 
122  template <typename T> std::unique_ptr<T> findOneChild() const {
123  auto Enumerator(findAllChildren<T>());
124  if (!Enumerator)
125  return nullptr;
126  return Enumerator->getNext();
127  }
128 
129  template <typename T>
130  std::unique_ptr<ConcreteSymbolEnumerator<T>> findAllChildren() const {
131  auto BaseIter = RawSymbol->findChildren(T::Tag);
132  if (!BaseIter)
133  return nullptr;
134  return std::make_unique<ConcreteSymbolEnumerator<T>>(std::move(BaseIter));
135  }
136  std::unique_ptr<IPDBEnumSymbols> findAllChildren(PDB_SymType Type) const;
137  std::unique_ptr<IPDBEnumSymbols> findAllChildren() const;
138 
139  std::unique_ptr<IPDBEnumSymbols>
141  PDB_NameSearchFlags Flags) const;
142  std::unique_ptr<IPDBEnumSymbols> findChildrenByRVA(PDB_SymType Type,
143  StringRef Name,
144  PDB_NameSearchFlags Flags,
145  uint32_t RVA) const;
146  std::unique_ptr<IPDBEnumSymbols> findInlineFramesByRVA(uint32_t RVA) const;
147 
148  const IPDBRawSymbol &getRawSymbol() const { return *RawSymbol; }
150 
151  const IPDBSession &getSession() const { return Session; }
152 
153  std::unique_ptr<IPDBEnumSymbols> getChildStats(TagStats &Stats) const;
154 
155 protected:
156  std::unique_ptr<PDBSymbol> getSymbolByIdHelper(uint32_t Id) const;
157 
158  template <typename ConcreteType>
159  std::unique_ptr<ConcreteType> getConcreteSymbolByIdHelper(uint32_t Id) const {
160  return unique_dyn_cast_or_null<ConcreteType>(getSymbolByIdHelper(Id));
161  }
162 
164  std::unique_ptr<IPDBRawSymbol> OwnedRawSymbol;
165  IPDBRawSymbol *RawSymbol = nullptr;
166 };
167 
168 } // namespace llvm
169 }
170 
171 #endif
IPDBSession defines an interface used to provide a context for querying debug information from a debu...
Definition: IPDBSession.h:25
IPDBRawSymbol * RawSymbol
Definition: PDBSymbol.h:165
This class represents lattice values for constants.
Definition: AllocatorList.h:23
const IPDBSession & getSession() const
Definition: PDBSymbol.h:151
virtual std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type) const =0
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
static std::unique_ptr< ConcreteT > createAs(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > RawSymbol)
Definition: PDBSymbol.h:90
virtual void dumpRight(PDBSymDumper &Dumper) const
For certain PDBSymbolTypes, dumps additional information for the type that normally goes on the right...
Definition: PDBSymbol.h:112
std::unique_ptr< IPDBRawSymbol > OwnedRawSymbol
Definition: PDBSymbol.h:164
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:952
PDB_NameSearchFlags
Defines flags used for enumerating child symbols.
Definition: PDBTypes.h:100
IPDBRawSymbol & getRawSymbol()
Definition: PDBSymbol.h:149
std::unique_ptr< T > findOneChild() const
Definition: PDBSymbol.h:122
std::unique_ptr< ConcreteSymbolEnumerator< T > > findAllChildren() const
Definition: PDBSymbol.h:130
std::unordered_map< PDB_SymType, int > TagStats
Definition: PDBExtras.h:24
block placement Basic Block Placement Stats
std::unique_ptr< IPDBEnumSymbols > getChildStats(TagStats &Stats) const
Definition: PDBSymbol.cpp:169
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:241
void defaultDump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowFlags, PdbSymbolIdField RecurseFlags) const
Definition: PDBSymbol.cpp:117
std::unique_ptr< ConcreteType > getConcreteSymbolByIdHelper(uint32_t Id) const
Definition: PDBSymbol.h:159
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
IPDBRawSymbol defines an interface used to represent an arbitrary symbol.
Definition: IPDBRawSymbol.h:49
std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags) const
Definition: PDBSymbol.cpp:152
PDBSymbol(const IPDBSession &PDBSession)
Definition: PDBSymbol.cpp:52
std::unique_ptr< PDBSymbol > getSymbolByIdHelper(uint32_t Id) const
Definition: PDBSymbol.cpp:181
PDB_SymType getSymTag() const
Definition: PDBSymbol.cpp:139
PDBSymbol defines the base of the inheritance hierarchy for concrete symbol types (e...
Definition: PDBSymbol.h:73
const IPDBRawSymbol & getRawSymbol() const
Definition: PDBSymbol.h:148
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:96
const IPDBSession & Session
Definition: PDBSymbol.h:163
std::unique_ptr< IPDBEnumSymbols > findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, uint32_t RVA) const
Definition: PDBSymbol.cpp:158
void dumpProperties() const
Definition: PDBSymbol.cpp:123
std::unique_ptr< IPDBEnumSymbols > findInlineFramesByRVA(uint32_t RVA) const
Definition: PDBSymbol.cpp:164
uint32_t getSymIndexId() const
Definition: PDBSymbol.cpp:140
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
static std::unique_ptr< PDBSymbol > create(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > RawSymbol)
Definition: PDBSymbol.cpp:102
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
void dumpChildStats() const
Definition: PDBSymbol.cpp:129