LLVM  7.0.0
PDBSymbolFunc.cpp
Go to the documentation of this file.
1 //===- PDBSymbolFunc.cpp - --------------------------------------*- 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 
11 
19 
20 #include <unordered_set>
21 #include <utility>
22 #include <vector>
23 
24 using namespace llvm;
25 using namespace llvm::pdb;
26 
27 namespace {
28 class FunctionArgEnumerator : public IPDBEnumChildren<PDBSymbolData> {
29 public:
30  typedef ConcreteSymbolEnumerator<PDBSymbolData> ArgEnumeratorType;
31 
32  FunctionArgEnumerator(const IPDBSession &PDBSession,
33  const PDBSymbolFunc &PDBFunc)
34  : Session(PDBSession), Func(PDBFunc) {
35  // Arguments can appear multiple times if they have live range
36  // information, so we only take the first occurrence.
37  std::unordered_set<std::string> SeenNames;
38  auto DataChildren = Func.findAllChildren<PDBSymbolData>();
39  while (auto Child = DataChildren->getNext()) {
40  if (Child->getDataKind() == PDB_DataKind::Param) {
41  std::string Name = Child->getName();
42  if (SeenNames.find(Name) != SeenNames.end())
43  continue;
44  Args.push_back(std::move(Child));
45  SeenNames.insert(Name);
46  }
47  }
48  reset();
49  }
50 
51  uint32_t getChildCount() const override { return Args.size(); }
52 
53  std::unique_ptr<PDBSymbolData>
54  getChildAtIndex(uint32_t Index) const override {
55  if (Index >= Args.size())
56  return nullptr;
57 
58  return Session.getConcreteSymbolById<PDBSymbolData>(
59  Args[Index]->getSymIndexId());
60  }
61 
62  std::unique_ptr<PDBSymbolData> getNext() override {
63  if (CurIter == Args.end())
64  return nullptr;
65  const auto &Result = **CurIter;
66  ++CurIter;
67  return Session.getConcreteSymbolById<PDBSymbolData>(Result.getSymIndexId());
68  }
69 
70  void reset() override { CurIter = Args.empty() ? Args.end() : Args.begin(); }
71 
72  FunctionArgEnumerator *clone() const override {
73  return new FunctionArgEnumerator(Session, Func);
74  }
75 
76 private:
77  typedef std::vector<std::unique_ptr<PDBSymbolData>> ArgListType;
78  const IPDBSession &Session;
79  const PDBSymbolFunc &Func;
80  ArgListType Args;
81  ArgListType::const_iterator CurIter;
82 };
83 }
84 
86  std::unique_ptr<IPDBRawSymbol> Symbol)
87  : PDBSymbol(PDBSession, std::move(Symbol)) {
88  assert(RawSymbol->getSymTag() == PDB_SymType::Function);
89 }
90 
91 std::unique_ptr<IPDBEnumChildren<PDBSymbolData>>
93  return llvm::make_unique<FunctionArgEnumerator>(Session, *this);
94 }
95 
96 void PDBSymbolFunc::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
97 
99  std::string Name = getName();
100  if (Name.empty())
101  return false;
102  if (Name[0] == '~')
103  return true;
104  if (Name == "__vecDelDtor")
105  return true;
106  return false;
107 }
108 
109 std::unique_ptr<IPDBEnumLineNumbers> PDBSymbolFunc::getLineNumbers() const {
110  auto Len = RawSymbol->getLength();
111  return Session.findLineNumbersByAddress(RawSymbol->getVirtualAddress(),
112  Len ? Len : 1);
113 }
114 
116  if (auto Lines = getLineNumbers()) {
117  if (auto FirstLine = Lines->getNext()) {
118  return FirstLine->getCompilandId();
119  }
120  }
121  return 0;
122 }
IPDBSession defines an interface used to provide a context for querying debug information from a debu...
Definition: IPDBSession.h:26
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
PDBSymbolFunc(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > FuncSymbol)
std::unique_ptr< IPDBEnumChildren< PDBSymbolData > > getArguments() const
std::unique_ptr< IPDBRawSymbol > RawSymbol
Definition: PDBSymbol.h:134
Definition: BitVector.h:921
static StringRef getName(Value *V)
virtual std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByAddress(uint64_t Address, uint32_t Length) const =0
PDBSymbol defines the base of the inheritance hierarchy for concrete symbol types (e...
Definition: PDBSymbol.h:61
virtual void dump(const PDBSymbolAnnotation &Symbol)
const IPDBSession & Session
Definition: PDBSymbol.h:133
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
FORWARD_CONCRETE_SYMBOL_ID_METHOD_WITH_NAME(PDBSymbolTypeFunctionSig, getType, getSignature) std uint32_t getCompilandId() const
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
void dump(PDBSymDumper &Dumper) const override
Dumps the contents of a symbol a raw_ostream.