blob: 35305708a95c720c830762a946b6f80ea68ad4ec [file] [log] [blame]
Adrian McCarthy4d93d662017-03-29 19:27:08 +00001//===- NativeExeSymbol.cpp - native impl for PDBSymbolExe -------*- 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
10#include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h"
11
Adrian McCarthy4aedc812017-06-22 18:57:51 +000012#include "llvm/ADT/STLExtras.h"
Adrian McCarthy4d93d662017-03-29 19:27:08 +000013#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
14#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
Zachary Turner7999b4f2018-09-05 23:30:38 +000015#include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h"
Adrian McCarthy4d93d662017-03-29 19:27:08 +000016#include "llvm/DebugInfo/PDB/Native/NativeEnumModules.h"
17#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
Zachary Turner7999b4f2018-09-05 23:30:38 +000018#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
Adrian McCarthy4d93d662017-03-29 19:27:08 +000019
Zachary Turner7999b4f2018-09-05 23:30:38 +000020using namespace llvm;
21using namespace llvm::pdb;
Adrian McCarthy4d93d662017-03-29 19:27:08 +000022
Adrian McCarthy8d090fc2017-07-12 19:38:11 +000023NativeExeSymbol::NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId)
Zachary Turner7999b4f2018-09-05 23:30:38 +000024 : NativeRawSymbol(Session, PDB_SymType::Exe, SymbolId),
25 File(Session.getPDBFile()) {
26 Expected<DbiStream &> DbiS = File.getPDBDbiStream();
27 if (!DbiS) {
28 consumeError(DbiS.takeError());
29 return;
30 }
31 Dbi = &DbiS.get();
32 Compilands.resize(Dbi->modules().getModuleCount());
33}
Adrian McCarthy31bcb6f2017-06-22 18:43:18 +000034
35std::unique_ptr<NativeRawSymbol> NativeExeSymbol::clone() const {
Adrian McCarthy4aedc812017-06-22 18:57:51 +000036 return llvm::make_unique<NativeExeSymbol>(Session, SymbolId);
Adrian McCarthy31bcb6f2017-06-22 18:43:18 +000037}
Adrian McCarthy4d93d662017-03-29 19:27:08 +000038
39std::unique_ptr<IPDBEnumSymbols>
40NativeExeSymbol::findChildren(PDB_SymType Type) const {
41 switch (Type) {
42 case PDB_SymType::Compiland: {
Zachary Turner7999b4f2018-09-05 23:30:38 +000043 return std::unique_ptr<IPDBEnumSymbols>(new NativeEnumModules(Session));
Adrian McCarthy4d93d662017-03-29 19:27:08 +000044 break;
45 }
Adrian McCarthyb41f03e2017-08-04 22:37:58 +000046 case PDB_SymType::Enum:
47 return Session.createTypeEnumerator(codeview::LF_ENUM);
Adrian McCarthy4d93d662017-03-29 19:27:08 +000048 default:
49 break;
50 }
51 return nullptr;
52}
53
54uint32_t NativeExeSymbol::getAge() const {
55 auto IS = File.getPDBInfoStream();
56 if (IS)
57 return IS->getAge();
58 consumeError(IS.takeError());
59 return 0;
60}
61
62std::string NativeExeSymbol::getSymbolsFileName() const {
63 return File.getFilePath();
64}
65
Reid Kleckner67653ee2017-07-17 23:59:44 +000066codeview::GUID NativeExeSymbol::getGuid() const {
Adrian McCarthy4d93d662017-03-29 19:27:08 +000067 auto IS = File.getPDBInfoStream();
68 if (IS)
69 return IS->getGuid();
70 consumeError(IS.takeError());
Reid Kleckner67653ee2017-07-17 23:59:44 +000071 return codeview::GUID{{0}};
Adrian McCarthy4d93d662017-03-29 19:27:08 +000072}
73
74bool NativeExeSymbol::hasCTypes() const {
75 auto Dbi = File.getPDBDbiStream();
76 if (Dbi)
77 return Dbi->hasCTypes();
78 consumeError(Dbi.takeError());
79 return false;
80}
81
82bool NativeExeSymbol::hasPrivateSymbols() const {
83 auto Dbi = File.getPDBDbiStream();
84 if (Dbi)
85 return !Dbi->isStripped();
86 consumeError(Dbi.takeError());
87 return false;
88}
89
Zachary Turner7999b4f2018-09-05 23:30:38 +000090uint32_t NativeExeSymbol::getNumCompilands() const {
91 if (!Dbi)
92 return 0;
93
94 return Dbi->modules().getModuleCount();
95}
96
97std::unique_ptr<PDBSymbolCompiland>
98NativeExeSymbol::getOrCreateCompiland(uint32_t Index) {
99 if (!Dbi)
100 return nullptr;
101
102 if (Index >= Compilands.size())
103 return nullptr;
104
105 if (Compilands[Index] == 0) {
106 const DbiModuleList &Modules = Dbi->modules();
107 Compilands[Index] = Session.createSymbol<NativeCompilandSymbol>(
108 Modules.getModuleDescriptor(Index));
109 }
110
111 return Session.getConcreteSymbolById<PDBSymbolCompiland>(Compilands[Index]);
112}