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