Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:46

0001 //===- PDBSymbol.h - base class for user-facing symbol types -----*- C++-*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOL_H
0010 #define LLVM_DEBUGINFO_PDB_PDBSYMBOL_H
0011 
0012 #include "IPDBRawSymbol.h"
0013 #include "PDBExtras.h"
0014 #include "PDBTypes.h"
0015 #include "llvm/Support/Casting.h"
0016 
0017 #define FORWARD_SYMBOL_METHOD(MethodName)                                      \
0018   decltype(auto) MethodName() const { return RawSymbol->MethodName(); }
0019 
0020 #define FORWARD_CONCRETE_SYMBOL_ID_METHOD_WITH_NAME(ConcreteType, PrivateName, \
0021                                                     PublicName)                \
0022   decltype(auto) PublicName##Id() const {                                      \
0023     return RawSymbol->PrivateName##Id();                                       \
0024   }                                                                            \
0025   std::unique_ptr<ConcreteType> PublicName() const {                           \
0026     uint32_t Id = PublicName##Id();                                            \
0027     return getConcreteSymbolByIdHelper<ConcreteType>(Id);                      \
0028   }
0029 
0030 #define FORWARD_SYMBOL_ID_METHOD_WITH_NAME(PrivateName, PublicName)            \
0031   FORWARD_CONCRETE_SYMBOL_ID_METHOD_WITH_NAME(PDBSymbol, PrivateName,          \
0032                                               PublicName)
0033 
0034 #define FORWARD_SYMBOL_ID_METHOD(MethodName)                                   \
0035   FORWARD_SYMBOL_ID_METHOD_WITH_NAME(MethodName, MethodName)
0036 
0037 namespace llvm {
0038 
0039 class StringRef;
0040 class raw_ostream;
0041 
0042 namespace pdb {
0043 class IPDBSession;
0044 class PDBSymDumper;
0045 class PDBSymbol;
0046 template <typename ChildType> class ConcreteSymbolEnumerator;
0047 
0048 #define DECLARE_PDB_SYMBOL_CONCRETE_TYPE(TagValue)                             \
0049 private:                                                                       \
0050   using PDBSymbol::PDBSymbol;                                                  \
0051   friend class PDBSymbol;                                                      \
0052                                                                                \
0053 public:                                                                        \
0054   static const PDB_SymType Tag = TagValue;                                     \
0055   static bool classof(const PDBSymbol *S) { return S->getSymTag() == Tag; }
0056 
0057 #define DECLARE_PDB_SYMBOL_CUSTOM_TYPE(Condition)                              \
0058 private:                                                                       \
0059   using PDBSymbol::PDBSymbol;                                                  \
0060   friend class PDBSymbol;                                                      \
0061                                                                                \
0062 public:                                                                        \
0063   static bool classof(const PDBSymbol *S) { return Condition; }
0064 
0065 /// PDBSymbol defines the base of the inheritance hierarchy for concrete symbol
0066 /// types (e.g. functions, executables, vtables, etc).  All concrete symbol
0067 /// types inherit from PDBSymbol and expose the exact set of methods that are
0068 /// valid for that particular symbol type, as described in the Microsoft
0069 /// reference "Lexical and Class Hierarchy of Symbol Types":
0070 /// https://msdn.microsoft.com/en-us/library/370hs6k4.aspx
0071 class PDBSymbol {
0072   static std::unique_ptr<PDBSymbol> createSymbol(const IPDBSession &PDBSession,
0073                                                  PDB_SymType Tag);
0074 
0075 protected:
0076   explicit PDBSymbol(const IPDBSession &PDBSession);
0077   PDBSymbol(PDBSymbol &&Other);
0078 
0079 public:
0080   static std::unique_ptr<PDBSymbol>
0081   create(const IPDBSession &PDBSession,
0082          std::unique_ptr<IPDBRawSymbol> RawSymbol);
0083   static std::unique_ptr<PDBSymbol> create(const IPDBSession &PDBSession,
0084                                            IPDBRawSymbol &RawSymbol);
0085 
0086   template <typename ConcreteT>
0087   static std::unique_ptr<ConcreteT>
0088   createAs(const IPDBSession &PDBSession,
0089            std::unique_ptr<IPDBRawSymbol> RawSymbol) {
0090     std::unique_ptr<PDBSymbol> S = create(PDBSession, std::move(RawSymbol));
0091     return unique_dyn_cast_or_null<ConcreteT>(std::move(S));
0092   }
0093   template <typename ConcreteT>
0094   static std::unique_ptr<ConcreteT> createAs(const IPDBSession &PDBSession,
0095                                              IPDBRawSymbol &RawSymbol) {
0096     std::unique_ptr<PDBSymbol> S = create(PDBSession, RawSymbol);
0097     return unique_dyn_cast_or_null<ConcreteT>(std::move(S));
0098   }
0099 
0100   virtual ~PDBSymbol();
0101 
0102   /// Dumps the contents of a symbol a raw_ostream.  By default this will just
0103   /// call dump() on the underlying RawSymbol, which allows us to discover
0104   /// unknown properties, but individual implementations of PDBSymbol may
0105   /// override the behavior to only dump known fields.
0106   virtual void dump(PDBSymDumper &Dumper) const = 0;
0107 
0108   /// For certain PDBSymbolTypes, dumps additional information for the type that
0109   /// normally goes on the right side of the symbol.
0110   virtual void dumpRight(PDBSymDumper &Dumper) const {}
0111 
0112   void defaultDump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowFlags,
0113                    PdbSymbolIdField RecurseFlags) const;
0114   void dumpProperties() const;
0115   void dumpChildStats() const;
0116 
0117   PDB_SymType getSymTag() const;
0118   uint32_t getSymIndexId() const;
0119 
0120   template <typename T> std::unique_ptr<T> findOneChild() const {
0121     auto Enumerator(findAllChildren<T>());
0122     if (!Enumerator)
0123       return nullptr;
0124     return Enumerator->getNext();
0125   }
0126 
0127   template <typename T>
0128   std::unique_ptr<ConcreteSymbolEnumerator<T>> findAllChildren() const {
0129     auto BaseIter = RawSymbol->findChildren(T::Tag);
0130     if (!BaseIter)
0131       return nullptr;
0132     return std::make_unique<ConcreteSymbolEnumerator<T>>(std::move(BaseIter));
0133   }
0134   std::unique_ptr<IPDBEnumSymbols> findAllChildren(PDB_SymType Type) const;
0135   std::unique_ptr<IPDBEnumSymbols> findAllChildren() const;
0136 
0137   std::unique_ptr<IPDBEnumSymbols>
0138   findChildren(PDB_SymType Type, StringRef Name,
0139                PDB_NameSearchFlags Flags) const;
0140   std::unique_ptr<IPDBEnumSymbols> findChildrenByRVA(PDB_SymType Type,
0141                                                      StringRef Name,
0142                                                      PDB_NameSearchFlags Flags,
0143                                                      uint32_t RVA) const;
0144   std::unique_ptr<IPDBEnumSymbols> findInlineFramesByVA(uint64_t VA) const;
0145   std::unique_ptr<IPDBEnumSymbols> findInlineFramesByRVA(uint32_t RVA) const;
0146   std::unique_ptr<IPDBEnumLineNumbers>
0147   findInlineeLinesByVA(uint64_t VA, uint32_t Length) const;
0148   std::unique_ptr<IPDBEnumLineNumbers>
0149   findInlineeLinesByRVA(uint32_t RVA, uint32_t Length) const;
0150 
0151   std::string getName() const;
0152 
0153   const IPDBRawSymbol &getRawSymbol() const { return *RawSymbol; }
0154   IPDBRawSymbol &getRawSymbol() { return *RawSymbol; }
0155 
0156   const IPDBSession &getSession() const { return Session; }
0157 
0158   std::unique_ptr<IPDBEnumSymbols> getChildStats(TagStats &Stats) const;
0159 
0160 protected:
0161   std::unique_ptr<PDBSymbol> getSymbolByIdHelper(uint32_t Id) const;
0162 
0163   template <typename ConcreteType>
0164   std::unique_ptr<ConcreteType> getConcreteSymbolByIdHelper(uint32_t Id) const {
0165     return unique_dyn_cast_or_null<ConcreteType>(getSymbolByIdHelper(Id));
0166   }
0167 
0168   const IPDBSession &Session;
0169   std::unique_ptr<IPDBRawSymbol> OwnedRawSymbol;
0170   IPDBRawSymbol *RawSymbol = nullptr;
0171 };
0172 
0173 } // namespace llvm
0174 }
0175 
0176 #endif