Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 1 | //===- 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 Turner | d2684b7 | 2017-02-25 00:33:34 +0000 | [diff] [blame^] | 13 | #include "llvm/DebugInfo/MSF/BinaryByteStream.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 14 | #include "llvm/DebugInfo/PDB/GenericError.h" |
| 15 | #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" |
| 16 | #include "llvm/DebugInfo/PDB/IPDBSourceFile.h" |
Adrian McCarthy | 649b8e0 | 2017-02-24 00:10:47 +0000 | [diff] [blame] | 17 | #include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 18 | #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 | |
| 29 | using namespace llvm; |
| 30 | using namespace llvm::msf; |
| 31 | using namespace llvm::pdb; |
| 32 | |
| 33 | NativeSession::NativeSession(std::unique_ptr<PDBFile> PdbFile, |
| 34 | std::unique_ptr<BumpPtrAllocator> Allocator) |
| 35 | : Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)) {} |
| 36 | |
| 37 | NativeSession::~NativeSession() = default; |
| 38 | |
| 39 | Error 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 Turner | 7b327d0 | 2017-02-16 23:35:45 +0000 | [diff] [blame] | 51 | auto File = llvm::make_unique<PDBFile>(Path, std::move(Stream), *Allocator); |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 52 | 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 | |
| 63 | Error NativeSession::createFromExe(StringRef Path, |
| 64 | std::unique_ptr<IPDBSession> &Session) { |
| 65 | return make_error<RawError>(raw_error_code::feature_unsupported); |
| 66 | } |
| 67 | |
| 68 | uint64_t NativeSession::getLoadAddress() const { return 0; } |
| 69 | |
| 70 | void NativeSession::setLoadAddress(uint64_t Address) {} |
| 71 | |
Adrian McCarthy | 649b8e0 | 2017-02-24 00:10:47 +0000 | [diff] [blame] | 72 | std::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 McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | std::unique_ptr<PDBSymbol> |
| 81 | NativeSession::getSymbolById(uint32_t SymbolId) const { |
| 82 | return nullptr; |
| 83 | } |
| 84 | |
| 85 | std::unique_ptr<PDBSymbol> |
| 86 | NativeSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const { |
| 87 | return nullptr; |
| 88 | } |
| 89 | |
| 90 | std::unique_ptr<IPDBEnumLineNumbers> |
| 91 | NativeSession::findLineNumbers(const PDBSymbolCompiland &Compiland, |
| 92 | const IPDBSourceFile &File) const { |
| 93 | return nullptr; |
| 94 | } |
| 95 | |
| 96 | std::unique_ptr<IPDBEnumLineNumbers> |
| 97 | NativeSession::findLineNumbersByAddress(uint64_t Address, |
| 98 | uint32_t Length) const { |
| 99 | return nullptr; |
| 100 | } |
| 101 | |
| 102 | std::unique_ptr<IPDBEnumSourceFiles> |
| 103 | NativeSession::findSourceFiles(const PDBSymbolCompiland *Compiland, |
| 104 | StringRef Pattern, |
| 105 | PDB_NameSearchFlags Flags) const { |
| 106 | return nullptr; |
| 107 | } |
| 108 | |
| 109 | std::unique_ptr<IPDBSourceFile> |
| 110 | NativeSession::findOneSourceFile(const PDBSymbolCompiland *Compiland, |
| 111 | StringRef Pattern, |
| 112 | PDB_NameSearchFlags Flags) const { |
| 113 | return nullptr; |
| 114 | } |
| 115 | |
| 116 | std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>> |
| 117 | NativeSession::findCompilandsForSourceFile(StringRef Pattern, |
| 118 | PDB_NameSearchFlags Flags) const { |
| 119 | return nullptr; |
| 120 | } |
| 121 | |
| 122 | std::unique_ptr<PDBSymbolCompiland> |
| 123 | NativeSession::findOneCompilandForSourceFile(StringRef Pattern, |
| 124 | PDB_NameSearchFlags Flags) const { |
| 125 | return nullptr; |
| 126 | } |
| 127 | |
| 128 | std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getAllSourceFiles() const { |
| 129 | return nullptr; |
| 130 | } |
| 131 | |
| 132 | std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getSourceFilesForCompiland( |
| 133 | const PDBSymbolCompiland &Compiland) const { |
| 134 | return nullptr; |
| 135 | } |
| 136 | |
| 137 | std::unique_ptr<IPDBSourceFile> |
| 138 | NativeSession::getSourceFileById(uint32_t FileId) const { |
| 139 | return nullptr; |
| 140 | } |
| 141 | |
| 142 | std::unique_ptr<IPDBEnumDataStreams> NativeSession::getDebugStreams() const { |
| 143 | return nullptr; |
| 144 | } |