blob: 88c6b7c2444767f626513fb3dc3d2178fccb9a87 [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
Zachary Turner1de49c92016-05-27 18:47:20 +000035 codeview::StreamRef S;
36
37 uint32_t SymbolSubstreamSig = 0;
38 if (auto EC = Reader.readInteger(SymbolSubstreamSig))
Zachary Turner06c2b4b2016-05-09 17:45:21 +000039 return EC;
Zachary Turner1de49c92016-05-27 18:47:20 +000040 if (auto EC = Reader.readArray(SymbolsSubstream, SymbolSize - 4))
41 return EC;
42
Zachary Turner8dbe3622016-05-27 01:54:44 +000043 if (auto EC = Reader.readStreamRef(LinesSubstream, C11Size))
Zachary Turner06c2b4b2016-05-09 17:45:21 +000044 return EC;
Zachary Turner8dbe3622016-05-27 01:54:44 +000045 if (auto EC = Reader.readStreamRef(C13LinesSubstream, C13Size))
Zachary Turner06c2b4b2016-05-09 17:45:21 +000046 return EC;
47
48 uint32_t GlobalRefsSize;
49 if (auto EC = Reader.readInteger(GlobalRefsSize))
50 return EC;
Zachary Turner8dbe3622016-05-27 01:54:44 +000051 if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize))
Zachary Turner06c2b4b2016-05-09 17:45:21 +000052 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 Turner0d43c1c2016-05-28 05:21:57 +000060iterator_range<codeview::CVSymbolArray::Iterator>
61ModStream::symbols(bool *HadError) const {
Zachary Turner1de49c92016-05-27 18:47:20 +000062 return llvm::make_range(SymbolsSubstream.begin(), SymbolsSubstream.end());
Zachary Turner06c2b4b2016-05-09 17:45:21 +000063}