1 //===- PDBSymbol.h - base class for user-facing symbol types -----*- C++-*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOL_H
11 #define LLVM_DEBUGINFO_PDB_PDBSYMBOL_H
13 #include "ConcreteSymbolEnumerator.h"
14 #include "IPDBRawSymbol.h"
15 #include "PDBExtras.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/Support/Casting.h"
20 #define FORWARD_SYMBOL_METHOD(MethodName) \
21 auto MethodName() const->decltype(RawSymbol->MethodName()) { \
22 return RawSymbol->MethodName(); \
25 #define FORWARD_CONCRETE_SYMBOL_ID_METHOD_WITH_NAME(ConcreteType, PrivateName, \
27 auto PublicName##Id() const->decltype(RawSymbol->PrivateName##Id()) { \
28 return RawSymbol->PrivateName##Id(); \
30 std::unique_ptr<ConcreteType> PublicName() const { \
31 uint32_t Id = PublicName##Id(); \
32 return getConcreteSymbolByIdHelper<ConcreteType>(Id); \
35 #define FORWARD_SYMBOL_ID_METHOD_WITH_NAME(PrivateName, PublicName) \
36 FORWARD_CONCRETE_SYMBOL_ID_METHOD_WITH_NAME(PDBSymbol, PrivateName, \
39 #define FORWARD_SYMBOL_ID_METHOD(MethodName) \
40 FORWARD_SYMBOL_ID_METHOD_WITH_NAME(MethodName, MethodName)
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; }
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
63 PDBSymbol(const IPDBSession &PDBSession,
64 std::unique_ptr<IPDBRawSymbol> Symbol);
65 PDBSymbol(PDBSymbol &Symbol);
68 static std::unique_ptr<PDBSymbol>
69 create(const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol);
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;
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 {}
83 void defaultDump(raw_ostream &OS, int Indent) const;
84 void dumpProperties() const;
85 void dumpChildStats() const;
87 PDB_SymType getSymTag() const;
88 uint32_t getSymIndexId() const;
90 template <typename T> std::unique_ptr<T> findOneChild() const {
91 auto Enumerator(findAllChildren<T>());
94 return Enumerator->getNext();
97 std::unique_ptr<PDBSymbol> clone() const;
100 std::unique_ptr<ConcreteSymbolEnumerator<T>> findAllChildren() const {
101 auto BaseIter = RawSymbol->findChildren(T::Tag);
104 return llvm::make_unique<ConcreteSymbolEnumerator<T>>(std::move(BaseIter));
106 std::unique_ptr<IPDBEnumSymbols> findAllChildren(PDB_SymType Type) const;
107 std::unique_ptr<IPDBEnumSymbols> findAllChildren() const;
109 std::unique_ptr<IPDBEnumSymbols>
110 findChildren(PDB_SymType Type, StringRef Name,
111 PDB_NameSearchFlags Flags) const;
112 std::unique_ptr<IPDBEnumSymbols> findChildrenByRVA(PDB_SymType Type,
114 PDB_NameSearchFlags Flags,
116 std::unique_ptr<IPDBEnumSymbols> findInlineFramesByRVA(uint32_t RVA) const;
118 const IPDBRawSymbol &getRawSymbol() const { return *RawSymbol; }
119 IPDBRawSymbol &getRawSymbol() { return *RawSymbol; }
121 const IPDBSession &getSession() const { return Session; }
123 std::unique_ptr<IPDBEnumSymbols> getChildStats(TagStats &Stats) const;
126 std::unique_ptr<PDBSymbol> getSymbolByIdHelper(uint32_t Id) const;
128 template <typename ConcreteType>
129 std::unique_ptr<ConcreteType> getConcreteSymbolByIdHelper(uint32_t Id) const {
130 return unique_dyn_cast_or_null<ConcreteType>(getSymbolByIdHelper(Id));
133 const IPDBSession &Session;
134 std::unique_ptr<IPDBRawSymbol> RawSymbol;