LLVM  6.0.0svn
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  static const PDB_SymType Tag = TagValue; \
53  static bool classof(const PDBSymbol *S) { return S->getSymTag() == Tag; }
54 
55 /// PDBSymbol defines the base of the inheritance hierarchy for concrete symbol
56 /// types (e.g. functions, executables, vtables, etc). All concrete symbol
57 /// types inherit from PDBSymbol and expose the exact set of methods that are
58 /// valid for that particular symbol type, as described in the Microsoft
59 /// reference "Lexical and Class Hierarchy of Symbol Types":
60 /// https://msdn.microsoft.com/en-us/library/370hs6k4.aspx
61 class PDBSymbol {
62 protected:
63  PDBSymbol(const IPDBSession &PDBSession,
64  std::unique_ptr<IPDBRawSymbol> Symbol);
65  PDBSymbol(PDBSymbol &Symbol);
66 
67 public:
68  static std::unique_ptr<PDBSymbol>
69  create(const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol);
70 
71  virtual ~PDBSymbol();
72 
73  /// Dumps the contents of a symbol a raw_ostream. By default this will just
74  /// call dump() on the underlying RawSymbol, which allows us to discover
75  /// unknown properties, but individual implementations of PDBSymbol may
76  /// override the behavior to only dump known fields.
77  virtual void dump(PDBSymDumper &Dumper) const = 0;
78 
79  /// For certain PDBSymbolTypes, dumps additional information for the type that
80  /// normally goes on the right side of the symbol.
81  virtual void dumpRight(PDBSymDumper &Dumper) const {}
82 
83  void defaultDump(raw_ostream &OS, int Indent) const;
84  void dumpProperties() const;
85  void dumpChildStats() const;
86 
87  PDB_SymType getSymTag() const;
88  uint32_t getSymIndexId() const;
89 
90  template <typename T> std::unique_ptr<T> findOneChild() const {
91  auto Enumerator(findAllChildren<T>());
92  if (!Enumerator)
93  return nullptr;
94  return Enumerator->getNext();
95  }
96 
97  std::unique_ptr<PDBSymbol> clone() const;
98 
99  template <typename T>
100  std::unique_ptr<ConcreteSymbolEnumerator<T>> findAllChildren() const {
101  auto BaseIter = RawSymbol->findChildren(T::Tag);
102  if (!BaseIter)
103  return nullptr;
104  return llvm::make_unique<ConcreteSymbolEnumerator<T>>(std::move(BaseIter));
105  }
106  std::unique_ptr<IPDBEnumSymbols> findAllChildren(PDB_SymType Type) const;
107  std::unique_ptr<IPDBEnumSymbols> findAllChildren() const;
108 
109  std::unique_ptr<IPDBEnumSymbols>
111  PDB_NameSearchFlags Flags) const;
112  std::unique_ptr<IPDBEnumSymbols> findChildrenByRVA(PDB_SymType Type,
113  StringRef Name,
114  PDB_NameSearchFlags Flags,
115  uint32_t RVA) const;
116  std::unique_ptr<IPDBEnumSymbols> findInlineFramesByRVA(uint32_t RVA) const;
117 
118  const IPDBRawSymbol &getRawSymbol() const { return *RawSymbol; }
120 
121  const IPDBSession &getSession() const { return Session; }
122 
123  std::unique_ptr<IPDBEnumSymbols> getChildStats(TagStats &Stats) const;
124 
125 protected:
126  std::unique_ptr<PDBSymbol> getSymbolByIdHelper(uint32_t Id) const;
127 
128  template <typename ConcreteType>
129  std::unique_ptr<ConcreteType> getConcreteSymbolByIdHelper(uint32_t Id) const {
130  return unique_dyn_cast_or_null<ConcreteType>(getSymbolByIdHelper(Id));
131  }
132 
134  std::unique_ptr<IPDBRawSymbol> RawSymbol;
135 };
136 
137 } // namespace llvm
138 }
139 
140 #endif
void defaultDump(raw_ostream &OS, int Indent) const
Definition: PDBSymbol.cpp:106
IPDBSession defines an interface used to provide a context for querying debug information from a debu...
Definition: IPDBSession.h:26
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
const IPDBSession & getSession() const
Definition: PDBSymbol.h:121
virtual void dumpRight(PDBSymDumper &Dumper) const
For certain PDBSymbolTypes, dumps additional information for the type that normally goes on the right...
Definition: PDBSymbol.h:81
PDB_NameSearchFlags
Defines flags used for enumerating child symbols.
Definition: PDBTypes.h:92
IPDBRawSymbol & getRawSymbol()
Definition: PDBSymbol.h:119
std::unique_ptr< T > findOneChild() const
Definition: PDBSymbol.h:90
std::unique_ptr< ConcreteSymbolEnumerator< T > > findAllChildren() const
Definition: PDBSymbol.h:100
std::unique_ptr< IPDBRawSymbol > RawSymbol
Definition: PDBSymbol.h:134
PDBSymbol(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > Symbol)
Definition: PDBSymbol.cpp:53
std::unordered_map< PDB_SymType, int > TagStats
Definition: PDBExtras.h:23
static std::unique_ptr< PDBSymbol > create(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > Symbol)
Definition: PDBSymbol.cpp:67
block placement Basic Block Placement Stats
std::unique_ptr< IPDBEnumSymbols > getChildStats(TagStats &Stats) const
Definition: PDBSymbol.cpp:160
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:162
std::unique_ptr< ConcreteType > getConcreteSymbolByIdHelper(uint32_t Id) const
Definition: PDBSymbol.h:129
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:32
std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags) const
Definition: PDBSymbol.cpp:143
std::unique_ptr< PDBSymbol > getSymbolByIdHelper(uint32_t Id) const
Definition: PDBSymbol.cpp:172
PDB_SymType getSymTag() const
Definition: PDBSymbol.cpp:130
PDBSymbol defines the base of the inheritance hierarchy for concrete symbol types (e...
Definition: PDBSymbol.h:61
const IPDBRawSymbol & getRawSymbol() const
Definition: PDBSymbol.h:118
virtual void dump(PDBSymDumper &Dumper) const =0
Dumps the contents of a symbol a raw_ostream.
const IPDBSession & Session
Definition: PDBSymbol.h:133
std::unique_ptr< IPDBEnumSymbols > findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, uint32_t RVA) const
Definition: PDBSymbol.cpp:149
void dumpProperties() const
Definition: PDBSymbol.cpp:110
std::unique_ptr< IPDBEnumSymbols > findInlineFramesByRVA(uint32_t RVA) const
Definition: PDBSymbol.cpp:155
uint32_t getSymIndexId() const
Definition: PDBSymbol.cpp:131
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
void dumpChildStats() const
Definition: PDBSymbol.cpp:116
std::unique_ptr< PDBSymbol > clone() const
Definition: PDBSymbol.cpp:126