• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
12 #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
13 #include "llvm/DebugInfo/PDB/IPDBSession.h"
14 #include "llvm/DebugInfo/PDB/PDBExtras.h"
15 #include "llvm/DebugInfo/PDB/PDBSymbolAnnotation.h"
16 #include "llvm/DebugInfo/PDB/PDBSymbolBlock.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
18 #include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h"
19 #include "llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolCustom.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
22 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
23 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
24 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
25 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
26 #include "llvm/DebugInfo/PDB/PDBSymbolLabel.h"
27 #include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
28 #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
29 #include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h"
30 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
31 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
32 #include "llvm/DebugInfo/PDB/PDBSymbolTypeCustom.h"
33 #include "llvm/DebugInfo/PDB/PDBSymbolTypeDimension.h"
34 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
35 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFriend.h"
36 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h"
37 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
38 #include "llvm/DebugInfo/PDB/PDBSymbolTypeManaged.h"
39 #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
40 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
41 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
42 #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h"
43 #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h"
44 #include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h"
45 #include "llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h"
46 #include "llvm/DebugInfo/PDB/PDBTypes.h"
47 #include <algorithm>
48 #include <memory>
49 
50 using namespace llvm;
51 using namespace llvm::pdb;
52 
PDBSymbol(const IPDBSession & PDBSession,std::unique_ptr<IPDBRawSymbol> Symbol)53 PDBSymbol::PDBSymbol(const IPDBSession &PDBSession,
54                      std::unique_ptr<IPDBRawSymbol> Symbol)
55     : Session(PDBSession), RawSymbol(std::move(Symbol)) {}
56 
PDBSymbol(PDBSymbol & Symbol)57 PDBSymbol::PDBSymbol(PDBSymbol &Symbol)
58     : Session(Symbol.Session), RawSymbol(std::move(Symbol.RawSymbol)) {}
59 
60 PDBSymbol::~PDBSymbol() = default;
61 
62 #define FACTORY_SYMTAG_CASE(Tag, Type)                                         \
63   case PDB_SymType::Tag:                                                       \
64     return std::unique_ptr<PDBSymbol>(new Type(PDBSession, std::move(Symbol)));
65 
66 std::unique_ptr<PDBSymbol>
create(const IPDBSession & PDBSession,std::unique_ptr<IPDBRawSymbol> Symbol)67 PDBSymbol::create(const IPDBSession &PDBSession,
68                   std::unique_ptr<IPDBRawSymbol> Symbol) {
69   switch (Symbol->getSymTag()) {
70     FACTORY_SYMTAG_CASE(Exe, PDBSymbolExe)
71     FACTORY_SYMTAG_CASE(Compiland, PDBSymbolCompiland)
72     FACTORY_SYMTAG_CASE(CompilandDetails, PDBSymbolCompilandDetails)
73     FACTORY_SYMTAG_CASE(CompilandEnv, PDBSymbolCompilandEnv)
74     FACTORY_SYMTAG_CASE(Function, PDBSymbolFunc)
75     FACTORY_SYMTAG_CASE(Block, PDBSymbolBlock)
76     FACTORY_SYMTAG_CASE(Data, PDBSymbolData)
77     FACTORY_SYMTAG_CASE(Annotation, PDBSymbolAnnotation)
78     FACTORY_SYMTAG_CASE(Label, PDBSymbolLabel)
79     FACTORY_SYMTAG_CASE(PublicSymbol, PDBSymbolPublicSymbol)
80     FACTORY_SYMTAG_CASE(UDT, PDBSymbolTypeUDT)
81     FACTORY_SYMTAG_CASE(Enum, PDBSymbolTypeEnum)
82     FACTORY_SYMTAG_CASE(FunctionSig, PDBSymbolTypeFunctionSig)
83     FACTORY_SYMTAG_CASE(PointerType, PDBSymbolTypePointer)
84     FACTORY_SYMTAG_CASE(ArrayType, PDBSymbolTypeArray)
85     FACTORY_SYMTAG_CASE(BuiltinType, PDBSymbolTypeBuiltin)
86     FACTORY_SYMTAG_CASE(Typedef, PDBSymbolTypeTypedef)
87     FACTORY_SYMTAG_CASE(BaseClass, PDBSymbolTypeBaseClass)
88     FACTORY_SYMTAG_CASE(Friend, PDBSymbolTypeFriend)
89     FACTORY_SYMTAG_CASE(FunctionArg, PDBSymbolTypeFunctionArg)
90     FACTORY_SYMTAG_CASE(FuncDebugStart, PDBSymbolFuncDebugStart)
91     FACTORY_SYMTAG_CASE(FuncDebugEnd, PDBSymbolFuncDebugEnd)
92     FACTORY_SYMTAG_CASE(UsingNamespace, PDBSymbolUsingNamespace)
93     FACTORY_SYMTAG_CASE(VTableShape, PDBSymbolTypeVTableShape)
94     FACTORY_SYMTAG_CASE(VTable, PDBSymbolTypeVTable)
95     FACTORY_SYMTAG_CASE(Custom, PDBSymbolCustom)
96     FACTORY_SYMTAG_CASE(Thunk, PDBSymbolThunk)
97     FACTORY_SYMTAG_CASE(CustomType, PDBSymbolTypeCustom)
98     FACTORY_SYMTAG_CASE(ManagedType, PDBSymbolTypeManaged)
99     FACTORY_SYMTAG_CASE(Dimension, PDBSymbolTypeDimension)
100   default:
101     return std::unique_ptr<PDBSymbol>(
102         new PDBSymbolUnknown(PDBSession, std::move(Symbol)));
103   }
104 }
105 
defaultDump(raw_ostream & OS,int Indent) const106 void PDBSymbol::defaultDump(raw_ostream &OS, int Indent) const {
107   RawSymbol->dump(OS, Indent);
108 }
109 
dumpProperties() const110 void PDBSymbol::dumpProperties() const {
111   outs() << "\n";
112   defaultDump(outs(), 0);
113   outs().flush();
114 }
115 
dumpChildStats() const116 void PDBSymbol::dumpChildStats() const {
117   TagStats Stats;
118   getChildStats(Stats);
119   outs() << "\n";
120   for (auto &Stat : Stats) {
121     outs() << Stat.first << ": " << Stat.second << "\n";
122   }
123   outs().flush();
124 }
125 
clone() const126 std::unique_ptr<PDBSymbol> PDBSymbol::clone() const {
127   return Session.getSymbolById(getSymIndexId());
128 }
129 
getSymTag() const130 PDB_SymType PDBSymbol::getSymTag() const { return RawSymbol->getSymTag(); }
getSymIndexId() const131 uint32_t PDBSymbol::getSymIndexId() const { return RawSymbol->getSymIndexId(); }
132 
findAllChildren() const133 std::unique_ptr<IPDBEnumSymbols> PDBSymbol::findAllChildren() const {
134   return findAllChildren(PDB_SymType::None);
135 }
136 
137 std::unique_ptr<IPDBEnumSymbols>
findAllChildren(PDB_SymType Type) const138 PDBSymbol::findAllChildren(PDB_SymType Type) const {
139   return RawSymbol->findChildren(Type);
140 }
141 
142 std::unique_ptr<IPDBEnumSymbols>
findChildren(PDB_SymType Type,StringRef Name,PDB_NameSearchFlags Flags) const143 PDBSymbol::findChildren(PDB_SymType Type, StringRef Name,
144                         PDB_NameSearchFlags Flags) const {
145   return RawSymbol->findChildren(Type, Name, Flags);
146 }
147 
148 std::unique_ptr<IPDBEnumSymbols>
findChildrenByRVA(PDB_SymType Type,StringRef Name,PDB_NameSearchFlags Flags,uint32_t RVA) const149 PDBSymbol::findChildrenByRVA(PDB_SymType Type, StringRef Name,
150                              PDB_NameSearchFlags Flags, uint32_t RVA) const {
151   return RawSymbol->findChildrenByRVA(Type, Name, Flags, RVA);
152 }
153 
154 std::unique_ptr<IPDBEnumSymbols>
findInlineFramesByRVA(uint32_t RVA) const155 PDBSymbol::findInlineFramesByRVA(uint32_t RVA) const {
156   return RawSymbol->findInlineFramesByRVA(RVA);
157 }
158 
159 std::unique_ptr<IPDBEnumSymbols>
getChildStats(TagStats & Stats) const160 PDBSymbol::getChildStats(TagStats &Stats) const {
161   std::unique_ptr<IPDBEnumSymbols> Result(findAllChildren());
162   if (!Result)
163     return nullptr;
164   Stats.clear();
165   while (auto Child = Result->getNext()) {
166     ++Stats[Child->getSymTag()];
167   }
168   Result->reset();
169   return Result;
170 }
171 
getSymbolByIdHelper(uint32_t Id) const172 std::unique_ptr<PDBSymbol> PDBSymbol::getSymbolByIdHelper(uint32_t Id) const {
173   return Session.getSymbolById(Id);
174 }
175