blob: 4c858253b79db217655be508712b7968225dee35 [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);
48 auto Stream = llvm::make_unique<MemoryBufferByteStream>(std::move(Buffer));
49
50 auto Allocator = llvm::make_unique<BumpPtrAllocator>();
Zachary Turner7b327d02017-02-16 23:35:45 +000051 auto File = llvm::make_unique<PDBFile>(Path, std::move(Stream), *Allocator);
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000052 if (auto EC = File->parseFileHeaders())
53 return EC;
54 if (auto EC = File->parseStreamData())
55 return EC;
56
57 Session =
58 llvm::make_unique<NativeSession>(std::move(File), std::move(Allocator));
59
60 return Error::success();
61}
62
63Error NativeSession::createFromExe(StringRef Path,
64 std::unique_ptr<IPDBSession> &Session) {
65 return make_error<RawError>(raw_error_code::feature_unsupported);
66}
67
68uint64_t NativeSession::getLoadAddress() const { return 0; }
69
70void NativeSession::setLoadAddress(uint64_t Address) {}
71
Adrian McCarthy649b8e02017-02-24 00:10:47 +000072std::unique_ptr<PDBSymbolExe> NativeSession::getGlobalScope() {
73 auto RawSymbol = llvm::make_unique<NativeRawSymbol>(*this);
74 auto PdbSymbol(PDBSymbol::create(*this, std::move(RawSymbol)));
75 std::unique_ptr<PDBSymbolExe> ExeSymbol(
76 static_cast<PDBSymbolExe *>(PdbSymbol.release()));
77 return ExeSymbol;
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000078}
79
80std::unique_ptr<PDBSymbol>
81NativeSession::getSymbolById(uint32_t SymbolId) const {
82 return nullptr;
83}
84
85std::unique_ptr<PDBSymbol>
86NativeSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const {
87 return nullptr;
88}
89
90std::unique_ptr<IPDBEnumLineNumbers>
91NativeSession::findLineNumbers(const PDBSymbolCompiland &Compiland,
92 const IPDBSourceFile &File) const {
93 return nullptr;
94}
95
96std::unique_ptr<IPDBEnumLineNumbers>
97NativeSession::findLineNumbersByAddress(uint64_t Address,
98 uint32_t Length) const {
99 return nullptr;
100}
101
102std::unique_ptr<IPDBEnumSourceFiles>
103NativeSession::findSourceFiles(const PDBSymbolCompiland *Compiland,
104 StringRef Pattern,
105 PDB_NameSearchFlags Flags) const {
106 return nullptr;
107}
108
109std::unique_ptr<IPDBSourceFile>
110NativeSession::findOneSourceFile(const PDBSymbolCompiland *Compiland,
111 StringRef Pattern,
112 PDB_NameSearchFlags Flags) const {
113 return nullptr;
114}
115
116std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
117NativeSession::findCompilandsForSourceFile(StringRef Pattern,
118 PDB_NameSearchFlags Flags) const {
119 return nullptr;
120}
121
122std::unique_ptr<PDBSymbolCompiland>
123NativeSession::findOneCompilandForSourceFile(StringRef Pattern,
124 PDB_NameSearchFlags Flags) const {
125 return nullptr;
126}
127
128std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getAllSourceFiles() const {
129 return nullptr;
130}
131
132std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getSourceFilesForCompiland(
133 const PDBSymbolCompiland &Compiland) const {
134 return nullptr;
135}
136
137std::unique_ptr<IPDBSourceFile>
138NativeSession::getSourceFileById(uint32_t FileId) const {
139 return nullptr;
140}
141
142std::unique_ptr<IPDBEnumDataStreams> NativeSession::getDebugStreams() const {
143 return nullptr;
144}