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" |
| 11 | #include "llvm/DebugInfo/PDB/Raw/ModInfo.h" |
| 12 | #include "llvm/DebugInfo/PDB/Raw/RawError.h" |
| 13 | #include "llvm/DebugInfo/PDB/Raw/StreamReader.h" |
| 14 | |
| 15 | using namespace llvm; |
| 16 | using namespace llvm::pdb; |
| 17 | |
| 18 | ModStream::ModStream(PDBFile &File, const ModInfo &Module) |
| 19 | : Mod(Module), Stream(Module.getModuleStreamIndex(), File) {} |
| 20 | |
| 21 | ModStream::~ModStream() {} |
| 22 | |
| 23 | Error ModStream::reload() { |
| 24 | StreamReader Reader(Stream); |
| 25 | |
| 26 | uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize(); |
| 27 | uint32_t C11Size = Mod.getLineInfoByteSize(); |
| 28 | uint32_t C13Size = Mod.getC13LineInfoByteSize(); |
| 29 | |
| 30 | if (C11Size > 0 && C13Size > 0) |
| 31 | return llvm::make_error<RawError>(raw_error_code::corrupt_file, |
| 32 | "Module has both C11 and C13 line info"); |
| 33 | |
| 34 | if (auto EC = SymbolsSubstream.initialize(Reader, SymbolSize)) |
| 35 | return EC; |
| 36 | if (auto EC = LinesSubstream.initialize(Reader, C11Size)) |
| 37 | return EC; |
| 38 | if (auto EC = C13LinesSubstream.initialize(Reader, C13Size)) |
| 39 | return EC; |
| 40 | |
| 41 | uint32_t GlobalRefsSize; |
| 42 | if (auto EC = Reader.readInteger(GlobalRefsSize)) |
| 43 | return EC; |
| 44 | if (auto EC = GlobalRefsSubstream.initialize(Reader, GlobalRefsSize)) |
| 45 | return EC; |
| 46 | if (Reader.bytesRemaining() > 0) |
| 47 | return llvm::make_error<RawError>(raw_error_code::corrupt_file, |
| 48 | "Unexpected bytes in module stream."); |
| 49 | |
| 50 | return Error::success(); |
| 51 | } |
| 52 | |
| 53 | iterator_range<codeview::SymbolIterator> ModStream::symbols() const { |
| 54 | return codeview::makeSymbolRange(SymbolsSubstream.data().slice(4)); |
| 55 | } |