LLVM  4.0.0
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_IPDBSYMBOL_H
11 #define LLVM_DEBUGINFO_PDB_IPDBSYMBOL_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 namespace llvm {
26 
27 class StringRef;
28 class raw_ostream;
29 
30 namespace pdb {
31 class IPDBRawSymbol;
32 
33 #define DECLARE_PDB_SYMBOL_CONCRETE_TYPE(TagValue) \
34  static const PDB_SymType Tag = TagValue; \
35  static bool classof(const PDBSymbol *S) { return S->getSymTag() == Tag; }
36 
37 /// PDBSymbol defines the base of the inheritance hierarchy for concrete symbol
38 /// types (e.g. functions, executables, vtables, etc). All concrete symbol
39 /// types inherit from PDBSymbol and expose the exact set of methods that are
40 /// valid for that particular symbol type, as described in the Microsoft
41 /// reference "Lexical and Class Hierarchy of Symbol Types":
42 /// https://msdn.microsoft.com/en-us/library/370hs6k4.aspx
43 class PDBSymbol {
44 protected:
45  PDBSymbol(const IPDBSession &PDBSession,
46  std::unique_ptr<IPDBRawSymbol> Symbol);
47 
48 public:
49  static std::unique_ptr<PDBSymbol>
50  create(const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol);
51 
52  virtual ~PDBSymbol();
53 
54  /// Dumps the contents of a symbol a raw_ostream. By default this will just
55  /// call dump() on the underlying RawSymbol, which allows us to discover
56  /// unknown properties, but individual implementations of PDBSymbol may
57  /// override the behavior to only dump known fields.
58  virtual void dump(PDBSymDumper &Dumper) const = 0;
59  void defaultDump(raw_ostream &OS, int Indent) const;
60 
61  PDB_SymType getSymTag() const;
62  uint32_t getSymIndexId() const;
63 
64  template <typename T> std::unique_ptr<T> findOneChild() const {
65  auto Enumerator(findAllChildren<T>());
66  return Enumerator->getNext();
67  }
68 
69  template <typename T>
70  std::unique_ptr<ConcreteSymbolEnumerator<T>> findAllChildren() const {
71  auto BaseIter = RawSymbol->findChildren(T::Tag);
72  return llvm::make_unique<ConcreteSymbolEnumerator<T>>(std::move(BaseIter));
73  }
74  std::unique_ptr<IPDBEnumSymbols> findAllChildren(PDB_SymType Type) const;
75  std::unique_ptr<IPDBEnumSymbols> findAllChildren() const;
76 
77  std::unique_ptr<IPDBEnumSymbols>
80  std::unique_ptr<IPDBEnumSymbols> findChildrenByRVA(PDB_SymType Type,
83  uint32_t RVA) const;
84  std::unique_ptr<IPDBEnumSymbols> findInlineFramesByRVA(uint32_t RVA) const;
85 
86  const IPDBRawSymbol &getRawSymbol() const { return *RawSymbol; }
88 
89  const IPDBSession &getSession() const { return Session; }
90 
91  std::unique_ptr<IPDBEnumSymbols> getChildStats(TagStats &Stats) const;
92 
93 protected:
95  const std::unique_ptr<IPDBRawSymbol> RawSymbol;
96 };
97 
98 } // namespace llvm
99 }
100 
101 #endif
const IPDBSession & getSession() const
Definition: PDBSymbol.h:89
IPDBSession defines an interface used to provide a context for querying debug information from a debu...
Definition: IPDBSession.h:25
std::unique_ptr< ConcreteSymbolEnumerator< T > > findAllChildren() const
Definition: PDBSymbol.h:70
PDB_NameSearchFlags
Defines flags used for enumerating child symbols.
Definition: PDBTypes.h:91
IPDBRawSymbol & getRawSymbol()
Definition: PDBSymbol.h:87
std::unique_ptr< IPDBEnumSymbols > findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, uint32_t RVA) const
Definition: PDBSymbol.cpp:131
const std::unique_ptr< IPDBRawSymbol > RawSymbol
Definition: PDBSymbol.h:95
PDBSymbol(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > Symbol)
Definition: PDBSymbol.cpp:52
struct fuzzer::@269 Flags
static std::unique_ptr< PDBSymbol > create(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > Symbol)
Definition: PDBSymbol.cpp:63
block placement Basic Block Placement Stats
std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags) const
Definition: PDBSymbol.cpp:125
void defaultDump(raw_ostream &OS, int Indent) const
Definition: PDBSymbol.cpp:108
std::unique_ptr< IPDBEnumSymbols > findInlineFramesByRVA(uint32_t RVA) const
Definition: PDBSymbol.cpp:137
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
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
std::unique_ptr< IPDBEnumSymbols > getChildStats(TagStats &Stats) const
Definition: PDBSymbol.cpp:142
std::unique_ptr< T > findOneChild() const
Definition: PDBSymbol.h:64
IPDBRawSymbol defines an interface used to represent an arbitrary symbol.
Definition: IPDBRawSymbol.h:29
PDB_SymType getSymTag() const
Definition: PDBSymbol.cpp:112
PDBSymbol defines the base of the inheritance hierarchy for concrete symbol types (e...
Definition: PDBSymbol.h:43
virtual void dump(PDBSymDumper &Dumper) const =0
Dumps the contents of a symbol a raw_ostream.
const IPDBRawSymbol & getRawSymbol() const
Definition: PDBSymbol.h:86
const IPDBSession & Session
Definition: PDBSymbol.h:94
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:47
std::unordered_map< PDB_SymType, int > TagStats
Definition: PDBExtras.h:21
uint32_t getSymIndexId() const
Definition: PDBSymbol.cpp:113