LLVM 24.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
11#include "llvm/ADT/StringSet.h"
19
20#include <utility>
21#include <vector>
22
23using namespace llvm;
24using namespace llvm::pdb;
25
26namespace {
27class FunctionArgEnumerator : public IPDBEnumChildren<PDBSymbolData> {
28public:
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 StringSet<> SeenNames;
37 auto DataChildren = Func.findAllChildren<PDBSymbolData>();
38 while (auto Child = DataChildren->getNext()) {
39 if (Child->getDataKind() == PDB_DataKind::Param) {
40 if (SeenNames.insert(Child->getName()).second)
41 Args.push_back(std::move(Child));
42 }
43 }
44 reset();
45 }
46
47 uint32_t getChildCount() const override { return Args.size(); }
48
49 std::unique_ptr<PDBSymbolData>
50 getChildAtIndex(uint32_t Index) const override {
51 if (Index >= Args.size())
52 return nullptr;
53
54 return Session.getConcreteSymbolById<PDBSymbolData>(
55 Args[Index]->getSymIndexId());
56 }
57
58 std::unique_ptr<PDBSymbolData> getNext() override {
59 if (CurIter == Args.end())
60 return nullptr;
61 const auto &Result = **CurIter;
62 ++CurIter;
63 return Session.getConcreteSymbolById<PDBSymbolData>(Result.getSymIndexId());
64 }
65
66 void reset() override { CurIter = Args.empty() ? Args.end() : Args.begin(); }
67
68private:
69 typedef std::vector<std::unique_ptr<PDBSymbolData>> ArgListType;
70 const IPDBSession &Session;
71 const PDBSymbolFunc &Func;
72 ArgListType Args;
73 ArgListType::const_iterator CurIter;
74};
75}
76
77std::unique_ptr<IPDBEnumChildren<PDBSymbolData>>
79 return std::make_unique<FunctionArgEnumerator>(Session, *this);
80}
81
82void PDBSymbolFunc::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
83
85 std::string Name = getName();
86 if (Name.empty())
87 return false;
88 if (Name[0] == '~')
89 return true;
90 if (Name == "__vecDelDtor")
91 return true;
92 return false;
93}
94
95std::unique_ptr<IPDBEnumLineNumbers> PDBSymbolFunc::getLineNumbers() const {
96 auto Len = RawSymbol->getLength();
98 Len ? Len : 1);
99}
100
102 if (auto Lines = getLineNumbers()) {
103 if (auto FirstLine = Lines->getNext()) {
104 return FirstLine->getCompilandId();
105 }
106 }
107 return 0;
108}
StringSet - A set-like wrapper for the StringMap.
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:26
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:169
std::string getName() const
IPDBRawSymbol * RawSymbol
Definition PDBSymbol.h:171
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.