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/ADT/StringRef.h"
19 #include "llvm/Support/Casting.h"
20 #include <unordered_map>
22 #define FORWARD_SYMBOL_METHOD(MethodName) \
23 auto MethodName() const->decltype(RawSymbol->MethodName()) { \
24 return RawSymbol->MethodName(); \
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; }
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
44 PDBSymbol(const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol);
47 static std::unique_ptr<PDBSymbol>
48 create(const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol);
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;
59 PDB_SymType getSymTag() const;
61 template <typename T> std::unique_ptr<T> findOneChild() const {
62 auto Enumerator(findAllChildren<T>());
63 return Enumerator->getNext();
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));
71 std::unique_ptr<IPDBEnumSymbols> findAllChildren(PDB_SymType Type) const;
72 std::unique_ptr<IPDBEnumSymbols> findAllChildren() const;
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,
79 PDB_NameSearchFlags Flags,
81 std::unique_ptr<IPDBEnumSymbols> findInlineFramesByRVA(uint32_t RVA) const;
83 const IPDBRawSymbol &getRawSymbol() const { return *RawSymbol; }
84 IPDBRawSymbol &getRawSymbol() { return *RawSymbol; }
86 const IPDBSession &getSession() const { return Session; }
88 std::unique_ptr<IPDBEnumSymbols> getChildStats(TagStats &Stats) const;
91 const IPDBSession &Session;
92 const std::unique_ptr<IPDBRawSymbol> RawSymbol;