LLVM 20.0.0git
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
20
21#include <unordered_set>
22#include <utility>
23#include <vector>
24
25using namespace llvm;
26using namespace llvm::pdb;
27
28namespace {
29class FunctionArgEnumerator : public IPDBEnumChildren<PDBSymbolData> {
30public:
31 typedef ConcreteSymbolEnumerator<PDBSymbolData> ArgEnumeratorType;
32
33 FunctionArgEnumerator(const IPDBSession &PDBSession,
34 const PDBSymbolFunc &PDBFunc)
35 : Session(PDBSession), Func(PDBFunc) {
36 // Arguments can appear multiple times if they have live range
37 // information, so we only take the first occurrence.
38 std::unordered_set<std::string> SeenNames;
39 auto DataChildren = Func.findAllChildren<PDBSymbolData>();
40 while (auto Child = DataChildren->getNext()) {
41 if (Child->getDataKind() == PDB_DataKind::Param) {
42 std::string Name = Child->getName();
43 if (SeenNames.find(Name) != SeenNames.end())
44 continue;
45 Args.push_back(std::move(Child));
46 SeenNames.insert(Name);
47 }
48 }
49 reset();
50 }
51
52 uint32_t getChildCount() const override { return Args.size(); }
53
54 std::unique_ptr<PDBSymbolData>
55 getChildAtIndex(uint32_t Index) const override {
56 if (Index >= Args.size())
57 return nullptr;
58
59 return Session.getConcreteSymbolById<PDBSymbolData>(
60 Args[Index]->getSymIndexId());
61 }
62
63 std::unique_ptr<PDBSymbolData> getNext() override {
64 if (CurIter == Args.end())
65 return nullptr;
66 const auto &Result = **CurIter;
67 ++CurIter;
68 return Session.getConcreteSymbolById<PDBSymbolData>(Result.getSymIndexId());
69 }
70
71 void reset() override { CurIter = Args.empty() ? Args.end() : Args.begin(); }
72
73private:
74 typedef std::vector<std::unique_ptr<PDBSymbolData>> ArgListType;
75 const IPDBSession &Session;
76 const PDBSymbolFunc &Func;
77 ArgListType Args;
78 ArgListType::const_iterator CurIter;
79};
80}
81
82std::unique_ptr<IPDBEnumChildren<PDBSymbolData>>
84 return std::make_unique<FunctionArgEnumerator>(Session, *this);
85}
86
87void PDBSymbolFunc::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
88
90 std::string Name = getName();
91 if (Name.empty())
92 return false;
93 if (Name[0] == '~')
94 return true;
95 if (Name == "__vecDelDtor")
96 return true;
97 return false;
98}
99
100std::unique_ptr<IPDBEnumLineNumbers> PDBSymbolFunc::getLineNumbers() const {
101 auto Len = RawSymbol->getLength();
103 Len ? Len : 1);
104}
105
107 if (auto Lines = getLineNumbers()) {
108 if (auto FirstLine = Lines->getNext()) {
109 return FirstLine->getCompilandId();
110 }
111 }
112 return 0;
113}
std::string Name
virtual uint32_t getChildCount() const =0
virtual ChildTypePtr getNext()=0
virtual ChildTypePtr getChildAtIndex(uint32_t Index) const =0
virtual uint64_t getLength() const =0
virtual uint64_t getVirtualAddress() 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< IPDBEnumLineNumbers > findLineNumbersByAddress(uint64_t Address, uint32_t Length) const =0
virtual void dump(const PDBSymbolAnnotation &Symbol)
void dump(PDBSymDumper &Dumper) const override
Dumps the contents of a symbol a raw_ostream.
std::unique_ptr< IPDBEnumChildren< PDBSymbolData > > getArguments() const
FORWARD_CONCRETE_SYMBOL_ID_METHOD_WITH_NAME(PDBSymbolTypeFunctionSig, getType, getSignature) std uint32_t getCompilandId() const
const IPDBSession & Session
Definition: PDBSymbol.h:168
std::string getName() const
Definition: PDBSymbol.cpp:183
IPDBRawSymbol * RawSymbol
Definition: PDBSymbol.h:170
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
NodeAddr< FuncNode * > Func
Definition: RDFGraph.h:393
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18