blob: 38d3f2f23e389d399a6a5a879128ccd125ac573c [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
Chad Rosier6c247c82016-05-27 18:31:02 +000035 if (auto EC = SymbolsSubstream.load(Reader, SymbolSize))
Zachary Turner06c2b4b2016-05-09 17:45:21 +000036 return EC;
Zachary Turner8dbe3622016-05-27 01:54:44 +000037 if (auto EC = Reader.readStreamRef(LinesSubstream, C11Size))
Zachary Turner06c2b4b2016-05-09 17:45:21 +000038 return EC;
Zachary Turner8dbe3622016-05-27 01:54:44 +000039 if (auto EC = Reader.readStreamRef(C13LinesSubstream, C13Size))
Zachary Turner06c2b4b2016-05-09 17:45:21 +000040 return EC;
41
42 uint32_t GlobalRefsSize;
43 if (auto EC = Reader.readInteger(GlobalRefsSize))
44 return EC;
Zachary Turner8dbe3622016-05-27 01:54:44 +000045 if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize))
Zachary Turner06c2b4b2016-05-09 17:45:21 +000046 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 Rosier6c247c82016-05-27 18:31:02 +000054iterator_range<codeview::SymbolIterator> ModStream::symbols() const {
55 return codeview::makeSymbolRange(SymbolsSubstream.data().slice(4), nullptr);
Zachary Turner06c2b4b2016-05-09 17:45:21 +000056}