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