PDBSymbol.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #ifndef LLVM_DEBUGINFO_PDB_IPDBSYMBOL_H
  10. #define LLVM_DEBUGINFO_PDB_IPDBSYMBOL_H
  11. #include "ConcreteSymbolEnumerator.h"
  12. #include "IPDBRawSymbol.h"
  13. #include "PDBExtras.h"
  14. #include "PDBTypes.h"
  15. #include "llvm/ADT/STLExtras.h"
  16. #include "llvm/ADT/StringRef.h"
  17. #include "llvm/Support/Casting.h"
  18. #include <unordered_map>
  19. #define FORWARD_SYMBOL_METHOD(MethodName) \
  20. auto MethodName() const->decltype(RawSymbol->MethodName()) { \
  21. return RawSymbol->MethodName(); \
  22. }
  23. namespace llvm {
  24. class IPDBRawSymbol;
  25. class raw_ostream;
  26. #define DECLARE_PDB_SYMBOL_CONCRETE_TYPE(TagValue) \
  27. static const PDB_SymType Tag = TagValue; \
  28. static bool classof(const PDBSymbol *S) { return S->getSymTag() == Tag; }
  29. /// PDBSymbol defines the base of the inheritance hierarchy for concrete symbol
  30. /// types (e.g. functions, executables, vtables, etc). All concrete symbol
  31. /// types inherit from PDBSymbol and expose the exact set of methods that are
  32. /// valid for that particular symbol type, as described in the Microsoft
  33. /// reference "Lexical and Class Hierarchy of Symbol Types":
  34. /// https://msdn.microsoft.com/en-us/library/370hs6k4.aspx
  35. class PDBSymbol {
  36. protected:
  37. PDBSymbol(const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol);
  38. public:
  39. static std::unique_ptr<PDBSymbol>
  40. create(const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol);
  41. virtual ~PDBSymbol();
  42. /// Dumps the contents of a symbol a raw_ostream. By default this will just
  43. /// call dump() on the underlying RawSymbol, which allows us to discover
  44. /// unknown properties, but individual implementations of PDBSymbol may
  45. /// override the behavior to only dump known fields.
  46. virtual void dump(PDBSymDumper &Dumper) const = 0;
  47. void defaultDump(raw_ostream &OS, int Indent) const;
  48. PDB_SymType getSymTag() const;
  49. template <typename T> std::unique_ptr<T> findOneChild() const {
  50. auto Enumerator(findAllChildren<T>());
  51. return Enumerator->getNext();
  52. }
  53. template <typename T>
  54. std::unique_ptr<ConcreteSymbolEnumerator<T>> findAllChildren() const {
  55. auto BaseIter = RawSymbol->findChildren(T::Tag);
  56. return llvm::make_unique<ConcreteSymbolEnumerator<T>>(std::move(BaseIter));
  57. }
  58. std::unique_ptr<IPDBEnumSymbols> findAllChildren(PDB_SymType Type) const;
  59. std::unique_ptr<IPDBEnumSymbols> findAllChildren() const;
  60. std::unique_ptr<IPDBEnumSymbols>
  61. findChildren(PDB_SymType Type, StringRef Name,
  62. PDB_NameSearchFlags Flags) const;
  63. std::unique_ptr<IPDBEnumSymbols> findChildrenByRVA(PDB_SymType Type,
  64. StringRef Name,
  65. PDB_NameSearchFlags Flags,
  66. uint32_t RVA) const;
  67. std::unique_ptr<IPDBEnumSymbols> findInlineFramesByRVA(uint32_t RVA) const;
  68. const IPDBRawSymbol &getRawSymbol() const { return *RawSymbol; }
  69. IPDBRawSymbol &getRawSymbol() { return *RawSymbol; }
  70. const IPDBSession &getSession() const { return Session; }
  71. std::unique_ptr<IPDBEnumSymbols> getChildStats(TagStats &Stats) const;
  72. protected:
  73. const IPDBSession &Session;
  74. const std::unique_ptr<IPDBRawSymbol> RawSymbol;
  75. };
  76. } // namespace llvm
  77. #endif