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