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 13 #include "ConcreteSymbolEnumerator.h" 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 findOneChild()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> findAllChildren()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> 78 findChildren(PDB_SymType Type, StringRef Name, 79 PDB_NameSearchFlags Flags) const; 80 std::unique_ptr<IPDBEnumSymbols> findChildrenByRVA(PDB_SymType Type, 81 StringRef Name, 82 PDB_NameSearchFlags Flags, 83 uint32_t RVA) const; 84 std::unique_ptr<IPDBEnumSymbols> findInlineFramesByRVA(uint32_t RVA) const; 85 getRawSymbol()86 const IPDBRawSymbol &getRawSymbol() const { return *RawSymbol; } getRawSymbol()87 IPDBRawSymbol &getRawSymbol() { return *RawSymbol; } 88 getSession()89 const IPDBSession &getSession() const { return Session; } 90 91 std::unique_ptr<IPDBEnumSymbols> getChildStats(TagStats &Stats) const; 92 93 protected: 94 const IPDBSession &Session; 95 const std::unique_ptr<IPDBRawSymbol> RawSymbol; 96 }; 97 98 } // namespace llvm 99 } 100 101 #endif 102