blob: c359e7757d0e409747d3f098120559531c2ae477 [file] [log] [blame]
Zachary Turner06c2b4b2016-05-09 17:45:21 +00001//===- 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 Turnerd5d37dc2016-05-25 20:37:03 +000011
12#include "llvm/DebugInfo/CodeView/StreamReader.h"
Zachary Turner06c2b4b2016-05-09 17:45:21 +000013#include "llvm/DebugInfo/PDB/Raw/ModInfo.h"
14#include "llvm/DebugInfo/PDB/Raw/RawError.h"
Zachary Turner06c2b4b2016-05-09 17:45:21 +000015
16using namespace llvm;
17using namespace llvm::pdb;
18
19ModStream::ModStream(PDBFile &File, const ModInfo &Module)
20 : Mod(Module), Stream(Module.getModuleStreamIndex(), File) {}
21
22ModStream::~ModStream() {}
23
24Error ModStream::reload() {
Zachary Turnerd5d37dc2016-05-25 20:37:03 +000025 codeview::StreamReader Reader(Stream);
Zachary Turner06c2b4b2016-05-09 17:45:21 +000026
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
35 if (auto EC = SymbolsSubstream.initialize(Reader, SymbolSize))
36 return EC;
37 if (auto EC = LinesSubstream.initialize(Reader, C11Size))
38 return EC;
39 if (auto EC = C13LinesSubstream.initialize(Reader, C13Size))
40 return EC;
41
42 uint32_t GlobalRefsSize;
43 if (auto EC = Reader.readInteger(GlobalRefsSize))
44 return EC;
45 if (auto EC = GlobalRefsSubstream.initialize(Reader, GlobalRefsSize))
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
54iterator_range<codeview::SymbolIterator> ModStream::symbols() const {
Zachary Turneraaad5742016-05-23 23:41:13 +000055 return codeview::makeSymbolRange(SymbolsSubstream.data().slice(4), nullptr);
Zachary Turner06c2b4b2016-05-09 17:45:21 +000056}