blob: 14c55906e0622e3d6cabeadec7f8609049651cde [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"
Zachary Turner90b8b8d2016-05-31 22:41:52 +000014#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
Zachary Turner06c2b4b2016-05-09 17:45:21 +000015#include "llvm/DebugInfo/PDB/Raw/RawError.h"
Zachary Turner7eb6d352016-06-02 20:11:22 +000016#include "llvm/DebugInfo/PDB/Raw/RawTypes.h"
Zachary Turner06c2b4b2016-05-09 17:45:21 +000017
18using namespace llvm;
19using namespace llvm::pdb;
20
21ModStream::ModStream(PDBFile &File, const ModInfo &Module)
22 : Mod(Module), Stream(Module.getModuleStreamIndex(), File) {}
23
24ModStream::~ModStream() {}
25
26Error ModStream::reload() {
Zachary Turnerd5d37dc2016-05-25 20:37:03 +000027 codeview::StreamReader Reader(Stream);
Zachary Turner06c2b4b2016-05-09 17:45:21 +000028
29 uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize();
30 uint32_t C11Size = Mod.getLineInfoByteSize();
31 uint32_t C13Size = Mod.getC13LineInfoByteSize();
32
33 if (C11Size > 0 && C13Size > 0)
34 return llvm::make_error<RawError>(raw_error_code::corrupt_file,
35 "Module has both C11 and C13 line info");
36
Zachary Turner1de49c92016-05-27 18:47:20 +000037 codeview::StreamRef S;
38
39 uint32_t SymbolSubstreamSig = 0;
40 if (auto EC = Reader.readInteger(SymbolSubstreamSig))
Zachary Turner06c2b4b2016-05-09 17:45:21 +000041 return EC;
Zachary Turner1de49c92016-05-27 18:47:20 +000042 if (auto EC = Reader.readArray(SymbolsSubstream, SymbolSize - 4))
43 return EC;
44
Zachary Turner8dbe3622016-05-27 01:54:44 +000045 if (auto EC = Reader.readStreamRef(LinesSubstream, C11Size))
Zachary Turner06c2b4b2016-05-09 17:45:21 +000046 return EC;
Zachary Turner8dbe3622016-05-27 01:54:44 +000047 if (auto EC = Reader.readStreamRef(C13LinesSubstream, C13Size))
Zachary Turner06c2b4b2016-05-09 17:45:21 +000048 return EC;
Zachary Turner7eb6d352016-06-02 20:11:22 +000049
50 codeview::StreamReader LineReader(C13LinesSubstream);
51 if (auto EC = LineReader.readArray(LineInfo, LineReader.bytesRemaining()))
Zachary Turner93839cb2016-06-02 05:07:49 +000052 return EC;
Zachary Turner06c2b4b2016-05-09 17:45:21 +000053
54 uint32_t GlobalRefsSize;
55 if (auto EC = Reader.readInteger(GlobalRefsSize))
56 return EC;
Zachary Turner8dbe3622016-05-27 01:54:44 +000057 if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize))
Zachary Turner06c2b4b2016-05-09 17:45:21 +000058 return EC;
59 if (Reader.bytesRemaining() > 0)
60 return llvm::make_error<RawError>(raw_error_code::corrupt_file,
61 "Unexpected bytes in module stream.");
62
63 return Error::success();
64}
65
Zachary Turner0d43c1c2016-05-28 05:21:57 +000066iterator_range<codeview::CVSymbolArray::Iterator>
67ModStream::symbols(bool *HadError) const {
David Majnemera7c29322016-06-01 18:13:04 +000068 return llvm::make_range(SymbolsSubstream.begin(HadError),
69 SymbolsSubstream.end());
Zachary Turner06c2b4b2016-05-09 17:45:21 +000070}
Zachary Turner7eb6d352016-06-02 20:11:22 +000071
Zachary Turnera96cce62016-06-03 03:25:59 +000072iterator_range<codeview::ModuleSubstreamArray::Iterator>
Zachary Turner7eb6d352016-06-02 20:11:22 +000073ModStream::lines(bool *HadError) const {
74 return llvm::make_range(LineInfo.begin(HadError), LineInfo.end());
75}