blob: 7e6843bceb7db330d0d3770951ef944b1c92e142 [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"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000013#include "llvm/DebugInfo/PDB/GenericError.h"
14#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
15#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
Adrian McCarthy4d93d662017-03-29 19:27:08 +000016#include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000017#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"
Zachary Turnerd9dc2822017-03-02 20:52:51 +000022#include "llvm/Support/BinaryByteStream.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000023#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 Turner695ed562017-02-28 00:04:07 +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
Zachary Turnerc883a8c2017-04-12 23:18:21 +000073std::unique_ptr<PDBSymbolExe> NativeSession::getGlobalScope() const {
74 auto RawSymbol =
75 llvm::make_unique<NativeExeSymbol>(const_cast<NativeSession &>(*this));
Adrian McCarthy649b8e02017-02-24 00:10:47 +000076 auto PdbSymbol(PDBSymbol::create(*this, std::move(RawSymbol)));
77 std::unique_ptr<PDBSymbolExe> ExeSymbol(
78 static_cast<PDBSymbolExe *>(PdbSymbol.release()));
79 return ExeSymbol;
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000080}
81
82std::unique_ptr<PDBSymbol>
83NativeSession::getSymbolById(uint32_t SymbolId) const {
84 return nullptr;
85}
86
87std::unique_ptr<PDBSymbol>
88NativeSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const {
89 return nullptr;
90}
91
92std::unique_ptr<IPDBEnumLineNumbers>
93NativeSession::findLineNumbers(const PDBSymbolCompiland &Compiland,
94 const IPDBSourceFile &File) const {
95 return nullptr;
96}
97
98std::unique_ptr<IPDBEnumLineNumbers>
99NativeSession::findLineNumbersByAddress(uint64_t Address,
100 uint32_t Length) const {
101 return nullptr;
102}
103
104std::unique_ptr<IPDBEnumSourceFiles>
105NativeSession::findSourceFiles(const PDBSymbolCompiland *Compiland,
106 StringRef Pattern,
107 PDB_NameSearchFlags Flags) const {
108 return nullptr;
109}
110
111std::unique_ptr<IPDBSourceFile>
112NativeSession::findOneSourceFile(const PDBSymbolCompiland *Compiland,
113 StringRef Pattern,
114 PDB_NameSearchFlags Flags) const {
115 return nullptr;
116}
117
118std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
119NativeSession::findCompilandsForSourceFile(StringRef Pattern,
120 PDB_NameSearchFlags Flags) const {
121 return nullptr;
122}
123
124std::unique_ptr<PDBSymbolCompiland>
125NativeSession::findOneCompilandForSourceFile(StringRef Pattern,
126 PDB_NameSearchFlags Flags) const {
127 return nullptr;
128}
129
130std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getAllSourceFiles() const {
131 return nullptr;
132}
133
134std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getSourceFilesForCompiland(
135 const PDBSymbolCompiland &Compiland) const {
136 return nullptr;
137}
138
139std::unique_ptr<IPDBSourceFile>
140NativeSession::getSourceFileById(uint32_t FileId) const {
141 return nullptr;
142}
143
144std::unique_ptr<IPDBEnumDataStreams> NativeSession::getDebugStreams() const {
145 return nullptr;
146}