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_IPDBSYMBOL_H
11 #define LLVM_DEBUGINFO_PDB_IPDBSYMBOL_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(); \
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; }
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
45 PDBSymbol(const IPDBSession &PDBSession,
46 std::unique_ptr<IPDBRawSymbol> Symbol);
49 static std::unique_ptr<PDBSymbol>
50 create(const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol);
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;
61 PDB_SymType getSymTag() const;
62 uint32_t getSymIndexId() const;
64 template <typename T> std::unique_ptr<T> findOneChild() const {
65 auto Enumerator(findAllChildren<T>());
66 return Enumerator->getNext();
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));
74 std::unique_ptr<IPDBEnumSymbols> findAllChildren(PDB_SymType Type) const;
75 std::unique_ptr<IPDBEnumSymbols> findAllChildren() const;
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,
82 PDB_NameSearchFlags Flags,
84 std::unique_ptr<IPDBEnumSymbols> findInlineFramesByRVA(uint32_t RVA) const;
86 const IPDBRawSymbol &getRawSymbol() const { return *RawSymbol; }
87 IPDBRawSymbol &getRawSymbol() { return *RawSymbol; }
89 const IPDBSession &getSession() const { return Session; }
91 std::unique_ptr<IPDBEnumSymbols> getChildStats(TagStats &Stats) const;
94 const IPDBSession &Session;
95 const std::unique_ptr<IPDBRawSymbol> RawSymbol;