blob: ac40330c5dccebfbcf0db04cf2d1604cfedb9766 [file] [log] [blame]
Zachary Turnerdbeaea72016-07-11 21:45:26 +00001//===- DbiStreamBuilder.cpp - PDB Dbi Stream Creation -----------*- C++ -*-===//
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
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000010#include "llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h"
Zachary Turnerdbeaea72016-07-11 21:45:26 +000011
Rui Ueyamaf9904042016-10-11 19:43:12 +000012#include "llvm/ADT/ArrayRef.h"
Zachary Turnerd2684b72017-02-25 00:33:34 +000013#include "llvm/DebugInfo/MSF/BinaryStreamWriter.h"
Zachary Turneraf299ea2017-02-25 00:44:30 +000014#include "llvm/DebugInfo/MSF/BinaryStreamWriter.h"
Zachary Turner620961d2016-09-14 23:00:02 +000015#include "llvm/DebugInfo/MSF/MSFBuilder.h"
Zachary Turnera3225b02016-07-29 20:56:36 +000016#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000017#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
18#include "llvm/DebugInfo/PDB/Native/RawError.h"
Rui Ueyamaddc79222016-10-31 17:38:56 +000019#include "llvm/Object/COFF.h"
20#include "llvm/Support/COFF.h"
Zachary Turnerdbeaea72016-07-11 21:45:26 +000021
22using namespace llvm;
23using namespace llvm::codeview;
Zachary Turnerbac69d32016-07-22 19:56:05 +000024using namespace llvm::msf;
Zachary Turnerdbeaea72016-07-11 21:45:26 +000025using namespace llvm::pdb;
26
Zachary Turnerd218c262016-07-22 15:46:37 +000027namespace {
28class ModiSubstreamBuilder {};
29}
30
Zachary Turner620961d2016-09-14 23:00:02 +000031DbiStreamBuilder::DbiStreamBuilder(msf::MSFBuilder &Msf)
32 : Msf(Msf), Allocator(Msf.getAllocator()), Age(1), BuildNumber(0),
33 PdbDllVersion(0), PdbDllRbld(0), Flags(0), MachineType(PDB_Machine::x86),
Reid Kleckner5d0bc632016-10-11 20:02:57 +000034 Header(nullptr), DbgStreams((int)DbgHeaderType::Max) {}
Zachary Turnerdbeaea72016-07-11 21:45:26 +000035
36void DbiStreamBuilder::setVersionHeader(PdbRaw_DbiVer V) { VerHeader = V; }
37
38void DbiStreamBuilder::setAge(uint32_t A) { Age = A; }
39
40void DbiStreamBuilder::setBuildNumber(uint16_t B) { BuildNumber = B; }
41
42void DbiStreamBuilder::setPdbDllVersion(uint16_t V) { PdbDllVersion = V; }
43
44void DbiStreamBuilder::setPdbDllRbld(uint16_t R) { PdbDllRbld = R; }
45
46void DbiStreamBuilder::setFlags(uint16_t F) { Flags = F; }
47
48void DbiStreamBuilder::setMachineType(PDB_Machine M) { MachineType = M; }
49
Rui Ueyamaf7c9c322016-11-11 23:41:13 +000050void DbiStreamBuilder::setSectionContribs(ArrayRef<SectionContrib> Arr) {
51 SectionContribs = Arr;
52}
53
Rui Ueyamaddc79222016-10-31 17:38:56 +000054void DbiStreamBuilder::setSectionMap(ArrayRef<SecMapEntry> SecMap) {
55 SectionMap = SecMap;
56}
57
Rui Ueyamaf9904042016-10-11 19:43:12 +000058Error DbiStreamBuilder::addDbgStream(pdb::DbgHeaderType Type,
59 ArrayRef<uint8_t> Data) {
60 if (DbgStreams[(int)Type].StreamNumber)
61 return make_error<RawError>(raw_error_code::duplicate_entry,
62 "The specified stream type already exists");
63 auto ExpectedIndex = Msf.addStream(Data.size());
64 if (!ExpectedIndex)
65 return ExpectedIndex.takeError();
66 uint32_t Index = std::move(*ExpectedIndex);
67 DbgStreams[(int)Type].Data = Data;
68 DbgStreams[(int)Type].StreamNumber = Index;
69 return Error::success();
70}
71
Zachary Turnerfaa554b2016-07-15 22:16:56 +000072uint32_t DbiStreamBuilder::calculateSerializedLength() const {
73 // For now we only support serializing the header.
Zachary Turnerb383d622016-07-22 15:46:46 +000074 return sizeof(DbiStreamHeader) + calculateFileInfoSubstreamSize() +
Rui Ueyamaf7c9c322016-11-11 23:41:13 +000075 calculateModiSubstreamSize() + calculateSectionContribsStreamSize() +
76 calculateSectionMapStreamSize() + calculateDbgStreamsSize();
Zachary Turnerd218c262016-07-22 15:46:37 +000077}
78
79Error DbiStreamBuilder::addModuleInfo(StringRef ObjFile, StringRef Module) {
80 auto Entry = llvm::make_unique<ModuleInfo>();
81 ModuleInfo *M = Entry.get();
82 Entry->Mod = Module;
83 Entry->Obj = ObjFile;
84 auto Result = ModuleInfos.insert(std::make_pair(Module, std::move(Entry)));
85 if (!Result.second)
86 return make_error<RawError>(raw_error_code::duplicate_entry,
87 "The specified module already exists");
88 ModuleInfoList.push_back(M);
89 return Error::success();
90}
91
92Error DbiStreamBuilder::addModuleSourceFile(StringRef Module, StringRef File) {
93 auto ModIter = ModuleInfos.find(Module);
94 if (ModIter == ModuleInfos.end())
95 return make_error<RawError>(raw_error_code::no_entry,
96 "The specified module was not found");
97 uint32_t Index = SourceFileNames.size();
98 SourceFileNames.insert(std::make_pair(File, Index));
99 auto &ModEntry = *ModIter;
100 ModEntry.second->SourceFiles.push_back(File);
101 return Error::success();
102}
103
104uint32_t DbiStreamBuilder::calculateModiSubstreamSize() const {
105 uint32_t Size = 0;
106 for (const auto &M : ModuleInfoList) {
Zachary Turnerb383d622016-07-22 15:46:46 +0000107 Size += sizeof(ModuleInfoHeader);
Zachary Turnerd218c262016-07-22 15:46:37 +0000108 Size += M->Mod.size() + 1;
109 Size += M->Obj.size() + 1;
110 }
Rui Ueyamafb1e6d22016-11-16 00:59:27 +0000111 return alignTo(Size, sizeof(uint32_t));
Zachary Turnerd218c262016-07-22 15:46:37 +0000112}
113
Rui Ueyamaf7c9c322016-11-11 23:41:13 +0000114uint32_t DbiStreamBuilder::calculateSectionContribsStreamSize() const {
115 if (SectionContribs.empty())
116 return 0;
117 return sizeof(enum PdbRaw_DbiSecContribVer) +
118 sizeof(SectionContribs[0]) * SectionContribs.size();
Rui Ueyamaa8a68a92016-11-12 00:23:32 +0000119}
Rui Ueyamaf7c9c322016-11-11 23:41:13 +0000120
Rui Ueyamaddc79222016-10-31 17:38:56 +0000121uint32_t DbiStreamBuilder::calculateSectionMapStreamSize() const {
122 if (SectionMap.empty())
123 return 0;
124 return sizeof(SecMapHeader) + sizeof(SecMapEntry) * SectionMap.size();
125}
126
Zachary Turnerd218c262016-07-22 15:46:37 +0000127uint32_t DbiStreamBuilder::calculateFileInfoSubstreamSize() const {
Zachary Turnerd218c262016-07-22 15:46:37 +0000128 uint32_t Size = 0;
129 Size += sizeof(ulittle16_t); // NumModules
130 Size += sizeof(ulittle16_t); // NumSourceFiles
131 Size += ModuleInfoList.size() * sizeof(ulittle16_t); // ModIndices
132 Size += ModuleInfoList.size() * sizeof(ulittle16_t); // ModFileCounts
133 uint32_t NumFileInfos = 0;
134 for (const auto &M : ModuleInfoList)
135 NumFileInfos += M->SourceFiles.size();
136 Size += NumFileInfos * sizeof(ulittle32_t); // FileNameOffsets
137 Size += calculateNamesBufferSize();
Rui Ueyamafb1e6d22016-11-16 00:59:27 +0000138 return alignTo(Size, sizeof(uint32_t));
Zachary Turnerd218c262016-07-22 15:46:37 +0000139}
140
141uint32_t DbiStreamBuilder::calculateNamesBufferSize() const {
142 uint32_t Size = 0;
143 for (const auto &F : SourceFileNames) {
144 Size += F.getKeyLength() + 1; // Names[I];
145 }
146 return Size;
147}
148
Rui Ueyama77be2402016-10-29 00:56:44 +0000149uint32_t DbiStreamBuilder::calculateDbgStreamsSize() const {
150 return DbgStreams.size() * sizeof(uint16_t);
151}
152
Zachary Turnerd218c262016-07-22 15:46:37 +0000153Error DbiStreamBuilder::generateModiSubstream() {
154 uint32_t Size = calculateModiSubstreamSize();
155 auto Data = Allocator.Allocate<uint8_t>(Size);
156
Zachary Turneraf299ea2017-02-25 00:44:30 +0000157 ModInfoBuffer = MutableBinaryByteStream(MutableArrayRef<uint8_t>(Data, Size),
158 llvm::support::little);
Zachary Turnerd218c262016-07-22 15:46:37 +0000159
Zachary Turneraf299ea2017-02-25 00:44:30 +0000160 BinaryStreamWriter ModiWriter(ModInfoBuffer);
Zachary Turnerd218c262016-07-22 15:46:37 +0000161 for (const auto &M : ModuleInfoList) {
Zachary Turnerb383d622016-07-22 15:46:46 +0000162 ModuleInfoHeader Layout = {};
163 Layout.ModDiStream = kInvalidStreamIndex;
Zachary Turnerd218c262016-07-22 15:46:37 +0000164 Layout.NumFiles = M->SourceFiles.size();
165 if (auto EC = ModiWriter.writeObject(Layout))
166 return EC;
Zachary Turneraf299ea2017-02-25 00:44:30 +0000167 if (auto EC = ModiWriter.writeCString(M->Mod))
Zachary Turnerd218c262016-07-22 15:46:37 +0000168 return EC;
Zachary Turneraf299ea2017-02-25 00:44:30 +0000169 if (auto EC = ModiWriter.writeCString(M->Obj))
Zachary Turnerd218c262016-07-22 15:46:37 +0000170 return EC;
171 }
Rui Ueyamafb1e6d22016-11-16 00:59:27 +0000172 if (ModiWriter.bytesRemaining() > sizeof(uint32_t))
Zachary Turnerd218c262016-07-22 15:46:37 +0000173 return make_error<RawError>(raw_error_code::invalid_format,
174 "Unexpected bytes in Modi Stream Data");
175 return Error::success();
176}
177
178Error DbiStreamBuilder::generateFileInfoSubstream() {
179 uint32_t Size = calculateFileInfoSubstreamSize();
180 uint32_t NameSize = calculateNamesBufferSize();
181 auto Data = Allocator.Allocate<uint8_t>(Size);
182 uint32_t NamesOffset = Size - NameSize;
183
Zachary Turneraf299ea2017-02-25 00:44:30 +0000184 FileInfoBuffer = MutableBinaryByteStream(MutableArrayRef<uint8_t>(Data, Size),
185 llvm::support::little);
Zachary Turnerd218c262016-07-22 15:46:37 +0000186
Zachary Turneraf299ea2017-02-25 00:44:30 +0000187 WritableBinaryStreamRef MetadataBuffer =
188 WritableBinaryStreamRef(FileInfoBuffer).keep_front(NamesOffset);
189 BinaryStreamWriter MetadataWriter(MetadataBuffer);
Zachary Turnerd218c262016-07-22 15:46:37 +0000190
Rui Ueyama50701312016-11-16 00:38:33 +0000191 uint16_t ModiCount = std::min<uint32_t>(UINT16_MAX, ModuleInfos.size());
192 uint16_t FileCount = std::min<uint32_t>(UINT16_MAX, SourceFileNames.size());
Zachary Turneraf299ea2017-02-25 00:44:30 +0000193 if (auto EC = MetadataWriter.writeInteger(ModiCount)) // NumModules
Zachary Turnerd218c262016-07-22 15:46:37 +0000194 return EC;
Zachary Turneraf299ea2017-02-25 00:44:30 +0000195 if (auto EC = MetadataWriter.writeInteger(FileCount)) // NumSourceFiles
Zachary Turnerd218c262016-07-22 15:46:37 +0000196 return EC;
197 for (uint16_t I = 0; I < ModiCount; ++I) {
Zachary Turneraf299ea2017-02-25 00:44:30 +0000198 if (auto EC = MetadataWriter.writeInteger(I)) // Mod Indices
Zachary Turnerd218c262016-07-22 15:46:37 +0000199 return EC;
200 }
201 for (const auto MI : ModuleInfoList) {
202 FileCount = static_cast<uint16_t>(MI->SourceFiles.size());
Zachary Turneraf299ea2017-02-25 00:44:30 +0000203 if (auto EC = MetadataWriter.writeInteger(FileCount)) // Mod File Counts
Zachary Turnerd218c262016-07-22 15:46:37 +0000204 return EC;
205 }
206
207 // Before writing the FileNameOffsets array, write the NamesBuffer array.
208 // A side effect of this is that this will actually compute the various
209 // file name offsets, so we can then go back and write the FileNameOffsets
210 // array to the other substream.
Zachary Turneraf299ea2017-02-25 00:44:30 +0000211 NamesBuffer = WritableBinaryStreamRef(FileInfoBuffer).drop_front(NamesOffset);
212 BinaryStreamWriter NameBufferWriter(NamesBuffer);
Zachary Turnerd218c262016-07-22 15:46:37 +0000213 for (auto &Name : SourceFileNames) {
214 Name.second = NameBufferWriter.getOffset();
Zachary Turneraf299ea2017-02-25 00:44:30 +0000215 if (auto EC = NameBufferWriter.writeCString(Name.getKey()))
Zachary Turnerd218c262016-07-22 15:46:37 +0000216 return EC;
217 }
218
219 for (const auto MI : ModuleInfoList) {
220 for (StringRef Name : MI->SourceFiles) {
221 auto Result = SourceFileNames.find(Name);
222 if (Result == SourceFileNames.end())
223 return make_error<RawError>(raw_error_code::no_entry,
224 "The source file was not found.");
Zachary Turneraf299ea2017-02-25 00:44:30 +0000225 if (auto EC = MetadataWriter.writeInteger(Result->second))
Zachary Turnerd218c262016-07-22 15:46:37 +0000226 return EC;
227 }
228 }
229
230 if (NameBufferWriter.bytesRemaining() > 0)
231 return make_error<RawError>(raw_error_code::invalid_format,
232 "The names buffer contained unexpected data.");
233
Rui Ueyamafb1e6d22016-11-16 00:59:27 +0000234 if (MetadataWriter.bytesRemaining() > sizeof(uint32_t))
Zachary Turnerd218c262016-07-22 15:46:37 +0000235 return make_error<RawError>(
236 raw_error_code::invalid_format,
237 "The metadata buffer contained unexpected data.");
238
239 return Error::success();
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000240}
241
Zachary Turnerd66889c2016-07-28 19:12:28 +0000242Error DbiStreamBuilder::finalize() {
243 if (Header)
244 return Error::success();
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000245
Zachary Turnerd66889c2016-07-28 19:12:28 +0000246 DbiStreamHeader *H = Allocator.Allocate<DbiStreamHeader>();
Zachary Turnerd218c262016-07-22 15:46:37 +0000247
248 if (auto EC = generateModiSubstream())
Zachary Turnere98137c2016-07-28 19:18:02 +0000249 return EC;
Zachary Turnerd218c262016-07-22 15:46:37 +0000250 if (auto EC = generateFileInfoSubstream())
Zachary Turnere98137c2016-07-28 19:18:02 +0000251 return EC;
Zachary Turnerd218c262016-07-22 15:46:37 +0000252
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000253 H->VersionHeader = *VerHeader;
254 H->VersionSignature = -1;
255 H->Age = Age;
256 H->BuildNumber = BuildNumber;
257 H->Flags = Flags;
258 H->PdbDllRbld = PdbDllRbld;
259 H->PdbDllVersion = PdbDllVersion;
260 H->MachineType = static_cast<uint16_t>(MachineType);
261
262 H->ECSubstreamSize = 0;
Zachary Turnerd218c262016-07-22 15:46:37 +0000263 H->FileInfoSize = FileInfoBuffer.getLength();
264 H->ModiSubstreamSize = ModInfoBuffer.getLength();
Rui Ueyamaf9904042016-10-11 19:43:12 +0000265 H->OptionalDbgHdrSize = DbgStreams.size() * sizeof(uint16_t);
Rui Ueyamaf7c9c322016-11-11 23:41:13 +0000266 H->SecContrSubstreamSize = calculateSectionContribsStreamSize();
Rui Ueyamaddc79222016-10-31 17:38:56 +0000267 H->SectionMapSize = calculateSectionMapStreamSize();
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000268 H->TypeServerSize = 0;
Zachary Turnerb383d622016-07-22 15:46:46 +0000269 H->SymRecordStreamIndex = kInvalidStreamIndex;
270 H->PublicSymbolStreamIndex = kInvalidStreamIndex;
271 H->MFCTypeServerIndex = kInvalidStreamIndex;
272 H->GlobalSymbolStreamIndex = kInvalidStreamIndex;
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000273
Zachary Turnerd66889c2016-07-28 19:12:28 +0000274 Header = H;
275 return Error::success();
276}
277
Zachary Turner620961d2016-09-14 23:00:02 +0000278Error DbiStreamBuilder::finalizeMsfLayout() {
279 uint32_t Length = calculateSerializedLength();
280 if (auto EC = Msf.setStreamSize(StreamDBI, Length))
281 return EC;
282 return Error::success();
283}
284
Rui Ueyamaddc79222016-10-31 17:38:56 +0000285static uint16_t toSecMapFlags(uint32_t Flags) {
286 uint16_t Ret = 0;
287 if (Flags & COFF::IMAGE_SCN_MEM_READ)
288 Ret |= static_cast<uint16_t>(OMFSegDescFlags::Read);
289 if (Flags & COFF::IMAGE_SCN_MEM_WRITE)
290 Ret |= static_cast<uint16_t>(OMFSegDescFlags::Write);
291 if (Flags & COFF::IMAGE_SCN_MEM_EXECUTE)
292 Ret |= static_cast<uint16_t>(OMFSegDescFlags::Execute);
293 if (Flags & COFF::IMAGE_SCN_MEM_EXECUTE)
294 Ret |= static_cast<uint16_t>(OMFSegDescFlags::Execute);
295 if (!(Flags & COFF::IMAGE_SCN_MEM_16BIT))
296 Ret |= static_cast<uint16_t>(OMFSegDescFlags::AddressIs32Bit);
297
298 // This seems always 1.
299 Ret |= static_cast<uint16_t>(OMFSegDescFlags::IsSelector);
300
301 return Ret;
302}
303
Rui Ueyamaf7c9c322016-11-11 23:41:13 +0000304// A utility function to create Section Contributions
305// for a given input sections.
306std::vector<SectionContrib> DbiStreamBuilder::createSectionContribs(
307 ArrayRef<object::coff_section> SecHdrs) {
308 std::vector<SectionContrib> Ret;
309
310 // Create a SectionContrib for each input section.
311 for (auto &Sec : SecHdrs) {
312 Ret.emplace_back();
313 auto &Entry = Ret.back();
314 memset(&Entry, 0, sizeof(Entry));
315
316 Entry.Off = Sec.PointerToRawData;
317 Entry.Size = Sec.SizeOfRawData;
318 Entry.Characteristics = Sec.Characteristics;
319 }
320 return Ret;
321}
322
Rui Ueyamaddc79222016-10-31 17:38:56 +0000323// A utility function to create a Section Map for a given list of COFF sections.
324//
325// A Section Map seem to be a copy of a COFF section list in other format.
326// I don't know why a PDB file contains both a COFF section header and
327// a Section Map, but it seems it must be present in a PDB.
328std::vector<SecMapEntry> DbiStreamBuilder::createSectionMap(
329 ArrayRef<llvm::object::coff_section> SecHdrs) {
330 std::vector<SecMapEntry> Ret;
331 int Idx = 0;
332
333 auto Add = [&]() -> SecMapEntry & {
334 Ret.emplace_back();
335 auto &Entry = Ret.back();
336 memset(&Entry, 0, sizeof(Entry));
337
338 Entry.Frame = Idx + 1;
339
340 // We don't know the meaning of these fields yet.
341 Entry.SecName = UINT16_MAX;
342 Entry.ClassName = UINT16_MAX;
343
344 return Entry;
345 };
346
347 for (auto &Hdr : SecHdrs) {
348 auto &Entry = Add();
349 Entry.Flags = toSecMapFlags(Hdr.Characteristics);
350 Entry.SecByteLength = Hdr.VirtualSize;
351 ++Idx;
352 }
353
354 // The last entry is for absolute symbols.
355 auto &Entry = Add();
356 Entry.Flags = static_cast<uint16_t>(OMFSegDescFlags::AddressIs32Bit) |
357 static_cast<uint16_t>(OMFSegDescFlags::IsAbsoluteAddress);
358 Entry.SecByteLength = UINT32_MAX;
359
360 return Ret;
361}
362
Zachary Turnera3225b02016-07-29 20:56:36 +0000363Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout,
Zachary Turneraf299ea2017-02-25 00:44:30 +0000364 WritableBinaryStreamRef Buffer) {
Rui Ueyamad1d8c8312016-08-03 23:43:23 +0000365 if (auto EC = finalize())
366 return EC;
367
Zachary Turnerd66889c2016-07-28 19:12:28 +0000368 auto InfoS =
369 WritableMappedBlockStream::createIndexedStream(Layout, Buffer, StreamDBI);
370
Zachary Turneraf299ea2017-02-25 00:44:30 +0000371 BinaryStreamWriter Writer(*InfoS);
Zachary Turnerd66889c2016-07-28 19:12:28 +0000372 if (auto EC = Writer.writeObject(*Header))
373 return EC;
374
375 if (auto EC = Writer.writeStreamRef(ModInfoBuffer))
376 return EC;
Rui Ueyamaddc79222016-10-31 17:38:56 +0000377
Rui Ueyamaf7c9c322016-11-11 23:41:13 +0000378 if (!SectionContribs.empty()) {
Zachary Turneraf299ea2017-02-25 00:44:30 +0000379 if (auto EC = Writer.writeEnum(DbiSecContribVer60))
Rui Ueyamaf7c9c322016-11-11 23:41:13 +0000380 return EC;
381 if (auto EC = Writer.writeArray(SectionContribs))
382 return EC;
383 }
384
Rui Ueyamaddc79222016-10-31 17:38:56 +0000385 if (!SectionMap.empty()) {
386 ulittle16_t Size = static_cast<ulittle16_t>(SectionMap.size());
387 SecMapHeader SMHeader = {Size, Size};
388 if (auto EC = Writer.writeObject(SMHeader))
389 return EC;
390 if (auto EC = Writer.writeArray(SectionMap))
391 return EC;
392 }
393
Zachary Turnerd66889c2016-07-28 19:12:28 +0000394 if (auto EC = Writer.writeStreamRef(FileInfoBuffer))
395 return EC;
Rui Ueyamaddc79222016-10-31 17:38:56 +0000396
Rui Ueyamaf9904042016-10-11 19:43:12 +0000397 for (auto &Stream : DbgStreams)
Zachary Turneraf299ea2017-02-25 00:44:30 +0000398 if (auto EC = Writer.writeInteger(Stream.StreamNumber))
Rui Ueyamaf9904042016-10-11 19:43:12 +0000399 return EC;
400
401 for (auto &Stream : DbgStreams) {
402 if (Stream.StreamNumber == kInvalidStreamIndex)
403 continue;
404 auto WritableStream = WritableMappedBlockStream::createIndexedStream(
405 Layout, Buffer, Stream.StreamNumber);
Zachary Turneraf299ea2017-02-25 00:44:30 +0000406 BinaryStreamWriter DbgStreamWriter(*WritableStream);
Rui Ueyamaf9904042016-10-11 19:43:12 +0000407 if (auto EC = DbgStreamWriter.writeArray(Stream.Data))
408 return EC;
409 }
Zachary Turnerd66889c2016-07-28 19:12:28 +0000410
411 if (Writer.bytesRemaining() > 0)
412 return make_error<RawError>(raw_error_code::invalid_format,
413 "Unexpected bytes found in DBI Stream");
414 return Error::success();
415}