10b57cec5SDimitry Andric //===- PDBSymbolData.cpp - PDB data (e.g. variable) accessors ---*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/PDBSymbolData.h" 10*81ad6265SDimitry Andric #include "llvm/DebugInfo/PDB/IPDBLineNumber.h" 110b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/IPDBSectionContrib.h" 120b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/IPDBSession.h" 130b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/PDBSymDumper.h" 140b57cec5SDimitry Andric 150b57cec5SDimitry Andric using namespace llvm; 160b57cec5SDimitry Andric using namespace llvm::pdb; 170b57cec5SDimitry Andric dump(PDBSymDumper & Dumper) const180b57cec5SDimitry Andricvoid PDBSymbolData::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); } 190b57cec5SDimitry Andric getLineNumbers() const200b57cec5SDimitry Andricstd::unique_ptr<IPDBEnumLineNumbers> PDBSymbolData::getLineNumbers() const { 210b57cec5SDimitry Andric auto Len = RawSymbol->getLength(); 220b57cec5SDimitry Andric Len = Len ? Len : 1; 230b57cec5SDimitry Andric if (auto RVA = RawSymbol->getRelativeVirtualAddress()) 240b57cec5SDimitry Andric return Session.findLineNumbersByRVA(RVA, Len); 250b57cec5SDimitry Andric 260b57cec5SDimitry Andric if (auto Section = RawSymbol->getAddressSection()) 270b57cec5SDimitry Andric return Session.findLineNumbersBySectOffset( 280b57cec5SDimitry Andric Section, RawSymbol->getAddressOffset(), Len); 290b57cec5SDimitry Andric 300b57cec5SDimitry Andric return nullptr; 310b57cec5SDimitry Andric } 320b57cec5SDimitry Andric getCompilandId() const330b57cec5SDimitry Andricuint32_t PDBSymbolData::getCompilandId() const { 340b57cec5SDimitry Andric if (auto Lines = getLineNumbers()) { 350b57cec5SDimitry Andric if (auto FirstLine = Lines->getNext()) 360b57cec5SDimitry Andric return FirstLine->getCompilandId(); 370b57cec5SDimitry Andric } 380b57cec5SDimitry Andric 390b57cec5SDimitry Andric uint32_t DataSection = RawSymbol->getAddressSection(); 400b57cec5SDimitry Andric uint32_t DataOffset = RawSymbol->getAddressOffset(); 410b57cec5SDimitry Andric if (DataSection == 0) { 420b57cec5SDimitry Andric if (auto RVA = RawSymbol->getRelativeVirtualAddress()) 430b57cec5SDimitry Andric Session.addressForRVA(RVA, DataSection, DataOffset); 440b57cec5SDimitry Andric } 450b57cec5SDimitry Andric 460b57cec5SDimitry Andric if (DataSection) { 470b57cec5SDimitry Andric if (auto SecContribs = Session.getSectionContribs()) { 480b57cec5SDimitry Andric while (auto Section = SecContribs->getNext()) { 490b57cec5SDimitry Andric if (Section->getAddressSection() == DataSection && 500b57cec5SDimitry Andric Section->getAddressOffset() <= DataOffset && 510b57cec5SDimitry Andric (Section->getAddressOffset() + Section->getLength()) > DataOffset) 520b57cec5SDimitry Andric return Section->getCompilandId(); 530b57cec5SDimitry Andric } 540b57cec5SDimitry Andric } 550b57cec5SDimitry Andric } else { 560b57cec5SDimitry Andric auto LexParentId = RawSymbol->getLexicalParentId(); 570b57cec5SDimitry Andric while (auto LexParent = Session.getSymbolById(LexParentId)) { 580b57cec5SDimitry Andric if (LexParent->getSymTag() == PDB_SymType::Exe) 590b57cec5SDimitry Andric break; 600b57cec5SDimitry Andric if (LexParent->getSymTag() == PDB_SymType::Compiland) 610b57cec5SDimitry Andric return LexParentId; 620b57cec5SDimitry Andric LexParentId = LexParent->getRawSymbol().getLexicalParentId(); 630b57cec5SDimitry Andric } 640b57cec5SDimitry Andric } 650b57cec5SDimitry Andric 660b57cec5SDimitry Andric return 0; 670b57cec5SDimitry Andric } 68