• 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 
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 
PDBSymbol(const IPDBSession & PDBSession,std::unique_ptr<IPDBRawSymbol> Symbol)54 PDBSymbol::PDBSymbol(const IPDBSession &PDBSession,
55                      std::unique_ptr<IPDBRawSymbol> Symbol)
56     : Session(PDBSession), RawSymbol(std::move(Symbol)) {}
57 
~PDBSymbol()58 PDBSymbol::~PDBSymbol() {}
59 
60 #define FACTORY_SYMTAG_CASE(Tag, Type)                                         \
61   case PDB_SymType::Tag:                                                       \
62     return std::unique_ptr<PDBSymbol>(new Type(PDBSession, std::move(Symbol)));
63 
64 std::unique_ptr<PDBSymbol>
create(const IPDBSession & PDBSession,std::unique_ptr<IPDBRawSymbol> Symbol)65 PDBSymbol::create(const IPDBSession &PDBSession,
66                   std::unique_ptr<IPDBRawSymbol> Symbol) {
67   switch (Symbol->getSymTag()) {
68     FACTORY_SYMTAG_CASE(Exe, PDBSymbolExe)
69     FACTORY_SYMTAG_CASE(Compiland, PDBSymbolCompiland)
70     FACTORY_SYMTAG_CASE(CompilandDetails, PDBSymbolCompilandDetails)
71     FACTORY_SYMTAG_CASE(CompilandEnv, PDBSymbolCompilandEnv)
72     FACTORY_SYMTAG_CASE(Function, PDBSymbolFunc)
73     FACTORY_SYMTAG_CASE(Block, PDBSymbolBlock)
74     FACTORY_SYMTAG_CASE(Data, PDBSymbolData)
75     FACTORY_SYMTAG_CASE(Annotation, PDBSymbolAnnotation)
76     FACTORY_SYMTAG_CASE(Label, PDBSymbolLabel)
77     FACTORY_SYMTAG_CASE(PublicSymbol, PDBSymbolPublicSymbol)
78     FACTORY_SYMTAG_CASE(UDT, PDBSymbolTypeUDT)
79     FACTORY_SYMTAG_CASE(Enum, PDBSymbolTypeEnum)
80     FACTORY_SYMTAG_CASE(FunctionSig, PDBSymbolTypeFunctionSig)
81     FACTORY_SYMTAG_CASE(PointerType, PDBSymbolTypePointer)
82     FACTORY_SYMTAG_CASE(ArrayType, PDBSymbolTypeArray)
83     FACTORY_SYMTAG_CASE(BuiltinType, PDBSymbolTypeBuiltin)
84     FACTORY_SYMTAG_CASE(Typedef, PDBSymbolTypeTypedef)
85     FACTORY_SYMTAG_CASE(BaseClass, PDBSymbolTypeBaseClass)
86     FACTORY_SYMTAG_CASE(Friend, PDBSymbolTypeFriend)
87     FACTORY_SYMTAG_CASE(FunctionArg, PDBSymbolTypeFunctionArg)
88     FACTORY_SYMTAG_CASE(FuncDebugStart, PDBSymbolFuncDebugStart)
89     FACTORY_SYMTAG_CASE(FuncDebugEnd, PDBSymbolFuncDebugEnd)
90     FACTORY_SYMTAG_CASE(UsingNamespace, PDBSymbolUsingNamespace)
91     FACTORY_SYMTAG_CASE(VTableShape, PDBSymbolTypeVTableShape)
92     FACTORY_SYMTAG_CASE(VTable, PDBSymbolTypeVTable)
93     FACTORY_SYMTAG_CASE(Custom, PDBSymbolCustom)
94     FACTORY_SYMTAG_CASE(Thunk, PDBSymbolThunk)
95     FACTORY_SYMTAG_CASE(CustomType, PDBSymbolTypeCustom)
96     FACTORY_SYMTAG_CASE(ManagedType, PDBSymbolTypeManaged)
97     FACTORY_SYMTAG_CASE(Dimension, PDBSymbolTypeDimension)
98   default:
99     return std::unique_ptr<PDBSymbol>(
100         new PDBSymbolUnknown(PDBSession, std::move(Symbol)));
101   }
102 }
103 
104 #define TRY_DUMP_TYPE(Type)                                                    \
105   if (const Type *DerivedThis = dyn_cast<Type>(this))                          \
106     Dumper.dump(OS, Indent, *DerivedThis);
107 
108 #define ELSE_TRY_DUMP_TYPE(Type, Dumper) else TRY_DUMP_TYPE(Type, Dumper)
109 
defaultDump(raw_ostream & OS,int Indent) const110 void PDBSymbol::defaultDump(raw_ostream &OS, int Indent) const {
111   RawSymbol->dump(OS, Indent);
112 }
113 
getSymTag() const114 PDB_SymType PDBSymbol::getSymTag() const { return RawSymbol->getSymTag(); }
115 
findAllChildren() const116 std::unique_ptr<IPDBEnumSymbols> PDBSymbol::findAllChildren() const {
117   return findAllChildren(PDB_SymType::None);
118 }
119 
120 std::unique_ptr<IPDBEnumSymbols>
findAllChildren(PDB_SymType Type) const121 PDBSymbol::findAllChildren(PDB_SymType Type) const {
122   return RawSymbol->findChildren(Type);
123 }
124 
125 std::unique_ptr<IPDBEnumSymbols>
findChildren(PDB_SymType Type,StringRef Name,PDB_NameSearchFlags Flags) const126 PDBSymbol::findChildren(PDB_SymType Type, StringRef Name,
127                         PDB_NameSearchFlags Flags) const {
128   return RawSymbol->findChildren(Type, Name, Flags);
129 }
130 
131 std::unique_ptr<IPDBEnumSymbols>
findChildrenByRVA(PDB_SymType Type,StringRef Name,PDB_NameSearchFlags Flags,uint32_t RVA) const132 PDBSymbol::findChildrenByRVA(PDB_SymType Type, StringRef Name,
133                              PDB_NameSearchFlags Flags, uint32_t RVA) const {
134   return RawSymbol->findChildrenByRVA(Type, Name, Flags, RVA);
135 }
136 
137 std::unique_ptr<IPDBEnumSymbols>
findInlineFramesByRVA(uint32_t RVA) const138 PDBSymbol::findInlineFramesByRVA(uint32_t RVA) const {
139   return RawSymbol->findInlineFramesByRVA(RVA);
140 }
141 
142 std::unique_ptr<IPDBEnumSymbols>
getChildStats(TagStats & Stats) const143 PDBSymbol::getChildStats(TagStats &Stats) const {
144   std::unique_ptr<IPDBEnumSymbols> Result(findAllChildren());
145   Stats.clear();
146   while (auto Child = Result->getNext()) {
147     ++Stats[Child->getSymTag()];
148   }
149   Result->reset();
150   return Result;
151 }
152