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 <unordered_map>
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Support/Casting.h"
19 #include "ConcreteSymbolEnumerator.h"
20 #include "IPDBRawSymbol.h"
21 #include "PDBExtras.h"
24 #define FORWARD_SYMBOL_METHOD(MethodName) \
25 auto MethodName() const->decltype(RawSymbol->MethodName()) { \
26 return RawSymbol->MethodName(); \
34 #define DECLARE_PDB_SYMBOL_CONCRETE_TYPE(TagValue) \
35 static const PDB_SymType Tag = TagValue; \
36 static bool classof(const PDBSymbol *S) { return S->getSymTag() == Tag; }
38 /// PDBSymbol defines the base of the inheritance hierarchy for concrete symbol
39 /// types (e.g. functions, executables, vtables, etc). All concrete symbol
40 /// types inherit from PDBSymbol and expose the exact set of methods that are
41 /// valid for that particular symbol type, as described in the Microsoft
42 /// reference "Lexical and Class Hierarchy of Symbol Types":
43 /// https://msdn.microsoft.com/en-us/library/370hs6k4.aspx
46 PDBSymbol(const IPDBSession &PDBSession, 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(raw_ostream &OS, int Indent, PDB_DumpLevel Level) const = 0;
59 void defaultDump(raw_ostream &OS, int Indent, PDB_DumpLevel Level) const;
61 PDB_SymType getSymTag() const;
63 template <typename T> std::unique_ptr<T> findOneChild() const {
64 auto Enumerator(findAllChildren<T>());
65 return Enumerator->getNext();
69 std::unique_ptr<ConcreteSymbolEnumerator<T>> findAllChildren() const {
70 auto BaseIter = RawSymbol->findChildren(T::Tag);
71 return llvm::make_unique<ConcreteSymbolEnumerator<T>>(std::move(BaseIter));
74 std::unique_ptr<IPDBEnumSymbols> findAllChildren() const;
75 std::unique_ptr<IPDBEnumSymbols>
76 findChildren(PDB_SymType Type, StringRef Name,
77 PDB_NameSearchFlags Flags) const;
78 std::unique_ptr<IPDBEnumSymbols> findChildrenByRVA(PDB_SymType Type,
80 PDB_NameSearchFlags Flags,
82 std::unique_ptr<IPDBEnumSymbols> findInlineFramesByRVA(uint32_t RVA) const;
84 const IPDBRawSymbol &getRawSymbol() const { return *RawSymbol; }
85 IPDBRawSymbol &getRawSymbol() { return *RawSymbol; }
88 std::unique_ptr<IPDBEnumSymbols> getChildStats(TagStats &Stats) const;
90 const IPDBSession &Session;
91 const std::unique_ptr<IPDBRawSymbol> RawSymbol;