blob: 7de94670bcb3f774acc2047d356de29e9b7ead1d [file] [log] [blame]
Zachary Turner21473f72015-02-08 00:29:29 +00001//===- 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
Zachary Turner52c9f882015-02-14 03:53:56 +000010#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
Aaron Smith1af50bc2018-03-26 22:17:12 +000011#include "llvm/DebugInfo/PDB/IPDBSectionContrib.h"
Zachary Turner29c69102015-02-23 05:58:34 +000012#include "llvm/DebugInfo/PDB/IPDBSession.h"
Zachary Turner9a818ad2015-02-22 22:03:38 +000013#include "llvm/DebugInfo/PDB/PDBSymDumper.h"
Zachary Turnera5549172015-02-10 22:43:25 +000014
Zachary Turner52c9f882015-02-14 03:53:56 +000015#include <utility>
16
Zachary Turner21473f72015-02-08 00:29:29 +000017using namespace llvm;
Zachary Turnerec28fc32016-05-04 20:32:13 +000018using namespace llvm::pdb;
Zachary Turner21473f72015-02-08 00:29:29 +000019
Jim Grosbach4c98cf72015-05-15 19:13:31 +000020void PDBSymbolData::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
Aaron Smith1af50bc2018-03-26 22:17:12 +000021
22std::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
35uint32_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}