blob: 7807e312365c9acb0d76f6a1fc6b9859b76d109c [file] [log] [blame]
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +00001//===- NativeSession.cpp - Native implementation of IPDBSession -*- 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/NativeSession.h"
11
12#include "llvm/ADT/STLExtras.h"
Adrian McCarthy8d090fc2017-07-12 19:38:11 +000013#include "llvm/DebugInfo/CodeView/TypeIndex.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000014#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
15#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
Adrian McCarthybf0afc32017-06-28 22:47:40 +000016#include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h"
Adrian McCarthyb41f03e2017-08-04 22:37:58 +000017#include "llvm/DebugInfo/PDB/Native/NativeEnumTypes.h"
Adrian McCarthy4d93d662017-03-29 19:27:08 +000018#include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h"
Zachary Turner5d629962018-09-07 00:12:56 +000019#include "llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h"
20#include "llvm/DebugInfo/PDB/Native/NativeTypeEnum.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000021#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
22#include "llvm/DebugInfo/PDB/Native/RawError.h"
Zachary Turner8ab7dd602018-09-07 00:12:34 +000023#include "llvm/DebugInfo/PDB/Native/SymbolCache.h"
Adrian McCarthyb41f03e2017-08-04 22:37:58 +000024#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000025#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
26#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
Adrian McCarthyb41f03e2017-08-04 22:37:58 +000027#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000028#include "llvm/Support/Allocator.h"
Zachary Turnerd9dc2822017-03-02 20:52:51 +000029#include "llvm/Support/BinaryByteStream.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000030#include "llvm/Support/Error.h"
31#include "llvm/Support/ErrorOr.h"
32#include "llvm/Support/MemoryBuffer.h"
Adrian McCarthybf0afc32017-06-28 22:47:40 +000033
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000034#include <algorithm>
Adrian McCarthyb41f03e2017-08-04 22:37:58 +000035#include <cassert>
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000036#include <memory>
Adrian McCarthybf0afc32017-06-28 22:47:40 +000037#include <utility>
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000038
39using namespace llvm;
40using namespace llvm::msf;
41using namespace llvm::pdb;
42
Zachary Turner8ab7dd602018-09-07 00:12:34 +000043static DbiStream *getDbiStreamPtr(PDBFile &File) {
44 Expected<DbiStream &> DbiS = File.getPDBDbiStream();
45 if (DbiS)
46 return &DbiS.get();
47
48 consumeError(DbiS.takeError());
49 return nullptr;
50}
Adrian McCarthy8d090fc2017-07-12 19:38:11 +000051
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000052NativeSession::NativeSession(std::unique_ptr<PDBFile> PdbFile,
53 std::unique_ptr<BumpPtrAllocator> Allocator)
Zachary Turner8ab7dd602018-09-07 00:12:34 +000054 : Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)),
55 Cache(*this, getDbiStreamPtr(*Pdb)) {}
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000056
57NativeSession::~NativeSession() = default;
58
Peter Collingbourne75257bc2017-10-20 19:48:26 +000059Error NativeSession::createFromPdb(std::unique_ptr<MemoryBuffer> Buffer,
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000060 std::unique_ptr<IPDBSession> &Session) {
Peter Collingbourne75257bc2017-10-20 19:48:26 +000061 StringRef Path = Buffer->getBufferIdentifier();
Zachary Turner695ed562017-02-28 00:04:07 +000062 auto Stream = llvm::make_unique<MemoryBufferByteStream>(
63 std::move(Buffer), llvm::support::little);
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000064
65 auto Allocator = llvm::make_unique<BumpPtrAllocator>();
Zachary Turner7b327d02017-02-16 23:35:45 +000066 auto File = llvm::make_unique<PDBFile>(Path, std::move(Stream), *Allocator);
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000067 if (auto EC = File->parseFileHeaders())
68 return EC;
69 if (auto EC = File->parseStreamData())
70 return EC;
71
72 Session =
73 llvm::make_unique<NativeSession>(std::move(File), std::move(Allocator));
74
75 return Error::success();
76}
77
78Error NativeSession::createFromExe(StringRef Path,
79 std::unique_ptr<IPDBSession> &Session) {
80 return make_error<RawError>(raw_error_code::feature_unsupported);
81}
82
83uint64_t NativeSession::getLoadAddress() const { return 0; }
84
Aaron Smith89a19ac2018-02-23 00:02:27 +000085bool NativeSession::setLoadAddress(uint64_t Address) { return false; }
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000086
Adrian McCarthy6a4b0802017-06-22 18:42:23 +000087std::unique_ptr<PDBSymbolExe> NativeSession::getGlobalScope() {
Zachary Turner7999b4f2018-09-05 23:30:38 +000088 return PDBSymbol::createAs<PDBSymbolExe>(*this, getNativeGlobalScope());
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000089}
90
91std::unique_ptr<PDBSymbol>
Zachary Turnercae734582018-09-10 21:30:59 +000092NativeSession::getSymbolById(SymIndexId SymbolId) const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000093 return Cache.getSymbolById(SymbolId);
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000094}
95
Aaron Smith53708a52018-03-26 22:10:02 +000096bool NativeSession::addressForVA(uint64_t VA, uint32_t &Section,
97 uint32_t &Offset) const {
98 return false;
99}
100
101bool NativeSession::addressForRVA(uint32_t VA, uint32_t &Section,
102 uint32_t &Offset) const {
103 return false;
104}
105
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +0000106std::unique_ptr<PDBSymbol>
107NativeSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const {
108 return nullptr;
109}
110
Aaron Smith3dca0be2018-04-10 17:33:18 +0000111std::unique_ptr<PDBSymbol>
112NativeSession::findSymbolByRVA(uint32_t RVA, PDB_SymType Type) const {
113 return nullptr;
114}
115
116std::unique_ptr<PDBSymbol>
117NativeSession::findSymbolBySectOffset(uint32_t Sect, uint32_t Offset,
118 PDB_SymType Type) const {
119 return nullptr;
120}
121
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +0000122std::unique_ptr<IPDBEnumLineNumbers>
123NativeSession::findLineNumbers(const PDBSymbolCompiland &Compiland,
124 const IPDBSourceFile &File) const {
125 return nullptr;
126}
127
128std::unique_ptr<IPDBEnumLineNumbers>
129NativeSession::findLineNumbersByAddress(uint64_t Address,
130 uint32_t Length) const {
131 return nullptr;
132}
133
Aaron Smith40198f52018-03-15 06:04:51 +0000134std::unique_ptr<IPDBEnumLineNumbers>
Aaron Smithed81a9d2018-03-26 22:13:22 +0000135NativeSession::findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const {
136 return nullptr;
137}
138
139std::unique_ptr<IPDBEnumLineNumbers>
Aaron Smith40198f52018-03-15 06:04:51 +0000140NativeSession::findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset,
141 uint32_t Length) const {
142 return nullptr;
143}
144
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +0000145std::unique_ptr<IPDBEnumSourceFiles>
146NativeSession::findSourceFiles(const PDBSymbolCompiland *Compiland,
147 StringRef Pattern,
148 PDB_NameSearchFlags Flags) const {
149 return nullptr;
150}
151
152std::unique_ptr<IPDBSourceFile>
153NativeSession::findOneSourceFile(const PDBSymbolCompiland *Compiland,
154 StringRef Pattern,
155 PDB_NameSearchFlags Flags) const {
156 return nullptr;
157}
158
159std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
160NativeSession::findCompilandsForSourceFile(StringRef Pattern,
161 PDB_NameSearchFlags Flags) const {
162 return nullptr;
163}
164
165std::unique_ptr<PDBSymbolCompiland>
166NativeSession::findOneCompilandForSourceFile(StringRef Pattern,
167 PDB_NameSearchFlags Flags) const {
168 return nullptr;
169}
170
171std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getAllSourceFiles() const {
172 return nullptr;
173}
174
175std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getSourceFilesForCompiland(
176 const PDBSymbolCompiland &Compiland) const {
177 return nullptr;
178}
179
180std::unique_ptr<IPDBSourceFile>
181NativeSession::getSourceFileById(uint32_t FileId) const {
182 return nullptr;
183}
184
185std::unique_ptr<IPDBEnumDataStreams> NativeSession::getDebugStreams() const {
186 return nullptr;
187}
Aaron Smith89bca9e2017-11-16 14:33:09 +0000188
189std::unique_ptr<IPDBEnumTables> NativeSession::getEnumTables() const {
190 return nullptr;
191}
Zachary Turner679aead2018-03-13 17:46:06 +0000192
193std::unique_ptr<IPDBEnumInjectedSources>
194NativeSession::getInjectedSources() const {
195 return nullptr;
196}
Aaron Smith523de052018-03-22 04:08:15 +0000197
198std::unique_ptr<IPDBEnumSectionContribs>
199NativeSession::getSectionContribs() const {
200 return nullptr;
201}
Zachary Turner7999b4f2018-09-05 23:30:38 +0000202
Aleksandr Urakovc43e0862018-10-23 08:14:53 +0000203std::unique_ptr<IPDBEnumFrameData>
204NativeSession::getFrameData() const {
205 return nullptr;
206}
207
Zachary Turner8ab7dd602018-09-07 00:12:34 +0000208void NativeSession::initializeExeSymbol() {
209 if (ExeSymbol == 0)
210 ExeSymbol = Cache.createSymbol<NativeExeSymbol>();
211}
212
213NativeExeSymbol &NativeSession::getNativeGlobalScope() const {
214 const_cast<NativeSession &>(*this).initializeExeSymbol();
215
216 return Cache.getNativeSymbolById<NativeExeSymbol>(ExeSymbol);
Zachary Turner7999b4f2018-09-05 23:30:38 +0000217}