blob: 39e9dfaf3e29418463d2f57652bcd6589c4d30cf [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
Zachary Turnerbac69d32016-07-22 19:56:05 +000012#include "llvm/DebugInfo/Msf/IndexedStreamData.h"
13#include "llvm/DebugInfo/Msf/StreamReader.h"
Zachary Turner06c2b4b2016-05-09 17:45:21 +000014#include "llvm/DebugInfo/PDB/Raw/ModInfo.h"
Zachary Turner90b8b8d2016-05-31 22:41:52 +000015#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
Zachary Turner06c2b4b2016-05-09 17:45:21 +000016#include "llvm/DebugInfo/PDB/Raw/RawError.h"
Zachary Turner7eb6d352016-06-02 20:11:22 +000017#include "llvm/DebugInfo/PDB/Raw/RawTypes.h"
Zachary Turner06c2b4b2016-05-09 17:45:21 +000018
19using namespace llvm;
Zachary Turnerbac69d32016-07-22 19:56:05 +000020using namespace llvm::msf;
Zachary Turner06c2b4b2016-05-09 17:45:21 +000021using namespace llvm::pdb;
22
Zachary Turnera1657a92016-06-08 17:26:39 +000023ModStream::ModStream(const ModInfo &Module,
24 std::unique_ptr<MappedBlockStream> Stream)
25 : Mod(Module), Stream(std::move(Stream)) {}
Zachary Turner06c2b4b2016-05-09 17:45:21 +000026
27ModStream::~ModStream() {}
28
29Error ModStream::reload() {
Zachary Turnerbac69d32016-07-22 19:56:05 +000030 StreamReader Reader(*Stream);
Zachary Turner06c2b4b2016-05-09 17:45:21 +000031
32 uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize();
33 uint32_t C11Size = Mod.getLineInfoByteSize();
34 uint32_t C13Size = Mod.getC13LineInfoByteSize();
35
36 if (C11Size > 0 && C13Size > 0)
37 return llvm::make_error<RawError>(raw_error_code::corrupt_file,
38 "Module has both C11 and C13 line info");
39
Zachary Turnerbac69d32016-07-22 19:56:05 +000040 StreamRef S;
Zachary Turner1de49c92016-05-27 18:47:20 +000041
42 uint32_t SymbolSubstreamSig = 0;
43 if (auto EC = Reader.readInteger(SymbolSubstreamSig))
Zachary Turner06c2b4b2016-05-09 17:45:21 +000044 return EC;
Zachary Turner1de49c92016-05-27 18:47:20 +000045 if (auto EC = Reader.readArray(SymbolsSubstream, SymbolSize - 4))
46 return EC;
47
Zachary Turner8dbe3622016-05-27 01:54:44 +000048 if (auto EC = Reader.readStreamRef(LinesSubstream, C11Size))
Zachary Turner06c2b4b2016-05-09 17:45:21 +000049 return EC;
Zachary Turner8dbe3622016-05-27 01:54:44 +000050 if (auto EC = Reader.readStreamRef(C13LinesSubstream, C13Size))
Zachary Turner06c2b4b2016-05-09 17:45:21 +000051 return EC;
Zachary Turner7eb6d352016-06-02 20:11:22 +000052
Zachary Turnerbac69d32016-07-22 19:56:05 +000053 StreamReader LineReader(C13LinesSubstream);
Zachary Turner7eb6d352016-06-02 20:11:22 +000054 if (auto EC = LineReader.readArray(LineInfo, LineReader.bytesRemaining()))
Zachary Turner93839cb2016-06-02 05:07:49 +000055 return EC;
Zachary Turner06c2b4b2016-05-09 17:45:21 +000056
57 uint32_t GlobalRefsSize;
58 if (auto EC = Reader.readInteger(GlobalRefsSize))
59 return EC;
Zachary Turner8dbe3622016-05-27 01:54:44 +000060 if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize))
Zachary Turner06c2b4b2016-05-09 17:45:21 +000061 return EC;
62 if (Reader.bytesRemaining() > 0)
63 return llvm::make_error<RawError>(raw_error_code::corrupt_file,
64 "Unexpected bytes in module stream.");
65
66 return Error::success();
67}
68
Zachary Turner0d43c1c2016-05-28 05:21:57 +000069iterator_range<codeview::CVSymbolArray::Iterator>
70ModStream::symbols(bool *HadError) const {
Reid Kleckner64b16172016-07-01 00:37:49 +000071 // It's OK if the stream is empty.
72 if (SymbolsSubstream.getUnderlyingStream().getLength() == 0)
73 return llvm::make_range(SymbolsSubstream.end(), SymbolsSubstream.end());
David Majnemera7c29322016-06-01 18:13:04 +000074 return llvm::make_range(SymbolsSubstream.begin(HadError),
75 SymbolsSubstream.end());
Zachary Turner06c2b4b2016-05-09 17:45:21 +000076}
Zachary Turner7eb6d352016-06-02 20:11:22 +000077
Zachary Turnera96cce62016-06-03 03:25:59 +000078iterator_range<codeview::ModuleSubstreamArray::Iterator>
Zachary Turner7eb6d352016-06-02 20:11:22 +000079ModStream::lines(bool *HadError) const {
80 return llvm::make_range(LineInfo.begin(HadError), LineInfo.end());
81}
Zachary Turner8848a7a2016-07-06 18:05:57 +000082
83Error ModStream::commit() { return Error::success(); }