blob: 455d33140dd47c383331a786c4260b4c1478ddce [file] [log] [blame]
Zachary Turner0a43efe2016-04-25 17:38:08 +00001//===- RawSession.cpp - Raw 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/Raw/RawSession.h"
Zachary Turner819e77d2016-05-06 20:51:57 +000011
Zachary Turnerb84faa82016-06-10 05:10:19 +000012#include "llvm/DebugInfo/CodeView/ByteStream.h"
13#include "llvm/DebugInfo/CodeView/StreamInterface.h"
Zachary Turner819e77d2016-05-06 20:51:57 +000014#include "llvm/DebugInfo/PDB/GenericError.h"
Zachary Turner0a43efe2016-04-25 17:38:08 +000015#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
16#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
17#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
18#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
19#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
Zachary Turner819e77d2016-05-06 20:51:57 +000020#include "llvm/DebugInfo/PDB/Raw/RawError.h"
Zachary Turner0a43efe2016-04-25 17:38:08 +000021
22#include "llvm/Support/ErrorOr.h"
23#include "llvm/Support/MemoryBuffer.h"
24
25using namespace llvm;
Zachary Turner2f09b502016-04-29 17:28:47 +000026using namespace llvm::pdb;
Zachary Turner0a43efe2016-04-25 17:38:08 +000027
Zachary Turnerb84faa82016-06-10 05:10:19 +000028namespace {
29// We need a class which behaves like an immutable ByteStream, but whose data
30// is backed by an llvm::MemoryBuffer. It also needs to own the underlying
31// MemoryBuffer, so this simple adapter is a good way to achieve that.
32class InputByteStream : public codeview::ByteStream<false> {
33public:
34 explicit InputByteStream(std::unique_ptr<MemoryBuffer> Buffer)
35 : ByteStream(ArrayRef<uint8_t>(Buffer->getBuffer().bytes_begin(),
36 Buffer->getBuffer().bytes_end())),
37 MemBuffer(std::move(Buffer)) {}
38
39 std::unique_ptr<MemoryBuffer> MemBuffer;
40};
41}
42
Zachary Turner0a43efe2016-04-25 17:38:08 +000043RawSession::RawSession(std::unique_ptr<PDBFile> PdbFile)
44 : Pdb(std::move(PdbFile)) {}
45
46RawSession::~RawSession() {}
47
Zachary Turner819e77d2016-05-06 20:51:57 +000048Error RawSession::createFromPdb(StringRef Path,
49 std::unique_ptr<IPDBSession> &Session) {
Zachary Turner0a43efe2016-04-25 17:38:08 +000050
51 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
52 MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
53 /*RequiresNullTerminator=*/false);
Zachary Turnerfbabf2d2016-07-06 17:25:12 +000054 if (!ErrorOrBuffer)
55 return llvm::make_error<GenericError>(generic_error_code::invalid_path);
Zachary Turner0a43efe2016-04-25 17:38:08 +000056
Zachary Turnerb84faa82016-06-10 05:10:19 +000057 std::unique_ptr<MemoryBuffer> Buffer = std::move(*ErrorOrBuffer);
58 auto Stream = llvm::make_unique<InputByteStream>(std::move(Buffer));
Zachary Turner0a43efe2016-04-25 17:38:08 +000059
Zachary Turnerb84faa82016-06-10 05:10:19 +000060 std::unique_ptr<PDBFile> File(new PDBFile(std::move(Stream)));
Zachary Turner819e77d2016-05-06 20:51:57 +000061 if (auto EC = File->parseFileHeaders())
62 return EC;
63 if (auto EC = File->parseStreamData())
64 return EC;
Zachary Turner0a43efe2016-04-25 17:38:08 +000065
66 Session.reset(new RawSession(std::move(File)));
67
Zachary Turner819e77d2016-05-06 20:51:57 +000068 return Error::success();
Zachary Turner0a43efe2016-04-25 17:38:08 +000069}
70
Zachary Turner819e77d2016-05-06 20:51:57 +000071Error RawSession::createFromExe(StringRef Path,
72 std::unique_ptr<IPDBSession> &Session) {
73 return llvm::make_error<RawError>(raw_error_code::feature_unsupported);
Zachary Turner0a43efe2016-04-25 17:38:08 +000074}
75
76uint64_t RawSession::getLoadAddress() const { return 0; }
77
78void RawSession::setLoadAddress(uint64_t Address) {}
79
80std::unique_ptr<PDBSymbolExe> RawSession::getGlobalScope() const {
81 return nullptr;
82}
83
84std::unique_ptr<PDBSymbol> RawSession::getSymbolById(uint32_t SymbolId) const {
85 return nullptr;
86}
87
88std::unique_ptr<PDBSymbol>
89RawSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const {
90 return nullptr;
91}
92
93std::unique_ptr<IPDBEnumLineNumbers>
94RawSession::findLineNumbers(const PDBSymbolCompiland &Compiland,
95 const IPDBSourceFile &File) const {
96 return nullptr;
97}
98
99std::unique_ptr<IPDBEnumLineNumbers>
100RawSession::findLineNumbersByAddress(uint64_t Address, uint32_t Length) const {
101 return nullptr;
102}
103
104std::unique_ptr<IPDBEnumSourceFiles>
105RawSession::findSourceFiles(const PDBSymbolCompiland *Compiland,
106 llvm::StringRef Pattern,
107 PDB_NameSearchFlags Flags) const {
108 return nullptr;
109}
110
111std::unique_ptr<IPDBSourceFile>
112RawSession::findOneSourceFile(const PDBSymbolCompiland *Compiland,
113 llvm::StringRef Pattern,
114 PDB_NameSearchFlags Flags) const {
115 return nullptr;
116}
117
118std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
119RawSession::findCompilandsForSourceFile(llvm::StringRef Pattern,
120 PDB_NameSearchFlags Flags) const {
121 return nullptr;
122}
123
124std::unique_ptr<PDBSymbolCompiland>
125RawSession::findOneCompilandForSourceFile(llvm::StringRef Pattern,
126 PDB_NameSearchFlags Flags) const {
127 return nullptr;
128}
129
130std::unique_ptr<IPDBEnumSourceFiles> RawSession::getAllSourceFiles() const {
131 return nullptr;
132}
133
134std::unique_ptr<IPDBEnumSourceFiles> RawSession::getSourceFilesForCompiland(
135 const PDBSymbolCompiland &Compiland) const {
136 return nullptr;
137}
138
139std::unique_ptr<IPDBSourceFile>
140RawSession::getSourceFileById(uint32_t FileId) const {
141 return nullptr;
142}
143
144std::unique_ptr<IPDBEnumDataStreams> RawSession::getDebugStreams() const {
145 return nullptr;
146}