1 //===- PDBSymbol.cpp - 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 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
11
12 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
13 #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
14 #include "llvm/DebugInfo/PDB/PDBSymbolAnnotation.h"
15 #include "llvm/DebugInfo/PDB/PDBSymbolBlock.h"
16 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h"
18 #include "llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h"
19 #include "llvm/DebugInfo/PDB/PDBSymbolCustom.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
22 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
23 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
24 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
25 #include "llvm/DebugInfo/PDB/PDBSymbolLabel.h"
26 #include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
27 #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
28 #include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h"
29 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
30 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
31 #include "llvm/DebugInfo/PDB/PDBSymbolTypeCustom.h"
32 #include "llvm/DebugInfo/PDB/PDBSymbolTypeDimension.h"
33 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
34 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFriend.h"
35 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h"
36 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
37 #include "llvm/DebugInfo/PDB/PDBSymbolTypeManaged.h"
38 #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
39 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
40 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
41 #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h"
42 #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h"
43 #include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h"
44 #include "llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h"
45 #include "llvm/DebugInfo/PDB/PDBSymDumper.h"
46 #include <memory>
47 #include <utility>
48
49 #include <memory>
50 #include <utility>
51
52 using namespace llvm;
53 using namespace llvm::pdb;
54
PDBSymbol(const IPDBSession & PDBSession,std::unique_ptr<IPDBRawSymbol> Symbol)55 PDBSymbol::PDBSymbol(const IPDBSession &PDBSession,
56 std::unique_ptr<IPDBRawSymbol> Symbol)
57 : Session(PDBSession), RawSymbol(std::move(Symbol)) {}
58
~PDBSymbol()59 PDBSymbol::~PDBSymbol() {}
60
61 #define FACTORY_SYMTAG_CASE(Tag, Type) \
62 case PDB_SymType::Tag: \
63 return std::unique_ptr<PDBSymbol>(new Type(PDBSession, std::move(Symbol)));
64
65 std::unique_ptr<PDBSymbol>
create(const IPDBSession & PDBSession,std::unique_ptr<IPDBRawSymbol> Symbol)66 PDBSymbol::create(const IPDBSession &PDBSession,
67 std::unique_ptr<IPDBRawSymbol> Symbol) {
68 switch (Symbol->getSymTag()) {
69 FACTORY_SYMTAG_CASE(Exe, PDBSymbolExe)
70 FACTORY_SYMTAG_CASE(Compiland, PDBSymbolCompiland)
71 FACTORY_SYMTAG_CASE(CompilandDetails, PDBSymbolCompilandDetails)
72 FACTORY_SYMTAG_CASE(CompilandEnv, PDBSymbolCompilandEnv)
73 FACTORY_SYMTAG_CASE(Function, PDBSymbolFunc)
74 FACTORY_SYMTAG_CASE(Block, PDBSymbolBlock)
75 FACTORY_SYMTAG_CASE(Data, PDBSymbolData)
76 FACTORY_SYMTAG_CASE(Annotation, PDBSymbolAnnotation)
77 FACTORY_SYMTAG_CASE(Label, PDBSymbolLabel)
78 FACTORY_SYMTAG_CASE(PublicSymbol, PDBSymbolPublicSymbol)
79 FACTORY_SYMTAG_CASE(UDT, PDBSymbolTypeUDT)
80 FACTORY_SYMTAG_CASE(Enum, PDBSymbolTypeEnum)
81 FACTORY_SYMTAG_CASE(FunctionSig, PDBSymbolTypeFunctionSig)
82 FACTORY_SYMTAG_CASE(PointerType, PDBSymbolTypePointer)
83 FACTORY_SYMTAG_CASE(ArrayType, PDBSymbolTypeArray)
84 FACTORY_SYMTAG_CASE(BuiltinType, PDBSymbolTypeBuiltin)
85 FACTORY_SYMTAG_CASE(Typedef, PDBSymbolTypeTypedef)
86 FACTORY_SYMTAG_CASE(BaseClass, PDBSymbolTypeBaseClass)
87 FACTORY_SYMTAG_CASE(Friend, PDBSymbolTypeFriend)
88 FACTORY_SYMTAG_CASE(FunctionArg, PDBSymbolTypeFunctionArg)
89 FACTORY_SYMTAG_CASE(FuncDebugStart, PDBSymbolFuncDebugStart)
90 FACTORY_SYMTAG_CASE(FuncDebugEnd, PDBSymbolFuncDebugEnd)
91 FACTORY_SYMTAG_CASE(UsingNamespace, PDBSymbolUsingNamespace)
92 FACTORY_SYMTAG_CASE(VTableShape, PDBSymbolTypeVTableShape)
93 FACTORY_SYMTAG_CASE(VTable, PDBSymbolTypeVTable)
94 FACTORY_SYMTAG_CASE(Custom, PDBSymbolCustom)
95 FACTORY_SYMTAG_CASE(Thunk, PDBSymbolThunk)
96 FACTORY_SYMTAG_CASE(CustomType, PDBSymbolTypeCustom)
97 FACTORY_SYMTAG_CASE(ManagedType, PDBSymbolTypeManaged)
98 FACTORY_SYMTAG_CASE(Dimension, PDBSymbolTypeDimension)
99 default:
100 return std::unique_ptr<PDBSymbol>(
101 new PDBSymbolUnknown(PDBSession, std::move(Symbol)));
102 }
103 }
104
105 #define TRY_DUMP_TYPE(Type) \
106 if (const Type *DerivedThis = dyn_cast<Type>(this)) \
107 Dumper.dump(OS, Indent, *DerivedThis);
108
109 #define ELSE_TRY_DUMP_TYPE(Type, Dumper) else TRY_DUMP_TYPE(Type, Dumper)
110
defaultDump(raw_ostream & OS,int Indent) const111 void PDBSymbol::defaultDump(raw_ostream &OS, int Indent) const {
112 RawSymbol->dump(OS, Indent);
113 }
114
getSymTag() const115 PDB_SymType PDBSymbol::getSymTag() const { return RawSymbol->getSymTag(); }
getSymIndexId() const116 uint32_t PDBSymbol::getSymIndexId() const { return RawSymbol->getSymIndexId(); }
117
findAllChildren() const118 std::unique_ptr<IPDBEnumSymbols> PDBSymbol::findAllChildren() const {
119 return findAllChildren(PDB_SymType::None);
120 }
121
122 std::unique_ptr<IPDBEnumSymbols>
findAllChildren(PDB_SymType Type) const123 PDBSymbol::findAllChildren(PDB_SymType Type) const {
124 return RawSymbol->findChildren(Type);
125 }
126
127 std::unique_ptr<IPDBEnumSymbols>
findChildren(PDB_SymType Type,StringRef Name,PDB_NameSearchFlags Flags) const128 PDBSymbol::findChildren(PDB_SymType Type, StringRef Name,
129 PDB_NameSearchFlags Flags) const {
130 return RawSymbol->findChildren(Type, Name, Flags);
131 }
132
133 std::unique_ptr<IPDBEnumSymbols>
findChildrenByRVA(PDB_SymType Type,StringRef Name,PDB_NameSearchFlags Flags,uint32_t RVA) const134 PDBSymbol::findChildrenByRVA(PDB_SymType Type, StringRef Name,
135 PDB_NameSearchFlags Flags, uint32_t RVA) const {
136 return RawSymbol->findChildrenByRVA(Type, Name, Flags, RVA);
137 }
138
139 std::unique_ptr<IPDBEnumSymbols>
findInlineFramesByRVA(uint32_t RVA) const140 PDBSymbol::findInlineFramesByRVA(uint32_t RVA) const {
141 return RawSymbol->findInlineFramesByRVA(RVA);
142 }
143
144 std::unique_ptr<IPDBEnumSymbols>
getChildStats(TagStats & Stats) const145 PDBSymbol::getChildStats(TagStats &Stats) const {
146 std::unique_ptr<IPDBEnumSymbols> Result(findAllChildren());
147 Stats.clear();
148 while (auto Child = Result->getNext()) {
149 ++Stats[Child->getSymTag()];
150 }
151 Result->reset();
152 return Result;
153 }
154