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 | |
| 10 | #include "llvm/DebugInfo/PDB/Raw/ModStream.h" |
Zachary Turner | d5d37dc | 2016-05-25 20:37:03 +0000 | [diff] [blame] | 11 | |
| 12 | #include "llvm/DebugInfo/CodeView/StreamReader.h" |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 13 | #include "llvm/DebugInfo/PDB/Raw/ModInfo.h" |
| 14 | #include "llvm/DebugInfo/PDB/Raw/RawError.h" |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 15 | |
| 16 | using namespace llvm; |
| 17 | using namespace llvm::pdb; |
| 18 | |
| 19 | ModStream::ModStream(PDBFile &File, const ModInfo &Module) |
| 20 | : Mod(Module), Stream(Module.getModuleStreamIndex(), File) {} |
| 21 | |
| 22 | ModStream::~ModStream() {} |
| 23 | |
| 24 | Error ModStream::reload() { |
Zachary Turner | d5d37dc | 2016-05-25 20:37:03 +0000 | [diff] [blame] | 25 | codeview::StreamReader Reader(Stream); |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 26 | |
| 27 | uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize(); |
| 28 | uint32_t C11Size = Mod.getLineInfoByteSize(); |
| 29 | uint32_t C13Size = Mod.getC13LineInfoByteSize(); |
| 30 | |
| 31 | if (C11Size > 0 && C13Size > 0) |
| 32 | return llvm::make_error<RawError>(raw_error_code::corrupt_file, |
| 33 | "Module has both C11 and C13 line info"); |
| 34 | |
Zachary Turner | 1de49c9 | 2016-05-27 18:47:20 +0000 | [diff] [blame] | 35 | codeview::StreamRef S; |
| 36 | |
| 37 | uint32_t SymbolSubstreamSig = 0; |
| 38 | if (auto EC = Reader.readInteger(SymbolSubstreamSig)) |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 39 | return EC; |
Zachary Turner | 1de49c9 | 2016-05-27 18:47:20 +0000 | [diff] [blame] | 40 | if (auto EC = Reader.readArray(SymbolsSubstream, SymbolSize - 4)) |
| 41 | return EC; |
| 42 | |
Zachary Turner | 8dbe362 | 2016-05-27 01:54:44 +0000 | [diff] [blame] | 43 | if (auto EC = Reader.readStreamRef(LinesSubstream, C11Size)) |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 44 | return EC; |
Zachary Turner | 8dbe362 | 2016-05-27 01:54:44 +0000 | [diff] [blame] | 45 | if (auto EC = Reader.readStreamRef(C13LinesSubstream, C13Size)) |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 46 | return EC; |
| 47 | |
| 48 | uint32_t GlobalRefsSize; |
| 49 | if (auto EC = Reader.readInteger(GlobalRefsSize)) |
| 50 | return EC; |
Zachary Turner | 8dbe362 | 2016-05-27 01:54:44 +0000 | [diff] [blame] | 51 | if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize)) |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 52 | return EC; |
| 53 | if (Reader.bytesRemaining() > 0) |
| 54 | return llvm::make_error<RawError>(raw_error_code::corrupt_file, |
| 55 | "Unexpected bytes in module stream."); |
| 56 | |
| 57 | return Error::success(); |
| 58 | } |
| 59 | |
Zachary Turner | 0d43c1c | 2016-05-28 05:21:57 +0000 | [diff] [blame^] | 60 | iterator_range<codeview::CVSymbolArray::Iterator> |
| 61 | ModStream::symbols(bool *HadError) const { |
Zachary Turner | 1de49c9 | 2016-05-27 18:47:20 +0000 | [diff] [blame] | 62 | return llvm::make_range(SymbolsSubstream.begin(), SymbolsSubstream.end()); |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 63 | } |