Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 1 | //===- ModStream.cpp - PDB Module Info Stream Access ----------------------===// |
| 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 | |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 10 | #include "llvm/DebugInfo/PDB/Native/ModStream.h" |
Eugene Zelenko | 570e39a | 2016-11-23 23:16:32 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/iterator_range.h" |
| 12 | #include "llvm/DebugInfo/CodeView/SymbolRecord.h" |
Zachary Turner | d2684b7 | 2017-02-25 00:33:34 +0000 | [diff] [blame] | 13 | #include "llvm/DebugInfo/MSF/BinaryStreamReader.h" |
| 14 | #include "llvm/DebugInfo/MSF/BinaryStreamRef.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 15 | #include "llvm/DebugInfo/PDB/Native/ModInfo.h" |
| 16 | #include "llvm/DebugInfo/PDB/Native/PDBFile.h" |
| 17 | #include "llvm/DebugInfo/PDB/Native/RawError.h" |
| 18 | #include "llvm/DebugInfo/PDB/Native/RawTypes.h" |
Eugene Zelenko | 570e39a | 2016-11-23 23:16:32 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Error.h" |
| 20 | #include <algorithm> |
| 21 | #include <cstdint> |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace llvm; |
Zachary Turner | bac69d3 | 2016-07-22 19:56:05 +0000 | [diff] [blame] | 24 | using namespace llvm::msf; |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 25 | using namespace llvm::pdb; |
| 26 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 27 | ModStream::ModStream(const ModInfo &Module, |
| 28 | std::unique_ptr<MappedBlockStream> Stream) |
| 29 | : Mod(Module), Stream(std::move(Stream)) {} |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 30 | |
Eugene Zelenko | 570e39a | 2016-11-23 23:16:32 +0000 | [diff] [blame] | 31 | ModStream::~ModStream() = default; |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 32 | |
| 33 | Error ModStream::reload() { |
Zachary Turner | af299ea | 2017-02-25 00:44:30 +0000 | [diff] [blame^] | 34 | BinaryStreamReader Reader(*Stream); |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 35 | |
| 36 | uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize(); |
| 37 | uint32_t C11Size = Mod.getLineInfoByteSize(); |
| 38 | uint32_t C13Size = Mod.getC13LineInfoByteSize(); |
| 39 | |
| 40 | if (C11Size > 0 && C13Size > 0) |
Eugene Zelenko | 570e39a | 2016-11-23 23:16:32 +0000 | [diff] [blame] | 41 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 42 | "Module has both C11 and C13 line info"); |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 43 | |
Zachary Turner | af299ea | 2017-02-25 00:44:30 +0000 | [diff] [blame^] | 44 | BinaryStreamRef S; |
Zachary Turner | 1de49c9 | 2016-05-27 18:47:20 +0000 | [diff] [blame] | 45 | |
Zachary Turner | af299ea | 2017-02-25 00:44:30 +0000 | [diff] [blame^] | 46 | if (auto EC = Reader.readInteger(Signature)) |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 47 | return EC; |
Zachary Turner | 1de49c9 | 2016-05-27 18:47:20 +0000 | [diff] [blame] | 48 | if (auto EC = Reader.readArray(SymbolsSubstream, SymbolSize - 4)) |
| 49 | return EC; |
| 50 | |
Zachary Turner | 8dbe362 | 2016-05-27 01:54:44 +0000 | [diff] [blame] | 51 | if (auto EC = Reader.readStreamRef(LinesSubstream, C11Size)) |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 52 | return EC; |
Zachary Turner | 8dbe362 | 2016-05-27 01:54:44 +0000 | [diff] [blame] | 53 | if (auto EC = Reader.readStreamRef(C13LinesSubstream, C13Size)) |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 54 | return EC; |
Zachary Turner | 7eb6d35 | 2016-06-02 20:11:22 +0000 | [diff] [blame] | 55 | |
Zachary Turner | af299ea | 2017-02-25 00:44:30 +0000 | [diff] [blame^] | 56 | BinaryStreamReader LineReader(C13LinesSubstream); |
Zachary Turner | 7eb6d35 | 2016-06-02 20:11:22 +0000 | [diff] [blame] | 57 | if (auto EC = LineReader.readArray(LineInfo, LineReader.bytesRemaining())) |
Zachary Turner | 93839cb | 2016-06-02 05:07:49 +0000 | [diff] [blame] | 58 | return EC; |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 59 | |
| 60 | uint32_t GlobalRefsSize; |
Zachary Turner | af299ea | 2017-02-25 00:44:30 +0000 | [diff] [blame^] | 61 | if (auto EC = Reader.readInteger(GlobalRefsSize)) |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 62 | return EC; |
Zachary Turner | 8dbe362 | 2016-05-27 01:54:44 +0000 | [diff] [blame] | 63 | if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize)) |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 64 | return EC; |
| 65 | if (Reader.bytesRemaining() > 0) |
Eugene Zelenko | 570e39a | 2016-11-23 23:16:32 +0000 | [diff] [blame] | 66 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 67 | "Unexpected bytes in module stream."); |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 68 | |
| 69 | return Error::success(); |
| 70 | } |
| 71 | |
Zachary Turner | 0d43c1c | 2016-05-28 05:21:57 +0000 | [diff] [blame] | 72 | iterator_range<codeview::CVSymbolArray::Iterator> |
| 73 | ModStream::symbols(bool *HadError) const { |
Reid Kleckner | 64b1617 | 2016-07-01 00:37:49 +0000 | [diff] [blame] | 74 | // It's OK if the stream is empty. |
| 75 | if (SymbolsSubstream.getUnderlyingStream().getLength() == 0) |
Eugene Zelenko | 570e39a | 2016-11-23 23:16:32 +0000 | [diff] [blame] | 76 | return make_range(SymbolsSubstream.end(), SymbolsSubstream.end()); |
| 77 | return make_range(SymbolsSubstream.begin(HadError), SymbolsSubstream.end()); |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 78 | } |
Zachary Turner | 7eb6d35 | 2016-06-02 20:11:22 +0000 | [diff] [blame] | 79 | |
Zachary Turner | a96cce6 | 2016-06-03 03:25:59 +0000 | [diff] [blame] | 80 | iterator_range<codeview::ModuleSubstreamArray::Iterator> |
Zachary Turner | 7eb6d35 | 2016-06-02 20:11:22 +0000 | [diff] [blame] | 81 | ModStream::lines(bool *HadError) const { |
Eugene Zelenko | 570e39a | 2016-11-23 23:16:32 +0000 | [diff] [blame] | 82 | return make_range(LineInfo.begin(HadError), LineInfo.end()); |
Zachary Turner | 7eb6d35 | 2016-06-02 20:11:22 +0000 | [diff] [blame] | 83 | } |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 84 | |
| 85 | Error ModStream::commit() { return Error::success(); } |