1*7330f729Sjoerg //===- PDBSymbolData.cpp - PDB data (e.g. variable) accessors ---*- C++ -*-===// 2*7330f729Sjoerg // 3*7330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*7330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information. 5*7330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*7330f729Sjoerg // 7*7330f729Sjoerg //===----------------------------------------------------------------------===// 8*7330f729Sjoerg 9*7330f729Sjoerg #include "llvm/DebugInfo/PDB/PDBSymbolData.h" 10*7330f729Sjoerg #include "llvm/DebugInfo/PDB/IPDBSectionContrib.h" 11*7330f729Sjoerg #include "llvm/DebugInfo/PDB/IPDBSession.h" 12*7330f729Sjoerg #include "llvm/DebugInfo/PDB/PDBSymDumper.h" 13*7330f729Sjoerg 14*7330f729Sjoerg #include <utility> 15*7330f729Sjoerg 16*7330f729Sjoerg using namespace llvm; 17*7330f729Sjoerg using namespace llvm::pdb; 18*7330f729Sjoerg dump(PDBSymDumper & Dumper) const19*7330f729Sjoergvoid PDBSymbolData::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); } 20*7330f729Sjoerg getLineNumbers() const21*7330f729Sjoergstd::unique_ptr<IPDBEnumLineNumbers> PDBSymbolData::getLineNumbers() const { 22*7330f729Sjoerg auto Len = RawSymbol->getLength(); 23*7330f729Sjoerg Len = Len ? Len : 1; 24*7330f729Sjoerg if (auto RVA = RawSymbol->getRelativeVirtualAddress()) 25*7330f729Sjoerg return Session.findLineNumbersByRVA(RVA, Len); 26*7330f729Sjoerg 27*7330f729Sjoerg if (auto Section = RawSymbol->getAddressSection()) 28*7330f729Sjoerg return Session.findLineNumbersBySectOffset( 29*7330f729Sjoerg Section, RawSymbol->getAddressOffset(), Len); 30*7330f729Sjoerg 31*7330f729Sjoerg return nullptr; 32*7330f729Sjoerg } 33*7330f729Sjoerg getCompilandId() const34*7330f729Sjoerguint32_t PDBSymbolData::getCompilandId() const { 35*7330f729Sjoerg if (auto Lines = getLineNumbers()) { 36*7330f729Sjoerg if (auto FirstLine = Lines->getNext()) 37*7330f729Sjoerg return FirstLine->getCompilandId(); 38*7330f729Sjoerg } 39*7330f729Sjoerg 40*7330f729Sjoerg uint32_t DataSection = RawSymbol->getAddressSection(); 41*7330f729Sjoerg uint32_t DataOffset = RawSymbol->getAddressOffset(); 42*7330f729Sjoerg if (DataSection == 0) { 43*7330f729Sjoerg if (auto RVA = RawSymbol->getRelativeVirtualAddress()) 44*7330f729Sjoerg Session.addressForRVA(RVA, DataSection, DataOffset); 45*7330f729Sjoerg } 46*7330f729Sjoerg 47*7330f729Sjoerg if (DataSection) { 48*7330f729Sjoerg if (auto SecContribs = Session.getSectionContribs()) { 49*7330f729Sjoerg while (auto Section = SecContribs->getNext()) { 50*7330f729Sjoerg if (Section->getAddressSection() == DataSection && 51*7330f729Sjoerg Section->getAddressOffset() <= DataOffset && 52*7330f729Sjoerg (Section->getAddressOffset() + Section->getLength()) > DataOffset) 53*7330f729Sjoerg return Section->getCompilandId(); 54*7330f729Sjoerg } 55*7330f729Sjoerg } 56*7330f729Sjoerg } else { 57*7330f729Sjoerg auto LexParentId = RawSymbol->getLexicalParentId(); 58*7330f729Sjoerg while (auto LexParent = Session.getSymbolById(LexParentId)) { 59*7330f729Sjoerg if (LexParent->getSymTag() == PDB_SymType::Exe) 60*7330f729Sjoerg break; 61*7330f729Sjoerg if (LexParent->getSymTag() == PDB_SymType::Compiland) 62*7330f729Sjoerg return LexParentId; 63*7330f729Sjoerg LexParentId = LexParent->getRawSymbol().getLexicalParentId(); 64*7330f729Sjoerg } 65*7330f729Sjoerg } 66*7330f729Sjoerg 67*7330f729Sjoerg return 0; 68*7330f729Sjoerg } 69