LLVM  10.0.0svn
PDBSymbolData.cpp
Go to the documentation of this file.
1 //===- PDBSymbolData.cpp - PDB data (e.g. variable) accessors ---*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
13 
14 #include <utility>
15 
16 using namespace llvm;
17 using namespace llvm::pdb;
18 
19 void PDBSymbolData::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
20 
21 std::unique_ptr<IPDBEnumLineNumbers> PDBSymbolData::getLineNumbers() const {
22  auto Len = RawSymbol->getLength();
23  Len = Len ? Len : 1;
24  if (auto RVA = RawSymbol->getRelativeVirtualAddress())
25  return Session.findLineNumbersByRVA(RVA, Len);
26 
27  if (auto Section = RawSymbol->getAddressSection())
30 
31  return nullptr;
32 }
33 
35  if (auto Lines = getLineNumbers()) {
36  if (auto FirstLine = Lines->getNext())
37  return FirstLine->getCompilandId();
38  }
39 
40  uint32_t DataSection = RawSymbol->getAddressSection();
41  uint32_t DataOffset = RawSymbol->getAddressOffset();
42  if (DataSection == 0) {
43  if (auto RVA = RawSymbol->getRelativeVirtualAddress())
44  Session.addressForRVA(RVA, DataSection, DataOffset);
45  }
46 
47  if (DataSection) {
48  if (auto SecContribs = Session.getSectionContribs()) {
49  while (auto Section = SecContribs->getNext()) {
50  if (Section->getAddressSection() == DataSection &&
51  Section->getAddressOffset() <= DataOffset &&
52  (Section->getAddressOffset() + Section->getLength()) > DataOffset)
53  return Section->getCompilandId();
54  }
55  }
56  } else {
57  auto LexParentId = RawSymbol->getLexicalParentId();
58  while (auto LexParent = Session.getSymbolById(LexParentId)) {
59  if (LexParent->getSymTag() == PDB_SymType::Exe)
60  break;
61  if (LexParent->getSymTag() == PDB_SymType::Compiland)
62  return LexParentId;
63  LexParentId = LexParent->getRawSymbol().getLexicalParentId();
64  }
65  }
66 
67  return 0;
68 }
virtual std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const =0
IPDBRawSymbol * RawSymbol
Definition: PDBSymbol.h:165
This class represents lattice values for constants.
Definition: AllocatorList.h:23
std::unique_ptr< IPDBEnumLineNumbers > getLineNumbers() const
virtual std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const =0
virtual std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, uint32_t Length) const =0
void dump(PDBSymDumper &Dumper) const override
Dumps the contents of a symbol a raw_ostream.
virtual uint32_t getAddressOffset() const =0
uint32_t getCompilandId() const
virtual uint32_t getRelativeVirtualAddress() const =0
virtual SymIndexId getLexicalParentId() const =0
virtual std::unique_ptr< IPDBEnumSectionContribs > getSectionContribs() const =0
virtual bool addressForRVA(uint32_t RVA, uint32_t &Section, uint32_t &Offset) const =0
virtual void dump(const PDBSymbolAnnotation &Symbol)
const IPDBSession & Session
Definition: PDBSymbol.h:163
virtual uint32_t getAddressSection() const =0
virtual uint64_t getLength() const =0