LLVM  9.0.0svn
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 
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,
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 
130  TagStats Stats;
131  getChildStats(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->findInlineFramesByRVA(RVA);
166 }
167 
168 std::unique_ptr<IPDBEnumSymbols>
170  std::unique_ptr<IPDBEnumSymbols> Result(findAllChildren());
171  if (!Result)
172  return nullptr;
173  Stats.clear();
174  while (auto Child = Result->getNext()) {
175  ++Stats[Child->getSymTag()];
176  }
177  Result->reset();
178  return Result;
179 }
180 
181 std::unique_ptr<PDBSymbol> PDBSymbol::getSymbolByIdHelper(uint32_t Id) const {
182  return Session.getSymbolById(Id);
183 }
184 
186  SymIndexId Value, int Indent,
187  const IPDBSession &Session,
188  PdbSymbolIdField FieldId,
189  PdbSymbolIdField ShowFlags,
190  PdbSymbolIdField RecurseFlags) {
191  if ((FieldId & ShowFlags) == PdbSymbolIdField::None)
192  return;
193 
194  OS << "\n";
195  OS.indent(Indent);
196  OS << Name << ": " << Value;
197  // Don't recurse unless the user requested it.
198  if ((FieldId & RecurseFlags) == PdbSymbolIdField::None)
199  return;
200  // And obviously don't recurse on the symbol itself.
201  if (FieldId == PdbSymbolIdField::SymIndexId)
202  return;
203 
204  auto Child = Session.getSymbolById(Value);
205 
206  // It could have been a placeholder symbol for a type we don't yet support,
207  // so just exit in that case.
208  if (!Child)
209  return;
210 
211  // Don't recurse more than once, so pass PdbSymbolIdField::None) for the
212  // recurse flags.
213  Child->defaultDump(OS, Indent + 2, ShowFlags, PdbSymbolIdField::None);
214 }
IPDBSession defines an interface used to provide a context for querying debug information from a debu...
Definition: IPDBSession.h:25
IPDBRawSymbol * RawSymbol
Definition: PDBSymbol.h:165
This class represents lattice values for constants.
Definition: AllocatorList.h:23
virtual std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type) const =0
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
virtual PDB_SymType getSymTag() const =0
PDBSymbolCustom represents symbols that are compiler-specific and do not fit anywhere else in the lex...
raw_ostream & indent(unsigned NumSpaces)
indent - Insert &#39;NumSpaces&#39; spaces.
PDB_NameSearchFlags
Defines flags used for enumerating child symbols.
Definition: PDBTypes.h:100
virtual std::unique_ptr< IPDBEnumSymbols > findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, uint32_t RVA) const =0
std::unique_ptr< ConcreteSymbolEnumerator< T > > findAllChildren() const
Definition: PDBSymbol.h:130
Definition: BitVector.h:937
std::unordered_map< PDB_SymType, int > TagStats
Definition: PDBExtras.h:24
block placement Basic Block Placement Stats
virtual SymIndexId getSymIndexId() const =0
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:810
std::unique_ptr< IPDBEnumSymbols > getChildStats(TagStats &Stats) const
Definition: PDBSymbol.cpp:169
virtual std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const =0
Class to represent array types.
Definition: DerivedTypes.h:400
Class to represent pointers.
Definition: DerivedTypes.h:498
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn.microsoft.com/en-us/library/bkedss5f.aspx.
Definition: PDBTypes.h:182
void defaultDump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowFlags, PdbSymbolIdField RecurseFlags) const
Definition: PDBSymbol.cpp:117
raw_ostream & outs()
This returns a reference to a raw_ostream for standard output.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
virtual std::unique_ptr< IPDBEnumSymbols > findInlineFramesByRVA(uint32_t RVA) const =0
IPDBRawSymbol defines an interface used to represent an arbitrary symbol.
Definition: IPDBRawSymbol.h:49
virtual void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const =0
std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags) const
Definition: PDBSymbol.cpp:152
void dumpSymbolIdField(raw_ostream &OS, StringRef Name, SymIndexId Value, int Indent, const IPDBSession &Session, PdbSymbolIdField FieldId, PdbSymbolIdField ShowFlags, PdbSymbolIdField RecurseFlags)
Definition: PDBSymbol.cpp:185
PDBSymbol(const IPDBSession &PDBSession)
Definition: PDBSymbol.cpp:52
std::unique_ptr< PDBSymbol > getSymbolByIdHelper(uint32_t Id) const
Definition: PDBSymbol.cpp:181
PDB_SymType getSymTag() const
Definition: PDBSymbol.cpp:139
PDBSymbol defines the base of the inheritance hierarchy for concrete symbol types (e...
Definition: PDBSymbol.h:73
#define FACTORY_SYMTAG_CASE(Tag, Type)
Definition: PDBSymbol.cpp:59
const IPDBSession & Session
Definition: PDBSymbol.h:163
std::unique_ptr< IPDBEnumSymbols > findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, uint32_t RVA) const
Definition: PDBSymbol.cpp:158
void dumpProperties() const
Definition: PDBSymbol.cpp:123
std::unique_ptr< IPDBEnumSymbols > findInlineFramesByRVA(uint32_t RVA) const
Definition: PDBSymbol.cpp:164
uint32_t getSymIndexId() const
Definition: PDBSymbol.cpp:140
Definition: JSON.cpp:597
LLVM Value Representation.
Definition: Value.h:72
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
static std::unique_ptr< PDBSymbol > create(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > RawSymbol)
Definition: PDBSymbol.cpp:102
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
void dumpChildStats() const
Definition: PDBSymbol.cpp:129