Path: blob/main/contrib/llvm-project/llvm/lib/DebugInfo/PDB/PDBSymbolData.cpp
35266 views
//===- PDBSymbolData.cpp - PDB data (e.g. variable) accessors ---*- 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/PDBSymbolData.h"9#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"10#include "llvm/DebugInfo/PDB/IPDBSectionContrib.h"11#include "llvm/DebugInfo/PDB/IPDBSession.h"12#include "llvm/DebugInfo/PDB/PDBSymDumper.h"1314using namespace llvm;15using namespace llvm::pdb;1617void PDBSymbolData::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }1819std::unique_ptr<IPDBEnumLineNumbers> PDBSymbolData::getLineNumbers() const {20auto Len = RawSymbol->getLength();21Len = Len ? Len : 1;22if (auto RVA = RawSymbol->getRelativeVirtualAddress())23return Session.findLineNumbersByRVA(RVA, Len);2425if (auto Section = RawSymbol->getAddressSection())26return Session.findLineNumbersBySectOffset(27Section, RawSymbol->getAddressOffset(), Len);2829return nullptr;30}3132uint32_t PDBSymbolData::getCompilandId() const {33if (auto Lines = getLineNumbers()) {34if (auto FirstLine = Lines->getNext())35return FirstLine->getCompilandId();36}3738uint32_t DataSection = RawSymbol->getAddressSection();39uint32_t DataOffset = RawSymbol->getAddressOffset();40if (DataSection == 0) {41if (auto RVA = RawSymbol->getRelativeVirtualAddress())42Session.addressForRVA(RVA, DataSection, DataOffset);43}4445if (DataSection) {46if (auto SecContribs = Session.getSectionContribs()) {47while (auto Section = SecContribs->getNext()) {48if (Section->getAddressSection() == DataSection &&49Section->getAddressOffset() <= DataOffset &&50(Section->getAddressOffset() + Section->getLength()) > DataOffset)51return Section->getCompilandId();52}53}54} else {55auto LexParentId = RawSymbol->getLexicalParentId();56while (auto LexParent = Session.getSymbolById(LexParentId)) {57if (LexParent->getSymTag() == PDB_SymType::Exe)58break;59if (LexParent->getSymTag() == PDB_SymType::Compiland)60return LexParentId;61LexParentId = LexParent->getRawSymbol().getLexicalParentId();62}63}6465return 0;66}676869