LLVM  8.0.1
PDBSymbol.cpp
Go to the documentation of this file.
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 
47 #include <algorithm>
48 #include <memory>
49 
50 using namespace llvm;
51 using namespace llvm::pdb;
52 
53 PDBSymbol::PDBSymbol(const IPDBSession &PDBSession) : Session(PDBSession) {}
54 
57 
58 PDBSymbol::~PDBSymbol() = default;
59 
60 #define FACTORY_SYMTAG_CASE(Tag, Type) \
61  case PDB_SymType::Tag: \
62  return std::unique_ptr<PDBSymbol>(new Type(PDBSession));
63 
64 std::unique_ptr<PDBSymbol>
65 PDBSymbol::createSymbol(const IPDBSession &PDBSession, PDB_SymType Tag) {
66  switch (Tag) {
97  default:
98  return std::unique_ptr<PDBSymbol>(new PDBSymbolUnknown(PDBSession));
99  }
100 }
101 
102 std::unique_ptr<PDBSymbol>
103 PDBSymbol::create(const IPDBSession &PDBSession,
104  std::unique_ptr<IPDBRawSymbol> RawSymbol) {
105  auto SymbolPtr = createSymbol(PDBSession, RawSymbol->getSymTag());
106  SymbolPtr->RawSymbol = RawSymbol.get();
107  SymbolPtr->OwnedRawSymbol = std::move(RawSymbol);
108  return SymbolPtr;
109 }
110 
111 std::unique_ptr<PDBSymbol> PDBSymbol::create(const IPDBSession &PDBSession,
113  auto SymbolPtr = createSymbol(PDBSession, RawSymbol.getSymTag());
114  SymbolPtr->RawSymbol = &RawSymbol;
115  return SymbolPtr;
116 }
117 
119  PdbSymbolIdField ShowFlags,
120  PdbSymbolIdField RecurseFlags) const {
121  RawSymbol->dump(OS, Indent, ShowFlags, RecurseFlags);
122 }
123 
125  outs() << "\n";
127  outs().flush();
128 }
129 
131  TagStats Stats;
132  getChildStats(Stats);
133  outs() << "\n";
134  for (auto &Stat : Stats) {
135  outs() << Stat.first << ": " << Stat.second << "\n";
136  }
137  outs().flush();
138 }
139 
142 
143 std::unique_ptr<IPDBEnumSymbols> PDBSymbol::findAllChildren() const {
145 }
146 
147 std::unique_ptr<IPDBEnumSymbols>
149  return RawSymbol->findChildren(Type);
150 }
151 
152 std::unique_ptr<IPDBEnumSymbols>
154  PDB_NameSearchFlags Flags) const {
155  return RawSymbol->findChildren(Type, Name, Flags);
156 }
157 
158 std::unique_ptr<IPDBEnumSymbols>
160  PDB_NameSearchFlags Flags, uint32_t RVA) const {
161  return RawSymbol->findChildrenByRVA(Type, Name, Flags, RVA);
162 }
163 
164 std::unique_ptr<IPDBEnumSymbols>
166  return RawSymbol->findInlineFramesByRVA(RVA);
167 }
168 
169 std::unique_ptr<IPDBEnumSymbols>
171  std::unique_ptr<IPDBEnumSymbols> Result(findAllChildren());
172  if (!Result)
173  return nullptr;
174  Stats.clear();
175  while (auto Child = Result->getNext()) {
176  ++Stats[Child->getSymTag()];
177  }
178  Result->reset();
179  return Result;
180 }
181 
182 std::unique_ptr<PDBSymbol> PDBSymbol::getSymbolByIdHelper(uint32_t Id) const {
183  return Session.getSymbolById(Id);
184 }
185 
187  SymIndexId Value, int Indent,
188  const IPDBSession &Session,
189  PdbSymbolIdField FieldId,
190  PdbSymbolIdField ShowFlags,
191  PdbSymbolIdField RecurseFlags) {
192  if ((FieldId & ShowFlags) == PdbSymbolIdField::None)
193  return;
194 
195  OS << "\n";
196  OS.indent(Indent);
197  OS << Name << ": " << Value;
198  // Don't recurse unless the user requested it.
199  if ((FieldId & RecurseFlags) == PdbSymbolIdField::None)
200  return;
201  // And obviously don't recurse on the symbol itself.
202  if (FieldId == PdbSymbolIdField::SymIndexId)
203  return;
204 
205  auto Child = Session.getSymbolById(Value);
206 
207  // It could have been a placeholder symbol for a type we don't yet support,
208  // so just exit in that case.
209  if (!Child)
210  return;
211 
212  // Don't recurse more than once, so pass PdbSymbolIdField::None) for the
213  // recurse flags.
214  Child->defaultDump(OS, Indent + 2, ShowFlags, PdbSymbolIdField::None);
215 }
IPDBSession defines an interface used to provide a context for querying debug information from a debu...
Definition: IPDBSession.h:26
IPDBRawSymbol * RawSymbol
Definition: PDBSymbol.h:166
This class represents lattice values for constants.
Definition: AllocatorList.h:24
virtual std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type) const =0
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:101
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:131
amdgpu Simplify well known AMD library false Value Value const Twine & Name
Definition: BitVector.h:938
std::unordered_map< PDB_SymType, int > TagStats
Definition: PDBExtras.h:25
block placement Basic Block Placement Stats
virtual SymIndexId getSymIndexId() const =0
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:784
std::unique_ptr< IPDBEnumSymbols > getChildStats(TagStats &Stats) const
Definition: PDBSymbol.cpp:170
virtual std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const =0
Class to represent array types.
Definition: DerivedTypes.h:369
Class to represent pointers.
Definition: DerivedTypes.h:467
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:183
void defaultDump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowFlags, PdbSymbolIdField RecurseFlags) const
Definition: PDBSymbol.cpp:118
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:46
virtual std::unique_ptr< IPDBEnumSymbols > findInlineFramesByRVA(uint32_t RVA) const =0
IPDBRawSymbol defines an interface used to represent an arbitrary symbol.
Definition: IPDBRawSymbol.h:50
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:153
void dumpSymbolIdField(raw_ostream &OS, StringRef Name, SymIndexId Value, int Indent, const IPDBSession &Session, PdbSymbolIdField FieldId, PdbSymbolIdField ShowFlags, PdbSymbolIdField RecurseFlags)
Definition: PDBSymbol.cpp:186
PDBSymbol(const IPDBSession &PDBSession)
Definition: PDBSymbol.cpp:53
std::unique_ptr< PDBSymbol > getSymbolByIdHelper(uint32_t Id) const
Definition: PDBSymbol.cpp:182
PDB_SymType getSymTag() const
Definition: PDBSymbol.cpp:140
PDBSymbol defines the base of the inheritance hierarchy for concrete symbol types (e...
Definition: PDBSymbol.h:74
#define FACTORY_SYMTAG_CASE(Tag, Type)
Definition: PDBSymbol.cpp:60
const IPDBSession & Session
Definition: PDBSymbol.h:164
std::unique_ptr< IPDBEnumSymbols > findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, uint32_t RVA) const
Definition: PDBSymbol.cpp:159
void dumpProperties() const
Definition: PDBSymbol.cpp:124
std::unique_ptr< IPDBEnumSymbols > findInlineFramesByRVA(uint32_t RVA) const
Definition: PDBSymbol.cpp:165
uint32_t getSymIndexId() const
Definition: PDBSymbol.cpp:141
Definition: JSON.cpp:598
LLVM Value Representation.
Definition: Value.h:73
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
static std::unique_ptr< PDBSymbol > create(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > RawSymbol)
Definition: PDBSymbol.cpp:103
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
void dumpChildStats() const
Definition: PDBSymbol.cpp:130