LLVM  16.0.0git
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 
14 
15 using namespace llvm;
16 using namespace llvm::pdb;
17 
18 void PDBSymbolData::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
19 
20 std::unique_ptr<IPDBEnumLineNumbers> PDBSymbolData::getLineNumbers() const {
21  auto Len = RawSymbol->getLength();
22  Len = Len ? Len : 1;
23  if (auto RVA = RawSymbol->getRelativeVirtualAddress())
24  return Session.findLineNumbersByRVA(RVA, Len);
25 
26  if (auto Section = RawSymbol->getAddressSection())
28  Section, RawSymbol->getAddressOffset(), Len);
29 
30  return nullptr;
31 }
32 
34  if (auto Lines = getLineNumbers()) {
35  if (auto FirstLine = Lines->getNext())
36  return FirstLine->getCompilandId();
37  }
38 
39  uint32_t DataSection = RawSymbol->getAddressSection();
40  uint32_t DataOffset = RawSymbol->getAddressOffset();
41  if (DataSection == 0) {
42  if (auto RVA = RawSymbol->getRelativeVirtualAddress())
43  Session.addressForRVA(RVA, DataSection, DataOffset);
44  }
45 
46  if (DataSection) {
47  if (auto SecContribs = Session.getSectionContribs()) {
48  while (auto Section = SecContribs->getNext()) {
49  if (Section->getAddressSection() == DataSection &&
50  Section->getAddressOffset() <= DataOffset &&
51  (Section->getAddressOffset() + Section->getLength()) > DataOffset)
52  return Section->getCompilandId();
53  }
54  }
55  } else {
56  auto LexParentId = RawSymbol->getLexicalParentId();
57  while (auto LexParent = Session.getSymbolById(LexParentId)) {
58  if (LexParent->getSymTag() == PDB_SymType::Exe)
59  break;
60  if (LexParent->getSymTag() == PDB_SymType::Compiland)
61  return LexParentId;
62  LexParentId = LexParent->getRawSymbol().getLexicalParentId();
63  }
64  }
65 
66  return 0;
67 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::pdb::PDBSymbolData::dump
void dump(PDBSymDumper &Dumper) const override
Dumps the contents of a symbol a raw_ostream.
Definition: PDBSymbolData.cpp:18
llvm::pdb::IPDBRawSymbol::getAddressOffset
virtual uint32_t getAddressOffset() const =0
llvm::pdb::IPDBSession::getSectionContribs
virtual std::unique_ptr< IPDBEnumSectionContribs > getSectionContribs() const =0
llvm::pdb::IPDBRawSymbol::getAddressSection
virtual uint32_t getAddressSection() const =0
PDBSymDumper.h
llvm::pdb::IPDBRawSymbol::getLength
virtual uint64_t getLength() const =0
IPDBLineNumber.h
llvm::pdb::PDBSymDumper::dump
virtual void dump(const PDBSymbolAnnotation &Symbol)
Definition: PDBSymDumper.cpp:24
IPDBSectionContrib.h
llvm::pdb::IPDBSession::addressForRVA
virtual bool addressForRVA(uint32_t RVA, uint32_t &Section, uint32_t &Offset) const =0
llvm::pdb::IPDBSession::findLineNumbersBySectOffset
virtual std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, uint32_t Length) const =0
llvm::pdb::PDBSymbolData::getLineNumbers
std::unique_ptr< IPDBEnumLineNumbers > getLineNumbers() const
Definition: PDBSymbolData.cpp:20
llvm::pdb
Definition: ConcreteSymbolEnumerator.h:20
IPDBSession.h
llvm::pdb::IPDBRawSymbol::getLexicalParentId
virtual SymIndexId getLexicalParentId() const =0
llvm::pdb::PDBSymDumper
Definition: PDBSymDumper.h:19
llvm::pdb::PDBSymbol::Session
const IPDBSession & Session
Definition: PDBSymbol.h:168
llvm::pdb::PDBSymbol::RawSymbol
IPDBRawSymbol * RawSymbol
Definition: PDBSymbol.h:170
uint32_t
llvm::pdb::IPDBSession::getSymbolById
virtual std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const =0
llvm::pdb::IPDBRawSymbol::getRelativeVirtualAddress
virtual uint32_t getRelativeVirtualAddress() const =0
llvm::pdb::PDB_SymType::Compiland
@ Compiland
llvm::pdb::PDB_SymType::Exe
@ Exe
llvm::pdb::IPDBSession::findLineNumbersByRVA
virtual std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const =0
llvm::pdb::PDBSymbolData::getCompilandId
uint32_t getCompilandId() const
Definition: PDBSymbolData.cpp:33
PDBSymbolData.h