blob: cafaa9bffa332d3fbf1e463ae5d71f27844601fb [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"
13#include "llvm/DebugInfo/MSF/ByteStream.h"
14#include "llvm/DebugInfo/PDB/GenericError.h"
15#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
16#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
17#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
18#include "llvm/DebugInfo/PDB/Native/RawError.h"
19#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
20#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
21#include "llvm/Support/Allocator.h"
22#include "llvm/Support/Error.h"
23#include "llvm/Support/ErrorOr.h"
24#include "llvm/Support/MemoryBuffer.h"
25#include <algorithm>
26#include <memory>
27
28using namespace llvm;
29using namespace llvm::msf;
30using namespace llvm::pdb;
31
32NativeSession::NativeSession(std::unique_ptr<PDBFile> PdbFile,
33 std::unique_ptr<BumpPtrAllocator> Allocator)
34 : Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)) {}
35
36NativeSession::~NativeSession() = default;
37
38Error NativeSession::createFromPdb(StringRef Path,
39 std::unique_ptr<IPDBSession> &Session) {
40 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
41 MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
42 /*RequiresNullTerminator=*/false);
43 if (!ErrorOrBuffer)
44 return make_error<GenericError>(generic_error_code::invalid_path);
45
46 std::unique_ptr<MemoryBuffer> Buffer = std::move(*ErrorOrBuffer);
47 auto Stream = llvm::make_unique<MemoryBufferByteStream>(std::move(Buffer));
48
49 auto Allocator = llvm::make_unique<BumpPtrAllocator>();
Zachary Turner7b327d02017-02-16 23:35:45 +000050 auto File = llvm::make_unique<PDBFile>(Path, std::move(Stream), *Allocator);
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000051 if (auto EC = File->parseFileHeaders())
52 return EC;
53 if (auto EC = File->parseStreamData())
54 return EC;
55
56 Session =
57 llvm::make_unique<NativeSession>(std::move(File), std::move(Allocator));
58
59 return Error::success();
60}
61
62Error NativeSession::createFromExe(StringRef Path,
63 std::unique_ptr<IPDBSession> &Session) {
64 return make_error<RawError>(raw_error_code::feature_unsupported);
65}
66
67uint64_t NativeSession::getLoadAddress() const { return 0; }
68
69void NativeSession::setLoadAddress(uint64_t Address) {}
70
71std::unique_ptr<PDBSymbolExe> NativeSession::getGlobalScope() const {
72 return nullptr;
73}
74
75std::unique_ptr<PDBSymbol>
76NativeSession::getSymbolById(uint32_t SymbolId) const {
77 return nullptr;
78}
79
80std::unique_ptr<PDBSymbol>
81NativeSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const {
82 return nullptr;
83}
84
85std::unique_ptr<IPDBEnumLineNumbers>
86NativeSession::findLineNumbers(const PDBSymbolCompiland &Compiland,
87 const IPDBSourceFile &File) const {
88 return nullptr;
89}
90
91std::unique_ptr<IPDBEnumLineNumbers>
92NativeSession::findLineNumbersByAddress(uint64_t Address,
93 uint32_t Length) const {
94 return nullptr;
95}
96
97std::unique_ptr<IPDBEnumSourceFiles>
98NativeSession::findSourceFiles(const PDBSymbolCompiland *Compiland,
99 StringRef Pattern,
100 PDB_NameSearchFlags Flags) const {
101 return nullptr;
102}
103
104std::unique_ptr<IPDBSourceFile>
105NativeSession::findOneSourceFile(const PDBSymbolCompiland *Compiland,
106 StringRef Pattern,
107 PDB_NameSearchFlags Flags) const {
108 return nullptr;
109}
110
111std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
112NativeSession::findCompilandsForSourceFile(StringRef Pattern,
113 PDB_NameSearchFlags Flags) const {
114 return nullptr;
115}
116
117std::unique_ptr<PDBSymbolCompiland>
118NativeSession::findOneCompilandForSourceFile(StringRef Pattern,
119 PDB_NameSearchFlags Flags) const {
120 return nullptr;
121}
122
123std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getAllSourceFiles() const {
124 return nullptr;
125}
126
127std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getSourceFilesForCompiland(
128 const PDBSymbolCompiland &Compiland) const {
129 return nullptr;
130}
131
132std::unique_ptr<IPDBSourceFile>
133NativeSession::getSourceFileById(uint32_t FileId) const {
134 return nullptr;
135}
136
137std::unique_ptr<IPDBEnumDataStreams> NativeSession::getDebugStreams() const {
138 return nullptr;
139}