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 | |
Chad Rosier | 6c247c8 | 2016-05-27 18:31:02 +0000 | [diff] [blame^] | 35 | if (auto EC = SymbolsSubstream.load(Reader, SymbolSize)) |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 36 | return EC; |
Zachary Turner | 8dbe362 | 2016-05-27 01:54:44 +0000 | [diff] [blame] | 37 | if (auto EC = Reader.readStreamRef(LinesSubstream, C11Size)) |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 38 | return EC; |
Zachary Turner | 8dbe362 | 2016-05-27 01:54:44 +0000 | [diff] [blame] | 39 | if (auto EC = Reader.readStreamRef(C13LinesSubstream, C13Size)) |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 40 | return EC; |
| 41 | |
| 42 | uint32_t GlobalRefsSize; |
| 43 | if (auto EC = Reader.readInteger(GlobalRefsSize)) |
| 44 | return EC; |
Zachary Turner | 8dbe362 | 2016-05-27 01:54:44 +0000 | [diff] [blame] | 45 | if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize)) |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 46 | return EC; |
| 47 | if (Reader.bytesRemaining() > 0) |
| 48 | return llvm::make_error<RawError>(raw_error_code::corrupt_file, |
| 49 | "Unexpected bytes in module stream."); |
| 50 | |
| 51 | return Error::success(); |
| 52 | } |
| 53 | |
Chad Rosier | 6c247c8 | 2016-05-27 18:31:02 +0000 | [diff] [blame^] | 54 | iterator_range<codeview::SymbolIterator> ModStream::symbols() const { |
| 55 | return codeview::makeSymbolRange(SymbolsSubstream.data().slice(4), nullptr); |
Zachary Turner | 06c2b4b | 2016-05-09 17:45:21 +0000 | [diff] [blame] | 56 | } |