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); |
Zachary Turner | fbabf2d | 2016-07-06 17:25:12 +0000 | [diff] [blame] | 54 | if (!ErrorOrBuffer) |
| 55 | return llvm::make_error<GenericError>(generic_error_code::invalid_path); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 56 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 57 | std::unique_ptr<MemoryBuffer> Buffer = std::move(*ErrorOrBuffer); |
| 58 | auto Stream = llvm::make_unique<InputByteStream>(std::move(Buffer)); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 59 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 60 | std::unique_ptr<PDBFile> File(new PDBFile(std::move(Stream))); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 61 | if (auto EC = File->parseFileHeaders()) |
| 62 | return EC; |
| 63 | if (auto EC = File->parseStreamData()) |
| 64 | return EC; |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 65 | |
| 66 | Session.reset(new RawSession(std::move(File))); |
| 67 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 68 | return Error::success(); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 71 | Error RawSession::createFromExe(StringRef Path, |
| 72 | std::unique_ptr<IPDBSession> &Session) { |
| 73 | return llvm::make_error<RawError>(raw_error_code::feature_unsupported); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | uint64_t RawSession::getLoadAddress() const { return 0; } |
| 77 | |
| 78 | void RawSession::setLoadAddress(uint64_t Address) {} |
| 79 | |
| 80 | std::unique_ptr<PDBSymbolExe> RawSession::getGlobalScope() const { |
| 81 | return nullptr; |
| 82 | } |
| 83 | |
| 84 | std::unique_ptr<PDBSymbol> RawSession::getSymbolById(uint32_t SymbolId) const { |
| 85 | return nullptr; |
| 86 | } |
| 87 | |
| 88 | std::unique_ptr<PDBSymbol> |
| 89 | RawSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const { |
| 90 | return nullptr; |
| 91 | } |
| 92 | |
| 93 | std::unique_ptr<IPDBEnumLineNumbers> |
| 94 | RawSession::findLineNumbers(const PDBSymbolCompiland &Compiland, |
| 95 | const IPDBSourceFile &File) const { |
| 96 | return nullptr; |
| 97 | } |
| 98 | |
| 99 | std::unique_ptr<IPDBEnumLineNumbers> |
| 100 | RawSession::findLineNumbersByAddress(uint64_t Address, uint32_t Length) const { |
| 101 | return nullptr; |
| 102 | } |
| 103 | |
| 104 | std::unique_ptr<IPDBEnumSourceFiles> |
| 105 | RawSession::findSourceFiles(const PDBSymbolCompiland *Compiland, |
| 106 | llvm::StringRef Pattern, |
| 107 | PDB_NameSearchFlags Flags) const { |
| 108 | return nullptr; |
| 109 | } |
| 110 | |
| 111 | std::unique_ptr<IPDBSourceFile> |
| 112 | RawSession::findOneSourceFile(const PDBSymbolCompiland *Compiland, |
| 113 | llvm::StringRef Pattern, |
| 114 | PDB_NameSearchFlags Flags) const { |
| 115 | return nullptr; |
| 116 | } |
| 117 | |
| 118 | std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>> |
| 119 | RawSession::findCompilandsForSourceFile(llvm::StringRef Pattern, |
| 120 | PDB_NameSearchFlags Flags) const { |
| 121 | return nullptr; |
| 122 | } |
| 123 | |
| 124 | std::unique_ptr<PDBSymbolCompiland> |
| 125 | RawSession::findOneCompilandForSourceFile(llvm::StringRef Pattern, |
| 126 | PDB_NameSearchFlags Flags) const { |
| 127 | return nullptr; |
| 128 | } |
| 129 | |
| 130 | std::unique_ptr<IPDBEnumSourceFiles> RawSession::getAllSourceFiles() const { |
| 131 | return nullptr; |
| 132 | } |
| 133 | |
| 134 | std::unique_ptr<IPDBEnumSourceFiles> RawSession::getSourceFilesForCompiland( |
| 135 | const PDBSymbolCompiland &Compiland) const { |
| 136 | return nullptr; |
| 137 | } |
| 138 | |
| 139 | std::unique_ptr<IPDBSourceFile> |
| 140 | RawSession::getSourceFileById(uint32_t FileId) const { |
| 141 | return nullptr; |
| 142 | } |
| 143 | |
| 144 | std::unique_ptr<IPDBEnumDataStreams> RawSession::getDebugStreams() const { |
| 145 | return nullptr; |
| 146 | } |