LLVM  10.0.0svn
PDBSymbolFunc.cpp
Go to the documentation of this file.
1 //===- PDBSymbolFunc.cpp - --------------------------------------*- 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 
10 
18 
19 #include <unordered_set>
20 #include <utility>
21 #include <vector>
22 
23 using namespace llvm;
24 using namespace llvm::pdb;
25 
26 namespace {
27 class FunctionArgEnumerator : public IPDBEnumChildren<PDBSymbolData> {
28 public:
29  typedef ConcreteSymbolEnumerator<PDBSymbolData> ArgEnumeratorType;
30 
31  FunctionArgEnumerator(const IPDBSession &PDBSession,
32  const PDBSymbolFunc &PDBFunc)
33  : Session(PDBSession), Func(PDBFunc) {
34  // Arguments can appear multiple times if they have live range
35  // information, so we only take the first occurrence.
36  std::unordered_set<std::string> SeenNames;
37  auto DataChildren = Func.findAllChildren<PDBSymbolData>();
38  while (auto Child = DataChildren->getNext()) {
39  if (Child->getDataKind() == PDB_DataKind::Param) {
40  std::string Name = Child->getName();
41  if (SeenNames.find(Name) != SeenNames.end())
42  continue;
43  Args.push_back(std::move(Child));
44  SeenNames.insert(Name);
45  }
46  }
47  reset();
48  }
49 
50  uint32_t getChildCount() const override { return Args.size(); }
51 
52  std::unique_ptr<PDBSymbolData>
53  getChildAtIndex(uint32_t Index) const override {
54  if (Index >= Args.size())
55  return nullptr;
56 
57  return Session.getConcreteSymbolById<PDBSymbolData>(
58  Args[Index]->getSymIndexId());
59  }
60 
61  std::unique_ptr<PDBSymbolData> getNext() override {
62  if (CurIter == Args.end())
63  return nullptr;
64  const auto &Result = **CurIter;
65  ++CurIter;
66  return Session.getConcreteSymbolById<PDBSymbolData>(Result.getSymIndexId());
67  }
68 
69  void reset() override { CurIter = Args.empty() ? Args.end() : Args.begin(); }
70 
71 private:
72  typedef std::vector<std::unique_ptr<PDBSymbolData>> ArgListType;
73  const IPDBSession &Session;
74  const PDBSymbolFunc &Func;
75  ArgListType Args;
76  ArgListType::const_iterator CurIter;
77 };
78 }
79 
80 std::unique_ptr<IPDBEnumChildren<PDBSymbolData>>
82  return std::make_unique<FunctionArgEnumerator>(Session, *this);
83 }
84 
85 void PDBSymbolFunc::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
86 
88  std::string Name = getName();
89  if (Name.empty())
90  return false;
91  if (Name[0] == '~')
92  return true;
93  if (Name == "__vecDelDtor")
94  return true;
95  return false;
96 }
97 
98 std::unique_ptr<IPDBEnumLineNumbers> PDBSymbolFunc::getLineNumbers() const {
99  auto Len = RawSymbol->getLength();
100  return Session.findLineNumbersByAddress(RawSymbol->getVirtualAddress(),
101  Len ? Len : 1);
102 }
103 
105  if (auto Lines = getLineNumbers()) {
106  if (auto FirstLine = Lines->getNext()) {
107  return FirstLine->getCompilandId();
108  }
109  }
110  return 0;
111 }
IPDBSession defines an interface used to provide a context for querying debug information from a debu...
Definition: IPDBSession.h:25
This class represents lattice values for constants.
Definition: AllocatorList.h:23
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
std::unique_ptr< IPDBEnumChildren< PDBSymbolData > > getArguments() const
static StringRef getName(Value *V)
virtual void dump(const PDBSymbolAnnotation &Symbol)
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.