Path: blob/main/contrib/llvm-project/llvm/lib/DebugInfo/PDB/PDBSymbolFunc.cpp
35269 views
//===- PDBSymbolFunc.cpp - --------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"910#include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"11#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"12#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"13#include "llvm/DebugInfo/PDB/IPDBSession.h"14#include "llvm/DebugInfo/PDB/Native/NativeTypeFunctionSig.h"15#include "llvm/DebugInfo/PDB/PDBSymDumper.h"16#include "llvm/DebugInfo/PDB/PDBSymbolData.h"17#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"18#include "llvm/DebugInfo/PDB/PDBTypes.h"1920#include <unordered_set>21#include <utility>22#include <vector>2324using namespace llvm;25using namespace llvm::pdb;2627namespace {28class FunctionArgEnumerator : public IPDBEnumChildren<PDBSymbolData> {29public:30typedef ConcreteSymbolEnumerator<PDBSymbolData> ArgEnumeratorType;3132FunctionArgEnumerator(const IPDBSession &PDBSession,33const PDBSymbolFunc &PDBFunc)34: Session(PDBSession), Func(PDBFunc) {35// Arguments can appear multiple times if they have live range36// information, so we only take the first occurrence.37std::unordered_set<std::string> SeenNames;38auto DataChildren = Func.findAllChildren<PDBSymbolData>();39while (auto Child = DataChildren->getNext()) {40if (Child->getDataKind() == PDB_DataKind::Param) {41std::string Name = Child->getName();42if (SeenNames.find(Name) != SeenNames.end())43continue;44Args.push_back(std::move(Child));45SeenNames.insert(Name);46}47}48reset();49}5051uint32_t getChildCount() const override { return Args.size(); }5253std::unique_ptr<PDBSymbolData>54getChildAtIndex(uint32_t Index) const override {55if (Index >= Args.size())56return nullptr;5758return Session.getConcreteSymbolById<PDBSymbolData>(59Args[Index]->getSymIndexId());60}6162std::unique_ptr<PDBSymbolData> getNext() override {63if (CurIter == Args.end())64return nullptr;65const auto &Result = **CurIter;66++CurIter;67return Session.getConcreteSymbolById<PDBSymbolData>(Result.getSymIndexId());68}6970void reset() override { CurIter = Args.empty() ? Args.end() : Args.begin(); }7172private:73typedef std::vector<std::unique_ptr<PDBSymbolData>> ArgListType;74const IPDBSession &Session;75const PDBSymbolFunc &Func;76ArgListType Args;77ArgListType::const_iterator CurIter;78};79}8081std::unique_ptr<IPDBEnumChildren<PDBSymbolData>>82PDBSymbolFunc::getArguments() const {83return std::make_unique<FunctionArgEnumerator>(Session, *this);84}8586void PDBSymbolFunc::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }8788bool PDBSymbolFunc::isDestructor() const {89std::string Name = getName();90if (Name.empty())91return false;92if (Name[0] == '~')93return true;94if (Name == "__vecDelDtor")95return true;96return false;97}9899std::unique_ptr<IPDBEnumLineNumbers> PDBSymbolFunc::getLineNumbers() const {100auto Len = RawSymbol->getLength();101return Session.findLineNumbersByAddress(RawSymbol->getVirtualAddress(),102Len ? Len : 1);103}104105uint32_t PDBSymbolFunc::getCompilandId() const {106if (auto Lines = getLineNumbers()) {107if (auto FirstLine = Lines->getNext()) {108return FirstLine->getCompilandId();109}110}111return 0;112}113114115