Home | History | Annotate | Download | only in PDB
      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/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>
     75   findChildren(PDB_SymType Type, StringRef Name,
     76                PDB_NameSearchFlags Flags) const;
     77   std::unique_ptr<IPDBEnumSymbols> findChildrenByRVA(PDB_SymType Type,
     78                                                      StringRef Name,
     79                                                      PDB_NameSearchFlags Flags,
     80                                                      uint32_t RVA) const;
     81   std::unique_ptr<IPDBEnumSymbols> findInlineFramesByRVA(uint32_t RVA) const;
     82 
     83   const IPDBRawSymbol &getRawSymbol() const { return *RawSymbol; }
     84   IPDBRawSymbol &getRawSymbol() { return *RawSymbol; }
     85 
     86   const IPDBSession &getSession() const { return Session; }
     87 
     88   std::unique_ptr<IPDBEnumSymbols> getChildStats(TagStats &Stats) const;
     89 
     90 protected:
     91   const IPDBSession &Session;
     92   const std::unique_ptr<IPDBRawSymbol> RawSymbol;
     93 };
     94 
     95 } // namespace llvm
     96 
     97 #endif
     98