Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 1 | //===- RawSession.cpp - Raw 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/Raw/RawSession.h" |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 11 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame^] | 12 | #include "llvm/DebugInfo/CodeView/ByteStream.h" |
| 13 | #include "llvm/DebugInfo/CodeView/StreamInterface.h" |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 14 | #include "llvm/DebugInfo/PDB/GenericError.h" |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 15 | #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" |
| 16 | #include "llvm/DebugInfo/PDB/IPDBSourceFile.h" |
| 17 | #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" |
| 18 | #include "llvm/DebugInfo/PDB/PDBSymbolExe.h" |
| 19 | #include "llvm/DebugInfo/PDB/Raw/PDBFile.h" |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 20 | #include "llvm/DebugInfo/PDB/Raw/RawError.h" |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 21 | |
| 22 | #include "llvm/Support/ErrorOr.h" |
| 23 | #include "llvm/Support/MemoryBuffer.h" |
| 24 | |
| 25 | using namespace llvm; |
Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 26 | using namespace llvm::pdb; |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 27 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame^] | 28 | namespace { |
| 29 | // We need a class which behaves like an immutable ByteStream, but whose data |
| 30 | // is backed by an llvm::MemoryBuffer. It also needs to own the underlying |
| 31 | // MemoryBuffer, so this simple adapter is a good way to achieve that. |
| 32 | class InputByteStream : public codeview::ByteStream<false> { |
| 33 | public: |
| 34 | explicit InputByteStream(std::unique_ptr<MemoryBuffer> Buffer) |
| 35 | : ByteStream(ArrayRef<uint8_t>(Buffer->getBuffer().bytes_begin(), |
| 36 | Buffer->getBuffer().bytes_end())), |
| 37 | MemBuffer(std::move(Buffer)) {} |
| 38 | |
| 39 | std::unique_ptr<MemoryBuffer> MemBuffer; |
| 40 | }; |
| 41 | } |
| 42 | |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 43 | RawSession::RawSession(std::unique_ptr<PDBFile> PdbFile) |
| 44 | : Pdb(std::move(PdbFile)) {} |
| 45 | |
| 46 | RawSession::~RawSession() {} |
| 47 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 48 | Error RawSession::createFromPdb(StringRef Path, |
| 49 | std::unique_ptr<IPDBSession> &Session) { |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 50 | |
| 51 | ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer = |
| 52 | MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1, |
| 53 | /*RequiresNullTerminator=*/false); |
| 54 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame^] | 55 | std::unique_ptr<MemoryBuffer> Buffer = std::move(*ErrorOrBuffer); |
| 56 | auto Stream = llvm::make_unique<InputByteStream>(std::move(Buffer)); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 57 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame^] | 58 | std::unique_ptr<PDBFile> File(new PDBFile(std::move(Stream))); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 59 | if (auto EC = File->parseFileHeaders()) |
| 60 | return EC; |
| 61 | if (auto EC = File->parseStreamData()) |
| 62 | return EC; |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 63 | |
| 64 | Session.reset(new RawSession(std::move(File))); |
| 65 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 66 | return Error::success(); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 69 | Error RawSession::createFromExe(StringRef Path, |
| 70 | std::unique_ptr<IPDBSession> &Session) { |
| 71 | return llvm::make_error<RawError>(raw_error_code::feature_unsupported); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | uint64_t RawSession::getLoadAddress() const { return 0; } |
| 75 | |
| 76 | void RawSession::setLoadAddress(uint64_t Address) {} |
| 77 | |
| 78 | std::unique_ptr<PDBSymbolExe> RawSession::getGlobalScope() const { |
| 79 | return nullptr; |
| 80 | } |
| 81 | |
| 82 | std::unique_ptr<PDBSymbol> RawSession::getSymbolById(uint32_t SymbolId) const { |
| 83 | return nullptr; |
| 84 | } |
| 85 | |
| 86 | std::unique_ptr<PDBSymbol> |
| 87 | RawSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const { |
| 88 | return nullptr; |
| 89 | } |
| 90 | |
| 91 | std::unique_ptr<IPDBEnumLineNumbers> |
| 92 | RawSession::findLineNumbers(const PDBSymbolCompiland &Compiland, |
| 93 | const IPDBSourceFile &File) const { |
| 94 | return nullptr; |
| 95 | } |
| 96 | |
| 97 | std::unique_ptr<IPDBEnumLineNumbers> |
| 98 | RawSession::findLineNumbersByAddress(uint64_t Address, uint32_t Length) const { |
| 99 | return nullptr; |
| 100 | } |
| 101 | |
| 102 | std::unique_ptr<IPDBEnumSourceFiles> |
| 103 | RawSession::findSourceFiles(const PDBSymbolCompiland *Compiland, |
| 104 | llvm::StringRef Pattern, |
| 105 | PDB_NameSearchFlags Flags) const { |
| 106 | return nullptr; |
| 107 | } |
| 108 | |
| 109 | std::unique_ptr<IPDBSourceFile> |
| 110 | RawSession::findOneSourceFile(const PDBSymbolCompiland *Compiland, |
| 111 | llvm::StringRef Pattern, |
| 112 | PDB_NameSearchFlags Flags) const { |
| 113 | return nullptr; |
| 114 | } |
| 115 | |
| 116 | std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>> |
| 117 | RawSession::findCompilandsForSourceFile(llvm::StringRef Pattern, |
| 118 | PDB_NameSearchFlags Flags) const { |
| 119 | return nullptr; |
| 120 | } |
| 121 | |
| 122 | std::unique_ptr<PDBSymbolCompiland> |
| 123 | RawSession::findOneCompilandForSourceFile(llvm::StringRef Pattern, |
| 124 | PDB_NameSearchFlags Flags) const { |
| 125 | return nullptr; |
| 126 | } |
| 127 | |
| 128 | std::unique_ptr<IPDBEnumSourceFiles> RawSession::getAllSourceFiles() const { |
| 129 | return nullptr; |
| 130 | } |
| 131 | |
| 132 | std::unique_ptr<IPDBEnumSourceFiles> RawSession::getSourceFilesForCompiland( |
| 133 | const PDBSymbolCompiland &Compiland) const { |
| 134 | return nullptr; |
| 135 | } |
| 136 | |
| 137 | std::unique_ptr<IPDBSourceFile> |
| 138 | RawSession::getSourceFileById(uint32_t FileId) const { |
| 139 | return nullptr; |
| 140 | } |
| 141 | |
| 142 | std::unique_ptr<IPDBEnumDataStreams> RawSession::getDebugStreams() const { |
| 143 | return nullptr; |
| 144 | } |