LLVM 20.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
47#include <memory>
48
49using namespace llvm;
50using namespace llvm::pdb;
51
52PDBSymbol::PDBSymbol(const IPDBSession &PDBSession) : Session(PDBSession) {}
53
55 : Session(Other.Session), RawSymbol(std::move(Other.RawSymbol)) {}
56
57PDBSymbol::~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
63std::unique_ptr<PDBSymbol>
64PDBSymbol::createSymbol(const IPDBSession &PDBSession, PDB_SymType Tag) {
65 switch (Tag) {
96 default:
97 return std::unique_ptr<PDBSymbol>(new PDBSymbolUnknown(PDBSession));
98 }
99}
100
101std::unique_ptr<PDBSymbol>
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
110std::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
118 PdbSymbolIdField ShowFlags,
119 PdbSymbolIdField RecurseFlags) const {
120 RawSymbol->dump(OS, Indent, ShowFlags, RecurseFlags);
121}
122
124 outs() << "\n";
126 outs().flush();
127}
128
132 outs() << "\n";
133 for (auto &Stat : Stats) {
134 outs() << Stat.first << ": " << Stat.second << "\n";
135 }
136 outs().flush();
137}
138
141
142std::unique_ptr<IPDBEnumSymbols> PDBSymbol::findAllChildren() const {
144}
145
146std::unique_ptr<IPDBEnumSymbols>
148 return RawSymbol->findChildren(Type);
149}
150
151std::unique_ptr<IPDBEnumSymbols>
153 PDB_NameSearchFlags Flags) const {
154 return RawSymbol->findChildren(Type, Name, Flags);
155}
156
157std::unique_ptr<IPDBEnumSymbols>
159 PDB_NameSearchFlags Flags, uint32_t RVA) const {
160 return RawSymbol->findChildrenByRVA(Type, Name, Flags, RVA);
161}
162
163std::unique_ptr<IPDBEnumSymbols>
166}
167
168std::unique_ptr<IPDBEnumSymbols>
170 return RawSymbol->findInlineFramesByRVA(RVA);
171}
172
173std::unique_ptr<IPDBEnumLineNumbers>
176}
177
178std::unique_ptr<IPDBEnumLineNumbers>
181}
182
183std::string PDBSymbol::getName() const { return RawSymbol->getName(); }
184
185std::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
198std::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}
std::string Name
block placement Basic Block Placement Stats
#define FACTORY_SYMTAG_CASE(Tag, Type)
Definition: PDBSymbol.cpp:59
raw_pwrite_stream & OS
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
IPDBRawSymbol defines an interface used to represent an arbitrary symbol.
Definition: IPDBRawSymbol.h:45
virtual std::string getName() const =0
virtual void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const =0
virtual PDB_SymType getSymTag() const =0
virtual std::unique_ptr< IPDBEnumSymbols > findInlineFramesByRVA(uint32_t RVA) const =0
virtual std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type) const =0
virtual std::unique_ptr< IPDBEnumLineNumbers > findInlineeLinesByVA(uint64_t VA, uint32_t Length) const =0
virtual SymIndexId getSymIndexId() const =0
virtual std::unique_ptr< IPDBEnumSymbols > findInlineFramesByVA(uint64_t VA) const =0
virtual std::unique_ptr< IPDBEnumLineNumbers > findInlineeLinesByRVA(uint32_t RVA, uint32_t Length) const =0
virtual std::unique_ptr< IPDBEnumSymbols > findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, uint32_t RVA) const =0
IPDBSession defines an interface used to provide a context for querying debug information from a debu...
Definition: IPDBSession.h:25
virtual std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const =0
PDBSymbolCustom represents symbols that are compiler-specific and do not fit anywhere else in the lex...
PDBSymbol defines the base of the inheritance hierarchy for concrete symbol types (e....
Definition: PDBSymbol.h:71
uint32_t getSymIndexId() const
Definition: PDBSymbol.cpp:140
PDB_SymType getSymTag() const
Definition: PDBSymbol.cpp:139
void dumpChildStats() const
Definition: PDBSymbol.cpp:129
const IPDBSession & Session
Definition: PDBSymbol.h:168
std::unique_ptr< PDBSymbol > getSymbolByIdHelper(uint32_t Id) const
Definition: PDBSymbol.cpp:198
std::unique_ptr< ConcreteSymbolEnumerator< T > > findAllChildren() const
Definition: PDBSymbol.h:128
std::unique_ptr< IPDBEnumSymbols > findInlineFramesByVA(uint64_t VA) const
Definition: PDBSymbol.cpp:164
void dumpProperties() const
Definition: PDBSymbol.cpp:123
std::unique_ptr< IPDBEnumSymbols > findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, uint32_t RVA) const
Definition: PDBSymbol.cpp:158
std::unique_ptr< IPDBEnumLineNumbers > findInlineeLinesByRVA(uint32_t RVA, uint32_t Length) const
Definition: PDBSymbol.cpp:179
std::unique_ptr< IPDBEnumSymbols > findInlineFramesByRVA(uint32_t RVA) const
Definition: PDBSymbol.cpp:169
std::string getName() const
Definition: PDBSymbol.cpp:183
PDBSymbol(const IPDBSession &PDBSession)
Definition: PDBSymbol.cpp:52
void defaultDump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowFlags, PdbSymbolIdField RecurseFlags) const
Definition: PDBSymbol.cpp:117
std::unique_ptr< IPDBEnumLineNumbers > findInlineeLinesByVA(uint64_t VA, uint32_t Length) const
Definition: PDBSymbol.cpp:174
IPDBRawSymbol * RawSymbol
Definition: PDBSymbol.h:170
std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags) const
Definition: PDBSymbol.cpp:152
static std::unique_ptr< PDBSymbol > create(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > RawSymbol)
Definition: PDBSymbol.cpp:102
std::unique_ptr< IPDBEnumSymbols > getChildStats(TagStats &Stats) const
Definition: PDBSymbol.cpp:186
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
PDB_NameSearchFlags
Defines flags used for enumerating child symbols.
Definition: PDBTypes.h:102
std::unordered_map< PDB_SymType, int > TagStats
Definition: PDBExtras.h:23
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn....
Definition: PDBTypes.h:243
void dumpSymbolIdField(raw_ostream &OS, StringRef Name, SymIndexId Value, int Indent, const IPDBSession &Session, PdbSymbolIdField FieldId, PdbSymbolIdField ShowFlags, PdbSymbolIdField RecurseFlags)
Definition: PDBSymbol.cpp:202
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Length
Definition: DWP.cpp:480
raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
@ Other
Any other memory.
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:1856
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858