LLVM  14.0.0git
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  decltype(auto) MethodName() const { return RawSymbol->MethodName(); }
21 
22 #define FORWARD_CONCRETE_SYMBOL_ID_METHOD_WITH_NAME(ConcreteType, PrivateName, \
23  PublicName) \
24  decltype(auto) PublicName##Id() const { \
25  return RawSymbol->PrivateName##Id(); \
26  } \
27  std::unique_ptr<ConcreteType> PublicName() const { \
28  uint32_t Id = PublicName##Id(); \
29  return getConcreteSymbolByIdHelper<ConcreteType>(Id); \
30  }
31 
32 #define FORWARD_SYMBOL_ID_METHOD_WITH_NAME(PrivateName, PublicName) \
33  FORWARD_CONCRETE_SYMBOL_ID_METHOD_WITH_NAME(PDBSymbol, PrivateName, \
34  PublicName)
35 
36 #define FORWARD_SYMBOL_ID_METHOD(MethodName) \
37  FORWARD_SYMBOL_ID_METHOD_WITH_NAME(MethodName, MethodName)
38 
39 namespace llvm {
40 
41 class StringRef;
42 class raw_ostream;
43 
44 namespace pdb {
45 class IPDBSession;
46 
47 #define DECLARE_PDB_SYMBOL_CONCRETE_TYPE(TagValue) \
48 private: \
49  using PDBSymbol::PDBSymbol; \
50  friend class PDBSymbol; \
51  \
52 public: \
53  static const PDB_SymType Tag = TagValue; \
54  static bool classof(const PDBSymbol *S) { return S->getSymTag() == Tag; }
55 
56 #define DECLARE_PDB_SYMBOL_CUSTOM_TYPE(Condition) \
57 private: \
58  using PDBSymbol::PDBSymbol; \
59  friend class PDBSymbol; \
60  \
61 public: \
62  static bool classof(const PDBSymbol *S) { return Condition; }
63 
64 /// PDBSymbol defines the base of the inheritance hierarchy for concrete symbol
65 /// types (e.g. functions, executables, vtables, etc). All concrete symbol
66 /// types inherit from PDBSymbol and expose the exact set of methods that are
67 /// valid for that particular symbol type, as described in the Microsoft
68 /// reference "Lexical and Class Hierarchy of Symbol Types":
69 /// https://msdn.microsoft.com/en-us/library/370hs6k4.aspx
70 class PDBSymbol {
71  static std::unique_ptr<PDBSymbol> createSymbol(const IPDBSession &PDBSession,
72  PDB_SymType Tag);
73 
74 protected:
75  explicit PDBSymbol(const IPDBSession &PDBSession);
77 
78 public:
79  static std::unique_ptr<PDBSymbol>
80  create(const IPDBSession &PDBSession,
81  std::unique_ptr<IPDBRawSymbol> RawSymbol);
82  static std::unique_ptr<PDBSymbol> create(const IPDBSession &PDBSession,
84 
85  template <typename ConcreteT>
86  static std::unique_ptr<ConcreteT>
87  createAs(const IPDBSession &PDBSession,
88  std::unique_ptr<IPDBRawSymbol> RawSymbol) {
89  std::unique_ptr<PDBSymbol> S = create(PDBSession, std::move(RawSymbol));
90  return unique_dyn_cast_or_null<ConcreteT>(std::move(S));
91  }
92  template <typename ConcreteT>
93  static std::unique_ptr<ConcreteT> createAs(const IPDBSession &PDBSession,
95  std::unique_ptr<PDBSymbol> S = create(PDBSession, RawSymbol);
96  return unique_dyn_cast_or_null<ConcreteT>(std::move(S));
97  }
98 
99  virtual ~PDBSymbol();
100 
101  /// Dumps the contents of a symbol a raw_ostream. By default this will just
102  /// call dump() on the underlying RawSymbol, which allows us to discover
103  /// unknown properties, but individual implementations of PDBSymbol may
104  /// override the behavior to only dump known fields.
105  virtual void dump(PDBSymDumper &Dumper) const = 0;
106 
107  /// For certain PDBSymbolTypes, dumps additional information for the type that
108  /// normally goes on the right side of the symbol.
109  virtual void dumpRight(PDBSymDumper &Dumper) const {}
110 
111  void defaultDump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowFlags,
112  PdbSymbolIdField RecurseFlags) const;
113  void dumpProperties() const;
114  void dumpChildStats() const;
115 
116  PDB_SymType getSymTag() const;
117  uint32_t getSymIndexId() const;
118 
119  template <typename T> std::unique_ptr<T> findOneChild() const {
120  auto Enumerator(findAllChildren<T>());
121  if (!Enumerator)
122  return nullptr;
123  return Enumerator->getNext();
124  }
125 
126  template <typename T>
127  std::unique_ptr<ConcreteSymbolEnumerator<T>> findAllChildren() const {
128  auto BaseIter = RawSymbol->findChildren(T::Tag);
129  if (!BaseIter)
130  return nullptr;
131  return std::make_unique<ConcreteSymbolEnumerator<T>>(std::move(BaseIter));
132  }
133  std::unique_ptr<IPDBEnumSymbols> findAllChildren(PDB_SymType Type) const;
134  std::unique_ptr<IPDBEnumSymbols> findAllChildren() const;
135 
136  std::unique_ptr<IPDBEnumSymbols>
138  PDB_NameSearchFlags Flags) const;
139  std::unique_ptr<IPDBEnumSymbols> findChildrenByRVA(PDB_SymType Type,
140  StringRef Name,
141  PDB_NameSearchFlags Flags,
142  uint32_t RVA) const;
143  std::unique_ptr<IPDBEnumSymbols> findInlineFramesByVA(uint64_t VA) const;
144  std::unique_ptr<IPDBEnumSymbols> findInlineFramesByRVA(uint32_t RVA) const;
145  std::unique_ptr<IPDBEnumLineNumbers>
146  findInlineeLinesByVA(uint64_t VA, uint32_t Length) const;
147  std::unique_ptr<IPDBEnumLineNumbers>
148  findInlineeLinesByRVA(uint32_t RVA, uint32_t Length) const;
149 
150  std::string getName() const;
151 
152  const IPDBRawSymbol &getRawSymbol() const { return *RawSymbol; }
154 
155  const IPDBSession &getSession() const { return Session; }
156 
157  std::unique_ptr<IPDBEnumSymbols> getChildStats(TagStats &Stats) const;
158 
159 protected:
160  std::unique_ptr<PDBSymbol> getSymbolByIdHelper(uint32_t Id) const;
161 
162  template <typename ConcreteType>
163  std::unique_ptr<ConcreteType> getConcreteSymbolByIdHelper(uint32_t Id) const {
164  return unique_dyn_cast_or_null<ConcreteType>(getSymbolByIdHelper(Id));
165  }
166 
168  std::unique_ptr<IPDBRawSymbol> OwnedRawSymbol;
170 };
171 
172 } // namespace llvm
173 }
174 
175 #endif
llvm::pdb::PDBSymbol::createAs
static std::unique_ptr< ConcreteT > createAs(const IPDBSession &PDBSession, IPDBRawSymbol &RawSymbol)
Definition: PDBSymbol.h:93
llvm::pdb::IPDBSession
IPDBSession defines an interface used to provide a context for querying debug information from a debu...
Definition: IPDBSession.h:25
llvm::pdb::PDBSymbol::getName
std::string getName() const
Definition: PDBSymbol.cpp:183
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::pdb::PDBSymbol::dumpChildStats
void dumpChildStats() const
Definition: PDBSymbol.cpp:129
llvm::pdb::PDBSymbol::OwnedRawSymbol
std::unique_ptr< IPDBRawSymbol > OwnedRawSymbol
Definition: PDBSymbol.h:168
IPDBRawSymbol.h
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::pdb::PDBSymbol::defaultDump
void defaultDump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowFlags, PdbSymbolIdField RecurseFlags) const
Definition: PDBSymbol.cpp:117
STLExtras.h
llvm::dwarf::Tag
Tag
Definition: Dwarf.h:104
llvm::pdb::PDB_SymType
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn....
Definition: PDBTypes.h:243
llvm::pdb::PDBSymbol::create
static std::unique_ptr< PDBSymbol > create(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > RawSymbol)
Definition: PDBSymbol.cpp:102
llvm::pdb::PDBSymbol::dump
virtual void dump(PDBSymDumper &Dumper) const =0
Dumps the contents of a symbol a raw_ostream.
llvm::pdb::IPDBRawSymbol::findChildren
virtual std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type) const =0
llvm::pdb::PDBSymbol::findInlineeLinesByRVA
std::unique_ptr< IPDBEnumLineNumbers > findInlineeLinesByRVA(uint32_t RVA, uint32_t Length) const
Definition: PDBSymbol.cpp:179
llvm::HighlightColor::Enumerator
@ Enumerator
llvm::pdb::PDBSymbol::PDBSymbol
PDBSymbol(const IPDBSession &PDBSession)
Definition: PDBSymbol.cpp:52
llvm::pdb::PDBSymbol::createAs
static std::unique_ptr< ConcreteT > createAs(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > RawSymbol)
Definition: PDBSymbol.h:87
llvm::pdb::PDBSymbol
PDBSymbol defines the base of the inheritance hierarchy for concrete symbol types (e....
Definition: PDBSymbol.h:70
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::pdb::PDBSymbol::~PDBSymbol
virtual ~PDBSymbol()
llvm::pdb::PDB_NameSearchFlags
PDB_NameSearchFlags
Defines flags used for enumerating child symbols.
Definition: PDBTypes.h:102
llvm::pdb::PDBSymbol::getSymbolByIdHelper
std::unique_ptr< PDBSymbol > getSymbolByIdHelper(uint32_t Id) const
Definition: PDBSymbol.cpp:198
PDBTypes.h
llvm::pdb::PDBSymbol::getSymIndexId
uint32_t getSymIndexId() const
Definition: PDBSymbol.cpp:140
llvm::pdb::PDBSymbol::getConcreteSymbolByIdHelper
std::unique_ptr< ConcreteType > getConcreteSymbolByIdHelper(uint32_t Id) const
Definition: PDBSymbol.h:163
llvm::pdb::PDBSymbol::getChildStats
std::unique_ptr< IPDBEnumSymbols > getChildStats(TagStats &Stats) const
Definition: PDBSymbol.cpp:186
llvm::pdb::PDBSymbol::findChildrenByRVA
std::unique_ptr< IPDBEnumSymbols > findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, uint32_t RVA) const
Definition: PDBSymbol.cpp:158
llvm::pdb::PDBSymbol::getRawSymbol
const IPDBRawSymbol & getRawSymbol() const
Definition: PDBSymbol.h:152
uint64_t
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::pdb::PDBSymbol::findInlineeLinesByVA
std::unique_ptr< IPDBEnumLineNumbers > findInlineeLinesByVA(uint64_t VA, uint32_t Length) const
Definition: PDBSymbol.cpp:174
llvm::pdb::PDBSymbol::findOneChild
std::unique_ptr< T > findOneChild() const
Definition: PDBSymbol.h:119
llvm::pdb::PDBSymDumper
Definition: PDBSymDumper.h:19
llvm::pdb::PDBSymbol::Session
const IPDBSession & Session
Definition: PDBSymbol.h:167
llvm::pdb::PDBSymbol::getRawSymbol
IPDBRawSymbol & getRawSymbol()
Definition: PDBSymbol.h:153
llvm::pdb::PDBSymbol::findChildren
std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags) const
Definition: PDBSymbol.cpp:152
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::pdb::PDBSymbol::RawSymbol
IPDBRawSymbol * RawSymbol
Definition: PDBSymbol.h:169
uint32_t
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::pdb::TagStats
std::unordered_map< PDB_SymType, int > TagStats
Definition: PDBExtras.h:23
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
Stats
block placement Basic Block Placement Stats
Definition: MachineBlockPlacement.cpp:3465
Casting.h
llvm::pdb::PDBSymbol::getSession
const IPDBSession & getSession() const
Definition: PDBSymbol.h:155
llvm::pdb::PDBSymbol::dumpRight
virtual void dumpRight(PDBSymDumper &Dumper) const
For certain PDBSymbolTypes, dumps additional information for the type that normally goes on the right...
Definition: PDBSymbol.h:109
llvm::pdb::PDBSymbol::getSymTag
PDB_SymType getSymTag() const
Definition: PDBSymbol.cpp:139
llvm::pdb::PdbSymbolIdField
PdbSymbolIdField
Definition: IPDBRawSymbol.h:24
llvm::pdb::PDBSymbol::findAllChildren
std::unique_ptr< ConcreteSymbolEnumerator< T > > findAllChildren() const
Definition: PDBSymbol.h:127
PDBExtras.h
llvm::pdb::IPDBRawSymbol
IPDBRawSymbol defines an interface used to represent an arbitrary symbol.
Definition: IPDBRawSymbol.h:45
llvm::AMDGPU::VGPRIndexMode::Id
Id
Definition: SIDefines.h:228
ConcreteSymbolEnumerator.h
llvm::pdb::PDBSymbol::findInlineFramesByRVA
std::unique_ptr< IPDBEnumSymbols > findInlineFramesByRVA(uint32_t RVA) const
Definition: PDBSymbol.cpp:169
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1175
llvm::pdb::PDBSymbol::dumpProperties
void dumpProperties() const
Definition: PDBSymbol.cpp:123
llvm::pdb::PDBSymbol::findInlineFramesByVA
std::unique_ptr< IPDBEnumSymbols > findInlineFramesByVA(uint64_t VA) const
Definition: PDBSymbol.cpp:164