1 //===- PDBSymbolData.cpp - PDB data (e.g. variable) accessors ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
18 using namespace llvm::pdb;
20 void PDBSymbolData::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
22 std::unique_ptr<IPDBEnumLineNumbers> PDBSymbolData::getLineNumbers() const {
23 auto Len = RawSymbol->getLength();
25 if (auto RVA = RawSymbol->getRelativeVirtualAddress())
26 return Session.findLineNumbersByRVA(RVA, Len);
28 if (auto Section = RawSymbol->getAddressSection())
29 return Session.findLineNumbersBySectOffset(
30 Section, RawSymbol->getAddressOffset(), Len);
35 uint32_t PDBSymbolData::getCompilandId() const {
36 if (auto Lines = getLineNumbers()) {
37 if (auto FirstLine = Lines->getNext())
38 return FirstLine->getCompilandId();
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);
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();
58 auto LexParentId = RawSymbol->getLexicalParentId();
59 while (auto LexParent = Session.getSymbolById(LexParentId)) {
60 if (LexParent->getSymTag() == PDB_SymType::Exe)
62 if (LexParent->getSymTag() == PDB_SymType::Compiland)
64 LexParentId = LexParent->getRawSymbol().getLexicalParentId();