LLVM 20.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
15using namespace llvm;
16using namespace llvm::pdb;
17
18void PDBSymbolData::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
19
20std::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}
virtual uint32_t getRelativeVirtualAddress() const =0
virtual uint32_t getAddressSection() const =0
virtual SymIndexId getLexicalParentId() const =0
virtual uint64_t getLength() const =0
virtual uint32_t getAddressOffset() const =0
virtual std::unique_ptr< IPDBEnumSectionContribs > getSectionContribs() const =0
virtual std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, uint32_t Length) const =0
virtual std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const =0
virtual bool addressForRVA(uint32_t RVA, uint32_t &Section, uint32_t &Offset) const =0
virtual std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const =0
virtual void dump(const PDBSymbolAnnotation &Symbol)
std::unique_ptr< IPDBEnumLineNumbers > getLineNumbers() const
void dump(PDBSymDumper &Dumper) const override
Dumps the contents of a symbol a raw_ostream.
uint32_t getCompilandId() const
const IPDBSession & Session
Definition: PDBSymbol.h:168
IPDBRawSymbol * RawSymbol
Definition: PDBSymbol.h:170
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18