blob: 458c17a79a3f4c35fb5f67dfd8a8ad2f8df67eaf [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);
54
Zachary Turnerb84faa82016-06-10 05:10:19 +000055 std::unique_ptr<MemoryBuffer> Buffer = std::move(*ErrorOrBuffer);
56 auto Stream = llvm::make_unique<InputByteStream>(std::move(Buffer));
Zachary Turner0a43efe2016-04-25 17:38:08 +000057
Zachary Turnerb84faa82016-06-10 05:10:19 +000058 std::unique_ptr<PDBFile> File(new PDBFile(std::move(Stream)));
Zachary Turner819e77d2016-05-06 20:51:57 +000059 if (auto EC = File->parseFileHeaders())
60 return EC;
61 if (auto EC = File->parseStreamData())
62 return EC;
Zachary Turner0a43efe2016-04-25 17:38:08 +000063
64 Session.reset(new RawSession(std::move(File)));
65
Zachary Turner819e77d2016-05-06 20:51:57 +000066 return Error::success();
Zachary Turner0a43efe2016-04-25 17:38:08 +000067}
68
Zachary Turner819e77d2016-05-06 20:51:57 +000069Error RawSession::createFromExe(StringRef Path,
70 std::unique_ptr<IPDBSession> &Session) {
71 return llvm::make_error<RawError>(raw_error_code::feature_unsupported);
Zachary Turner0a43efe2016-04-25 17:38:08 +000072}
73
74uint64_t RawSession::getLoadAddress() const { return 0; }
75
76void RawSession::setLoadAddress(uint64_t Address) {}
77
78std::unique_ptr<PDBSymbolExe> RawSession::getGlobalScope() const {
79 return nullptr;
80}
81
82std::unique_ptr<PDBSymbol> RawSession::getSymbolById(uint32_t SymbolId) const {
83 return nullptr;
84}
85
86std::unique_ptr<PDBSymbol>
87RawSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const {
88 return nullptr;
89}
90
91std::unique_ptr<IPDBEnumLineNumbers>
92RawSession::findLineNumbers(const PDBSymbolCompiland &Compiland,
93 const IPDBSourceFile &File) const {
94 return nullptr;
95}
96
97std::unique_ptr<IPDBEnumLineNumbers>
98RawSession::findLineNumbersByAddress(uint64_t Address, uint32_t Length) const {
99 return nullptr;
100}
101
102std::unique_ptr<IPDBEnumSourceFiles>
103RawSession::findSourceFiles(const PDBSymbolCompiland *Compiland,
104 llvm::StringRef Pattern,
105 PDB_NameSearchFlags Flags) const {
106 return nullptr;
107}
108
109std::unique_ptr<IPDBSourceFile>
110RawSession::findOneSourceFile(const PDBSymbolCompiland *Compiland,
111 llvm::StringRef Pattern,
112 PDB_NameSearchFlags Flags) const {
113 return nullptr;
114}
115
116std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
117RawSession::findCompilandsForSourceFile(llvm::StringRef Pattern,
118 PDB_NameSearchFlags Flags) const {
119 return nullptr;
120}
121
122std::unique_ptr<PDBSymbolCompiland>
123RawSession::findOneCompilandForSourceFile(llvm::StringRef Pattern,
124 PDB_NameSearchFlags Flags) const {
125 return nullptr;
126}
127
128std::unique_ptr<IPDBEnumSourceFiles> RawSession::getAllSourceFiles() const {
129 return nullptr;
130}
131
132std::unique_ptr<IPDBEnumSourceFiles> RawSession::getSourceFilesForCompiland(
133 const PDBSymbolCompiland &Compiland) const {
134 return nullptr;
135}
136
137std::unique_ptr<IPDBSourceFile>
138RawSession::getSourceFileById(uint32_t FileId) const {
139 return nullptr;
140}
141
142std::unique_ptr<IPDBEnumDataStreams> RawSession::getDebugStreams() const {
143 return nullptr;
144}