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