LLVM  14.0.0git
PDBSymbol.cpp
Go to the documentation of this file.
1 //===- PDBSymbol.cpp - base class for user-facing symbol types --*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
46 #include <algorithm>
47 #include <memory>
48 
49 using namespace llvm;
50 using namespace llvm::pdb;
51 
52 PDBSymbol::PDBSymbol(const IPDBSession &PDBSession) : Session(PDBSession) {}
53 
55  : Session(Other.Session), RawSymbol(std::move(Other.RawSymbol)) {}
56 
57 PDBSymbol::~PDBSymbol() = default;
58 
59 #define FACTORY_SYMTAG_CASE(Tag, Type) \
60  case PDB_SymType::Tag: \
61  return std::unique_ptr<PDBSymbol>(new Type(PDBSession));
62 
63 std::unique_ptr<PDBSymbol>
64 PDBSymbol::createSymbol(const IPDBSession &PDBSession, PDB_SymType Tag) {
65  switch (Tag) {
96  default:
97  return std::unique_ptr<PDBSymbol>(new PDBSymbolUnknown(PDBSession));
98  }
99 }
100 
101 std::unique_ptr<PDBSymbol>
102 PDBSymbol::create(const IPDBSession &PDBSession,
103  std::unique_ptr<IPDBRawSymbol> RawSymbol) {
104  auto SymbolPtr = createSymbol(PDBSession, RawSymbol->getSymTag());
105  SymbolPtr->RawSymbol = RawSymbol.get();
106  SymbolPtr->OwnedRawSymbol = std::move(RawSymbol);
107  return SymbolPtr;
108 }
109 
110 std::unique_ptr<PDBSymbol> PDBSymbol::create(const IPDBSession &PDBSession,
111  IPDBRawSymbol &RawSymbol) {
112  auto SymbolPtr = createSymbol(PDBSession, RawSymbol.getSymTag());
113  SymbolPtr->RawSymbol = &RawSymbol;
114  return SymbolPtr;
115 }
116 
117 void PDBSymbol::defaultDump(raw_ostream &OS, int Indent,
118  PdbSymbolIdField ShowFlags,
119  PdbSymbolIdField RecurseFlags) const {
120  RawSymbol->dump(OS, Indent, ShowFlags, RecurseFlags);
121 }
122 
124  outs() << "\n";
126  outs().flush();
127 }
128 
130  TagStats Stats;
132  outs() << "\n";
133  for (auto &Stat : Stats) {
134  outs() << Stat.first << ": " << Stat.second << "\n";
135  }
136  outs().flush();
137 }
138 
141 
142 std::unique_ptr<IPDBEnumSymbols> PDBSymbol::findAllChildren() const {
144 }
145 
146 std::unique_ptr<IPDBEnumSymbols>
148  return RawSymbol->findChildren(Type);
149 }
150 
151 std::unique_ptr<IPDBEnumSymbols>
153  PDB_NameSearchFlags Flags) const {
154  return RawSymbol->findChildren(Type, Name, Flags);
155 }
156 
157 std::unique_ptr<IPDBEnumSymbols>
159  PDB_NameSearchFlags Flags, uint32_t RVA) const {
160  return RawSymbol->findChildrenByRVA(Type, Name, Flags, RVA);
161 }
162 
163 std::unique_ptr<IPDBEnumSymbols>
165  return RawSymbol->findInlineFramesByVA(VA);
166 }
167 
168 std::unique_ptr<IPDBEnumSymbols>
170  return RawSymbol->findInlineFramesByRVA(RVA);
171 }
172 
173 std::unique_ptr<IPDBEnumLineNumbers>
175  return RawSymbol->findInlineeLinesByVA(VA, Length);
176 }
177 
178 std::unique_ptr<IPDBEnumLineNumbers>
180  return RawSymbol->findInlineeLinesByRVA(RVA, Length);
181 }
182 
183 std::string PDBSymbol::getName() const { return RawSymbol->getName(); }
184 
185 std::unique_ptr<IPDBEnumSymbols>
187  std::unique_ptr<IPDBEnumSymbols> Result(findAllChildren());
188  if (!Result)
189  return nullptr;
190  Stats.clear();
191  while (auto Child = Result->getNext()) {
192  ++Stats[Child->getSymTag()];
193  }
194  Result->reset();
195  return Result;
196 }
197 
198 std::unique_ptr<PDBSymbol> PDBSymbol::getSymbolByIdHelper(uint32_t Id) const {
199  return Session.getSymbolById(Id);
200 }
201 
203  SymIndexId Value, int Indent,
204  const IPDBSession &Session,
205  PdbSymbolIdField FieldId,
206  PdbSymbolIdField ShowFlags,
207  PdbSymbolIdField RecurseFlags) {
208  if ((FieldId & ShowFlags) == PdbSymbolIdField::None)
209  return;
210 
211  OS << "\n";
212  OS.indent(Indent);
213  OS << Name << ": " << Value;
214  // Don't recurse unless the user requested it.
215  if ((FieldId & RecurseFlags) == PdbSymbolIdField::None)
216  return;
217  // And obviously don't recurse on the symbol itself.
218  if (FieldId == PdbSymbolIdField::SymIndexId)
219  return;
220 
221  auto Child = Session.getSymbolById(Value);
222 
223  // It could have been a placeholder symbol for a type we don't yet support,
224  // so just exit in that case.
225  if (!Child)
226  return;
227 
228  // Don't recurse more than once, so pass PdbSymbolIdField::None) for the
229  // recurse flags.
230  Child->defaultDump(OS, Indent + 2, ShowFlags, PdbSymbolIdField::None);
231 }
llvm::pdb::PDB_SymType::UsingNamespace
@ UsingNamespace
llvm::pdb::PDBSymbolCompilandEnv
Definition: PDBSymbolCompilandEnv.h:19
llvm::pdb::IPDBRawSymbol::findChildrenByRVA
virtual std::unique_ptr< IPDBEnumSymbols > findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, uint32_t RVA) const =0
llvm::pdb::IPDBSession
IPDBSession defines an interface used to provide a context for querying debug information from a debu...
Definition: IPDBSession.h:25
llvm::pdb::PDBSymbol::getName
std::string getName() const
Definition: PDBSymbol.cpp:183
llvm::pdb::PDB_SymType::CustomType
@ CustomType
PDBSymbolCompilandEnv.h
PDBSymbolTypeManaged.h
PDBSymbolTypeFriend.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::pdb::PDBSymbolPublicSymbol
Definition: PDBSymbolPublicSymbol.h:20
llvm::pdb::PDBSymbol::dumpChildStats
void dumpChildStats() const
Definition: PDBSymbol.cpp:129
PDBSymbolTypeUDT.h
PDBSymbolBlock.h
llvm::pdb::PDB_SymType::FunctionSig
@ FunctionSig
llvm::pdb::PDB_SymType::BaseClass
@ BaseClass
PDBSymbolTypeBaseClass.h
llvm::Function
Definition: Function.h:62
IPDBRawSymbol.h
llvm::pdb::PDBSymbolTypeEnum
Definition: PDBSymbolTypeEnum.h:22
llvm::pdb::PDBSymbolTypeVTable
Definition: PDBSymbolTypeVTable.h:20
PDBSymbolTypeBuiltin.h
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::pdb::IPDBRawSymbol::findInlineFramesByVA
virtual std::unique_ptr< IPDBEnumSymbols > findInlineFramesByVA(uint64_t VA) const =0
llvm::pdb::PDBSymbol::defaultDump
void defaultDump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowFlags, PdbSymbolIdField RecurseFlags) const
Definition: PDBSymbol.cpp:117
llvm::pdb::IPDBRawSymbol::getName
virtual std::string getName() const =0
llvm::ArrayType
Class to represent array types.
Definition: DerivedTypes.h:357
llvm::pdb::PDBSymbolData
Definition: PDBSymbolData.h:22
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::pdb::PDB_SymType
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn....
Definition: PDBTypes.h:243
llvm::pdb::PDBSymbol::create
static std::unique_ptr< PDBSymbol > create(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > RawSymbol)
Definition: PDBSymbol.cpp:102
llvm::pdb::PDB_SymType::FuncDebugStart
@ FuncDebugStart
llvm::pdb::IPDBRawSymbol::dump
virtual void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const =0
llvm::pdb::IPDBRawSymbol::findChildren
virtual std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type) const =0
llvm::pdb::PdbSymbolIdField::None
@ None
llvm::pdb::PDBSymbol::findInlineeLinesByRVA
std::unique_ptr< IPDBEnumLineNumbers > findInlineeLinesByRVA(uint32_t RVA, uint32_t Length) const
Definition: PDBSymbol.cpp:179
llvm::pdb::PDBSymbolTypeTypedef
Definition: PDBSymbolTypeTypedef.h:20
llvm::pdb::PDBSymbolTypeFriend
Definition: PDBSymbolTypeFriend.h:20
llvm::pdb::PDBSymbolTypeDimension
Definition: PDBSymbolTypeDimension.h:20
llvm::pdb::PDBSymbolTypeFunctionArg
Definition: PDBSymbolTypeFunctionArg.h:20
llvm::pdb::IPDBRawSymbol::getSymIndexId
virtual SymIndexId getSymIndexId() const =0
llvm::outs
raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
Definition: raw_ostream.cpp:885
PDBSymbolTypeVTable.h
llvm::pdb::PDBSymbolExe
Definition: PDBSymbolExe.h:21
PDBSymbolTypeVTableShape.h
PDBSymbolTypeEnum.h
llvm::pdb::PDB_SymType::FunctionArg
@ FunctionArg
llvm::pdb::PDBSymbolTypeBaseClass
Definition: PDBSymbolTypeBaseClass.h:23
llvm::pdb::IPDBRawSymbol::getSymTag
virtual PDB_SymType getSymTag() const =0
llvm::pdb::PDBSymbol::PDBSymbol
PDBSymbol(const IPDBSession &PDBSession)
Definition: PDBSymbol.cpp:52
llvm::pdb::PDB_SymType::UDT
@ UDT
llvm::pdb::PDB_SymType::CompilandDetails
@ CompilandDetails
llvm::pdb::PDBSymbol
PDBSymbol defines the base of the inheritance hierarchy for concrete symbol types (e....
Definition: PDBSymbol.h:70
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::raw_ostream::flush
void flush()
Definition: raw_ostream.h:186
llvm::pdb::PDBSymbol::~PDBSymbol
virtual ~PDBSymbol()
llvm::pdb::PDB_NameSearchFlags
PDB_NameSearchFlags
Defines flags used for enumerating child symbols.
Definition: PDBTypes.h:102
llvm::pdb::PDBSymbolTypeCustom
Definition: PDBSymbolTypeCustom.h:20
llvm::pdb::PDBSymbol::getSymbolByIdHelper
std::unique_ptr< PDBSymbol > getSymbolByIdHelper(uint32_t Id) const
Definition: PDBSymbol.cpp:198
PDBSymbol.h
PDBSymbolCompilandDetails.h
PDBSymbolTypeArray.h
PDBSymbolThunk.h
PDBTypes.h
llvm::pdb::PDBSymbolTypeArray
Definition: PDBSymbolTypeArray.h:20
PDBSymbolCustom.h
llvm::pdb::PDBSymbolTypeFunctionSig
Definition: PDBSymbolTypeFunctionSig.h:20
PDBSymbolPublicSymbol.h
PDBSymbolFuncDebugEnd.h
llvm::pdb::PDB_SymType::VTableShape
@ VTableShape
llvm::pdb
Definition: ConcreteSymbolEnumerator.h:20
llvm::pdb::PDBSymbol::getSymIndexId
uint32_t getSymIndexId() const
Definition: PDBSymbol.cpp:140
llvm::pdb::PDBSymbol::getChildStats
std::unique_ptr< IPDBEnumSymbols > getChildStats(TagStats &Stats) const
Definition: PDBSymbol.cpp:186
llvm::pdb::PDBSymbol::findChildrenByRVA
std::unique_ptr< IPDBEnumSymbols > findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, uint32_t RVA) const
Definition: PDBSymbol.cpp:158
PDBSymbolFunc.h
llvm::pdb::PDBSymbolTypePointer
Definition: PDBSymbolTypePointer.h:20
llvm::pdb::PDBSymbolTypeVTableShape
Definition: PDBSymbolTypeVTableShape.h:20
uint64_t
IPDBSession.h
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
PDBSymbolCompiland.h
PDBSymbolTypeFunctionSig.h
PDBSymbolAnnotation.h
llvm::pdb::PDBSymbol::findInlineeLinesByVA
std::unique_ptr< IPDBEnumLineNumbers > findInlineeLinesByVA(uint64_t VA, uint32_t Length) const
Definition: PDBSymbol.cpp:174
llvm::PointerType
Class to represent pointers.
Definition: DerivedTypes.h:632
llvm::pdb::dumpSymbolIdField
void dumpSymbolIdField(raw_ostream &OS, StringRef Name, SymIndexId Value, int Indent, const IPDBSession &Session, PdbSymbolIdField FieldId, PdbSymbolIdField ShowFlags, PdbSymbolIdField RecurseFlags)
Definition: PDBSymbol.cpp:202
llvm::pdb::PDB_SymType::VTable
@ VTable
llvm::pdb::PDBSymbolBlock
Definition: PDBSymbolBlock.h:20
IPDBEnumChildren.h
llvm::pdb::IPDBRawSymbol::findInlineeLinesByVA
virtual std::unique_ptr< IPDBEnumLineNumbers > findInlineeLinesByVA(uint64_t VA, uint32_t Length) const =0
llvm::pdb::PDBSymbolAnnotation
Definition: PDBSymbolAnnotation.h:19
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1658
llvm::pdb::PDB_SymType::Thunk
@ Thunk
llvm::pdb::PDB_SymType::Dimension
@ Dimension
llvm::pdb::PDBSymbolLabel
Definition: PDBSymbolLabel.h:20
llvm::pdb::PDBSymbol::Session
const IPDBSession & Session
Definition: PDBSymbol.h:167
llvm::pdb::PDBSymbolFuncDebugStart
Definition: PDBSymbolFuncDebugStart.h:20
llvm::pdb::PDBSymbolThunk
Definition: PDBSymbolThunk.h:20
llvm::pdb::PDB_SymType::None
@ None
PDBSymbolLabel.h
PDBSymbolTypeTypedef.h
FACTORY_SYMTAG_CASE
#define FACTORY_SYMTAG_CASE(Tag, Type)
Definition: PDBSymbol.cpp:59
llvm::pdb::PDBSymbol::findChildren
std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags) const
Definition: PDBSymbol.cpp:152
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::pdb::PDB_SymType::FuncDebugEnd
@ FuncDebugEnd
llvm::pdb::PDBSymbol::RawSymbol
IPDBRawSymbol * RawSymbol
Definition: PDBSymbol.h:169
PDBSymbolExe.h
uint32_t
llvm::pdb::IPDBSession::getSymbolById
virtual std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const =0
llvm::pdb::PDB_SymType::Enum
@ Enum
llvm::pdb::PDBSymbolUnknown
Definition: PDBSymbolUnknown.h:19
llvm::pdb::TagStats
std::unordered_map< PDB_SymType, int > TagStats
Definition: PDBExtras.h:23
llvm::pdb::PDB_SymType::Annotation
@ Annotation
PDBSymbolTypeCustom.h
PDBSymbolTypePointer.h
llvm::pdb::PdbSymbolIdField::All
@ All
llvm::pdb::PDB_SymType::Label
@ Label
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
std
Definition: BitVector.h:838
llvm::pdb::PDB_SymType::CompilandEnv
@ CompilandEnv
Stats
block placement Basic Block Placement Stats
Definition: MachineBlockPlacement.cpp:3465
PDBSymbolTypeFunctionArg.h
llvm::pdb::IPDBRawSymbol::findInlineFramesByRVA
virtual std::unique_ptr< IPDBEnumSymbols > findInlineFramesByRVA(uint32_t RVA) const =0
llvm::pdb::PDBSymbolFuncDebugEnd
Definition: PDBSymbolFuncDebugEnd.h:21
llvm::pdb::PDB_SymType::Compiland
@ Compiland
llvm::pdb::PDB_SymType::ManagedType
@ ManagedType
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::pdb::PDBSymbolTypeManaged
Definition: PDBSymbolTypeManaged.h:20
llvm::pdb::PDBSymbolCompilandDetails
Definition: PDBSymbolCompilandDetails.h:20
PDBSymbolUsingNamespace.h
llvm::pdb::PdbSymbolIdField::SymIndexId
@ SymIndexId
llvm::pdb::PDBSymbol::getSymTag
PDB_SymType getSymTag() const
Definition: PDBSymbol.cpp:139
llvm::pdb::PdbSymbolIdField
PdbSymbolIdField
Definition: IPDBRawSymbol.h:24
llvm::pdb::PDB_SymType::BuiltinType
@ BuiltinType
llvm::pdb::PDB_SymType::Typedef
@ Typedef
llvm::raw_ostream::indent
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
Definition: raw_ostream.cpp:497
llvm::pdb::PDB_SymType::Exe
@ Exe
llvm::pdb::PDBSymbolTypeBuiltin
Definition: PDBSymbolTypeBuiltin.h:20
llvm::pdb::PDBSymbol::findAllChildren
std::unique_ptr< ConcreteSymbolEnumerator< T > > findAllChildren() const
Definition: PDBSymbol.h:127
PDBExtras.h
llvm::pdb::PDBSymbolFunc
Definition: PDBSymbolFunc.h:23
llvm::pdb::PDBSymbolUsingNamespace
Definition: PDBSymbolUsingNamespace.h:20
llvm::pdb::PDB_SymType::PublicSymbol
@ PublicSymbol
PDBSymbolUnknown.h
llvm::pdb::IPDBRawSymbol
IPDBRawSymbol defines an interface used to represent an arbitrary symbol.
Definition: IPDBRawSymbol.h:45
llvm::AMDGPU::VGPRIndexMode::Id
Id
Definition: SIDefines.h:232
llvm::pdb::PDBSymbolCompiland
Definition: PDBSymbolCompiland.h:21
llvm::pdb::PDBSymbolTypeUDT
Definition: PDBSymbolTypeUDT.h:24
llvm::pdb::PDB_SymType::Block
@ Block
PDBSymbolData.h
PDBSymbolFuncDebugStart.h
PDBSymbolTypeDimension.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::pdb::PDBSymbol::findInlineFramesByRVA
std::unique_ptr< IPDBEnumSymbols > findInlineFramesByRVA(uint32_t RVA) const
Definition: PDBSymbol.cpp:169
llvm::pdb::IPDBRawSymbol::findInlineeLinesByRVA
virtual std::unique_ptr< IPDBEnumLineNumbers > findInlineeLinesByRVA(uint32_t RVA, uint32_t Length) const =0
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1195
llvm::pdb::PDBSymbolCustom
PDBSymbolCustom represents symbols that are compiler-specific and do not fit anywhere else in the lex...
Definition: PDBSymbolCustom.h:24
llvm::pdb::PDBSymbol::dumpProperties
void dumpProperties() const
Definition: PDBSymbol.cpp:123
llvm::pdb::PDBSymbol::findInlineFramesByVA
std::unique_ptr< IPDBEnumSymbols > findInlineFramesByVA(uint64_t VA) const
Definition: PDBSymbol.cpp:164