Zachary Turner | 21473f7 | 2015-02-08 00:29:29 +0000 | [diff] [blame] | 1 | //===- 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 Turner | 52c9f88 | 2015-02-14 03:53:56 +0000 | [diff] [blame] | 10 | #include "llvm/DebugInfo/PDB/PDBSymbolData.h" |
Aaron Smith | 1af50bc | 2018-03-26 22:17:12 +0000 | [diff] [blame] | 11 | #include "llvm/DebugInfo/PDB/IPDBSectionContrib.h" |
Zachary Turner | 29c6910 | 2015-02-23 05:58:34 +0000 | [diff] [blame] | 12 | #include "llvm/DebugInfo/PDB/IPDBSession.h" |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 13 | #include "llvm/DebugInfo/PDB/PDBSymDumper.h" |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 14 | |
Zachary Turner | 52c9f88 | 2015-02-14 03:53:56 +0000 | [diff] [blame] | 15 | #include <utility> |
| 16 | |
Zachary Turner | 21473f7 | 2015-02-08 00:29:29 +0000 | [diff] [blame] | 17 | using namespace llvm; |
Zachary Turner | ec28fc3 | 2016-05-04 20:32:13 +0000 | [diff] [blame] | 18 | using namespace llvm::pdb; |
Zachary Turner | 21473f7 | 2015-02-08 00:29:29 +0000 | [diff] [blame] | 19 | |
Zachary Turner | 98571ed | 2015-02-08 22:53:53 +0000 | [diff] [blame] | 20 | PDBSymbolData::PDBSymbolData(const IPDBSession &PDBSession, |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 21 | std::unique_ptr<IPDBRawSymbol> DataSymbol) |
Zachary Turner | 1b1a70f | 2017-04-10 06:14:09 +0000 | [diff] [blame] | 22 | : PDBSymbol(PDBSession, std::move(DataSymbol)) { |
| 23 | assert(RawSymbol->getSymTag() == PDB_SymType::Data); |
Zachary Turner | 29c6910 | 2015-02-23 05:58:34 +0000 | [diff] [blame] | 24 | } |
| 25 | |
Jim Grosbach | 4c98cf7 | 2015-05-15 19:13:31 +0000 | [diff] [blame] | 26 | void PDBSymbolData::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); } |
Aaron Smith | 1af50bc | 2018-03-26 22:17:12 +0000 | [diff] [blame] | 27 | |
| 28 | std::unique_ptr<IPDBEnumLineNumbers> PDBSymbolData::getLineNumbers() const { |
| 29 | auto Len = RawSymbol->getLength(); |
| 30 | Len = Len ? Len : 1; |
| 31 | if (auto RVA = RawSymbol->getRelativeVirtualAddress()) |
| 32 | return Session.findLineNumbersByRVA(RVA, Len); |
| 33 | |
| 34 | if (auto Section = RawSymbol->getAddressSection()) |
| 35 | return Session.findLineNumbersBySectOffset( |
| 36 | Section, RawSymbol->getAddressOffset(), Len); |
| 37 | |
| 38 | return nullptr; |
| 39 | } |
| 40 | |
| 41 | uint32_t PDBSymbolData::getCompilandId() const { |
| 42 | if (auto Lines = getLineNumbers()) { |
| 43 | if (auto FirstLine = Lines->getNext()) |
| 44 | return FirstLine->getCompilandId(); |
| 45 | } |
| 46 | |
| 47 | uint32_t DataSection = RawSymbol->getAddressSection(); |
| 48 | uint32_t DataOffset = RawSymbol->getAddressOffset(); |
| 49 | if (DataSection == 0) { |
| 50 | if (auto RVA = RawSymbol->getRelativeVirtualAddress()) |
| 51 | Session.addressForRVA(RVA, DataSection, DataOffset); |
| 52 | } |
| 53 | |
| 54 | if (DataSection) { |
| 55 | if (auto SecContribs = Session.getSectionContribs()) { |
| 56 | while (auto Section = SecContribs->getNext()) { |
| 57 | if (Section->getAddressSection() == DataSection && |
| 58 | Section->getAddressOffset() <= DataOffset && |
| 59 | (Section->getAddressOffset() + Section->getLength()) > DataOffset) |
| 60 | return Section->getCompilandId(); |
| 61 | } |
| 62 | } |
| 63 | } else { |
| 64 | auto LexParentId = RawSymbol->getLexicalParentId(); |
| 65 | while (auto LexParent = Session.getSymbolById(LexParentId)) { |
| 66 | if (LexParent->getSymTag() == PDB_SymType::Exe) |
| 67 | break; |
| 68 | if (LexParent->getSymTag() == PDB_SymType::Compiland) |
| 69 | return LexParentId; |
| 70 | LexParentId = LexParent->getRawSymbol().getLexicalParentId(); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | return 0; |
| 75 | } |