blob: 62bda65cd99df3bcebe419692d1ca0e35c675457 [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 Turner620961d2016-09-14 23:00:02 +000013#include "llvm/DebugInfo/MSF/MSFBuilder.h"
Zachary Turnera3225b02016-07-29 20:56:36 +000014#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
Zachary Turner67c56012017-04-27 16:11:19 +000015#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000016#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
17#include "llvm/DebugInfo/PDB/Native/RawError.h"
Rui Ueyamaddc79222016-10-31 17:38:56 +000018#include "llvm/Object/COFF.h"
Zachary Turnerd9dc2822017-03-02 20:52:51 +000019#include "llvm/Support/BinaryStreamWriter.h"
Rui Ueyamaddc79222016-10-31 17:38:56 +000020#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 Turner620961d2016-09-14 23:00:02 +000027DbiStreamBuilder::DbiStreamBuilder(msf::MSFBuilder &Msf)
28 : Msf(Msf), Allocator(Msf.getAllocator()), Age(1), BuildNumber(0),
29 PdbDllVersion(0), PdbDllRbld(0), Flags(0), MachineType(PDB_Machine::x86),
Reid Kleckner5d0bc632016-10-11 20:02:57 +000030 Header(nullptr), DbgStreams((int)DbgHeaderType::Max) {}
Zachary Turnerdbeaea72016-07-11 21:45:26 +000031
Zachary Turnerea4e6072017-03-15 22:18:53 +000032DbiStreamBuilder::~DbiStreamBuilder() {}
33
Zachary Turnerdbeaea72016-07-11 21:45:26 +000034void DbiStreamBuilder::setVersionHeader(PdbRaw_DbiVer V) { VerHeader = V; }
35
36void DbiStreamBuilder::setAge(uint32_t A) { Age = A; }
37
38void DbiStreamBuilder::setBuildNumber(uint16_t B) { BuildNumber = B; }
39
40void DbiStreamBuilder::setPdbDllVersion(uint16_t V) { PdbDllVersion = V; }
41
42void DbiStreamBuilder::setPdbDllRbld(uint16_t R) { PdbDllRbld = R; }
43
44void DbiStreamBuilder::setFlags(uint16_t F) { Flags = F; }
45
46void DbiStreamBuilder::setMachineType(PDB_Machine M) { MachineType = M; }
47
Rui Ueyamaf7c9c322016-11-11 23:41:13 +000048void DbiStreamBuilder::setSectionContribs(ArrayRef<SectionContrib> Arr) {
49 SectionContribs = Arr;
50}
51
Rui Ueyamaddc79222016-10-31 17:38:56 +000052void DbiStreamBuilder::setSectionMap(ArrayRef<SecMapEntry> SecMap) {
53 SectionMap = SecMap;
54}
55
Rui Ueyamaf9904042016-10-11 19:43:12 +000056Error DbiStreamBuilder::addDbgStream(pdb::DbgHeaderType Type,
57 ArrayRef<uint8_t> Data) {
58 if (DbgStreams[(int)Type].StreamNumber)
59 return make_error<RawError>(raw_error_code::duplicate_entry,
60 "The specified stream type already exists");
61 auto ExpectedIndex = Msf.addStream(Data.size());
62 if (!ExpectedIndex)
63 return ExpectedIndex.takeError();
64 uint32_t Index = std::move(*ExpectedIndex);
65 DbgStreams[(int)Type].Data = Data;
66 DbgStreams[(int)Type].StreamNumber = Index;
67 return Error::success();
68}
69
Zachary Turnerfaa554b2016-07-15 22:16:56 +000070uint32_t DbiStreamBuilder::calculateSerializedLength() const {
71 // For now we only support serializing the header.
Zachary Turnerb383d622016-07-22 15:46:46 +000072 return sizeof(DbiStreamHeader) + calculateFileInfoSubstreamSize() +
Rui Ueyamaf7c9c322016-11-11 23:41:13 +000073 calculateModiSubstreamSize() + calculateSectionContribsStreamSize() +
74 calculateSectionMapStreamSize() + calculateDbgStreamsSize();
Zachary Turnerd218c262016-07-22 15:46:37 +000075}
76
Zachary Turner67c56012017-04-27 16:11:19 +000077Expected<DbiModuleDescriptorBuilder &>
Zachary Turnerea4e6072017-03-15 22:18:53 +000078DbiStreamBuilder::addModuleInfo(StringRef ModuleName) {
79 uint32_t Index = ModiList.size();
Zachary Turner67c56012017-04-27 16:11:19 +000080 auto MIB =
81 llvm::make_unique<DbiModuleDescriptorBuilder>(ModuleName, Index, Msf);
Zachary Turnerea4e6072017-03-15 22:18:53 +000082 auto M = MIB.get();
83 auto Result = ModiMap.insert(std::make_pair(ModuleName, std::move(MIB)));
84
Zachary Turnerd218c262016-07-22 15:46:37 +000085 if (!Result.second)
86 return make_error<RawError>(raw_error_code::duplicate_entry,
87 "The specified module already exists");
Zachary Turnerea4e6072017-03-15 22:18:53 +000088 ModiList.push_back(M);
89 return *M;
Zachary Turnerd218c262016-07-22 15:46:37 +000090}
91
92Error DbiStreamBuilder::addModuleSourceFile(StringRef Module, StringRef File) {
Zachary Turnerea4e6072017-03-15 22:18:53 +000093 auto ModIter = ModiMap.find(Module);
94 if (ModIter == ModiMap.end())
Zachary Turnerd218c262016-07-22 15:46:37 +000095 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;
Zachary Turnerea4e6072017-03-15 22:18:53 +0000100 ModEntry.second->addSourceFile(File);
Zachary Turnerd218c262016-07-22 15:46:37 +0000101 return Error::success();
102}
103
104uint32_t DbiStreamBuilder::calculateModiSubstreamSize() const {
105 uint32_t Size = 0;
Zachary Turnerea4e6072017-03-15 22:18:53 +0000106 for (const auto &M : ModiList)
107 Size += M->calculateSerializedLength();
108 return Size;
Zachary Turnerd218c262016-07-22 15:46:37 +0000109}
110
Rui Ueyamaf7c9c322016-11-11 23:41:13 +0000111uint32_t DbiStreamBuilder::calculateSectionContribsStreamSize() const {
112 if (SectionContribs.empty())
113 return 0;
114 return sizeof(enum PdbRaw_DbiSecContribVer) +
115 sizeof(SectionContribs[0]) * SectionContribs.size();
Rui Ueyamaa8a68a92016-11-12 00:23:32 +0000116}
Rui Ueyamaf7c9c322016-11-11 23:41:13 +0000117
Rui Ueyamaddc79222016-10-31 17:38:56 +0000118uint32_t DbiStreamBuilder::calculateSectionMapStreamSize() const {
119 if (SectionMap.empty())
120 return 0;
121 return sizeof(SecMapHeader) + sizeof(SecMapEntry) * SectionMap.size();
122}
123
Zachary Turnerd218c262016-07-22 15:46:37 +0000124uint32_t DbiStreamBuilder::calculateFileInfoSubstreamSize() const {
Zachary Turnerd218c262016-07-22 15:46:37 +0000125 uint32_t Size = 0;
126 Size += sizeof(ulittle16_t); // NumModules
127 Size += sizeof(ulittle16_t); // NumSourceFiles
Zachary Turnerea4e6072017-03-15 22:18:53 +0000128 Size += ModiList.size() * sizeof(ulittle16_t); // ModIndices
129 Size += ModiList.size() * sizeof(ulittle16_t); // ModFileCounts
Zachary Turnerd218c262016-07-22 15:46:37 +0000130 uint32_t NumFileInfos = 0;
Zachary Turnerea4e6072017-03-15 22:18:53 +0000131 for (const auto &M : ModiList)
132 NumFileInfos += M->source_files().size();
Zachary Turnerd218c262016-07-22 15:46:37 +0000133 Size += NumFileInfos * sizeof(ulittle32_t); // FileNameOffsets
134 Size += calculateNamesBufferSize();
Rui Ueyamafb1e6d22016-11-16 00:59:27 +0000135 return alignTo(Size, sizeof(uint32_t));
Zachary Turnerd218c262016-07-22 15:46:37 +0000136}
137
138uint32_t DbiStreamBuilder::calculateNamesBufferSize() const {
139 uint32_t Size = 0;
140 for (const auto &F : SourceFileNames) {
141 Size += F.getKeyLength() + 1; // Names[I];
142 }
143 return Size;
144}
145
Rui Ueyama77be2402016-10-29 00:56:44 +0000146uint32_t DbiStreamBuilder::calculateDbgStreamsSize() const {
147 return DbgStreams.size() * sizeof(uint16_t);
148}
149
Zachary Turnerd218c262016-07-22 15:46:37 +0000150Error DbiStreamBuilder::generateFileInfoSubstream() {
151 uint32_t Size = calculateFileInfoSubstreamSize();
152 uint32_t NameSize = calculateNamesBufferSize();
153 auto Data = Allocator.Allocate<uint8_t>(Size);
154 uint32_t NamesOffset = Size - NameSize;
155
Zachary Turner695ed562017-02-28 00:04:07 +0000156 FileInfoBuffer = MutableBinaryByteStream(MutableArrayRef<uint8_t>(Data, Size),
157 llvm::support::little);
Zachary Turnerd218c262016-07-22 15:46:37 +0000158
Zachary Turner120faca2017-02-27 22:11:43 +0000159 WritableBinaryStreamRef MetadataBuffer =
160 WritableBinaryStreamRef(FileInfoBuffer).keep_front(NamesOffset);
161 BinaryStreamWriter MetadataWriter(MetadataBuffer);
Zachary Turnerd218c262016-07-22 15:46:37 +0000162
Zachary Turnerea4e6072017-03-15 22:18:53 +0000163 uint16_t ModiCount = std::min<uint32_t>(UINT16_MAX, ModiList.size());
Rui Ueyama50701312016-11-16 00:38:33 +0000164 uint16_t FileCount = std::min<uint32_t>(UINT16_MAX, SourceFileNames.size());
Zachary Turner695ed562017-02-28 00:04:07 +0000165 if (auto EC = MetadataWriter.writeInteger(ModiCount)) // NumModules
Zachary Turnerd218c262016-07-22 15:46:37 +0000166 return EC;
Zachary Turner695ed562017-02-28 00:04:07 +0000167 if (auto EC = MetadataWriter.writeInteger(FileCount)) // NumSourceFiles
Zachary Turnerd218c262016-07-22 15:46:37 +0000168 return EC;
169 for (uint16_t I = 0; I < ModiCount; ++I) {
Zachary Turner695ed562017-02-28 00:04:07 +0000170 if (auto EC = MetadataWriter.writeInteger(I)) // Mod Indices
Zachary Turnerd218c262016-07-22 15:46:37 +0000171 return EC;
172 }
Zachary Turnerea4e6072017-03-15 22:18:53 +0000173 for (const auto &MI : ModiList) {
174 FileCount = static_cast<uint16_t>(MI->source_files().size());
Zachary Turner695ed562017-02-28 00:04:07 +0000175 if (auto EC = MetadataWriter.writeInteger(FileCount)) // Mod File Counts
Zachary Turnerd218c262016-07-22 15:46:37 +0000176 return EC;
177 }
178
179 // Before writing the FileNameOffsets array, write the NamesBuffer array.
180 // A side effect of this is that this will actually compute the various
181 // file name offsets, so we can then go back and write the FileNameOffsets
182 // array to the other substream.
Zachary Turner120faca2017-02-27 22:11:43 +0000183 NamesBuffer = WritableBinaryStreamRef(FileInfoBuffer).drop_front(NamesOffset);
184 BinaryStreamWriter NameBufferWriter(NamesBuffer);
Zachary Turnerd218c262016-07-22 15:46:37 +0000185 for (auto &Name : SourceFileNames) {
186 Name.second = NameBufferWriter.getOffset();
Zachary Turner120faca2017-02-27 22:11:43 +0000187 if (auto EC = NameBufferWriter.writeCString(Name.getKey()))
Zachary Turnerd218c262016-07-22 15:46:37 +0000188 return EC;
189 }
190
Zachary Turnerea4e6072017-03-15 22:18:53 +0000191 for (const auto &MI : ModiList) {
192 for (StringRef Name : MI->source_files()) {
Zachary Turnerd218c262016-07-22 15:46:37 +0000193 auto Result = SourceFileNames.find(Name);
194 if (Result == SourceFileNames.end())
195 return make_error<RawError>(raw_error_code::no_entry,
196 "The source file was not found.");
Zachary Turner695ed562017-02-28 00:04:07 +0000197 if (auto EC = MetadataWriter.writeInteger(Result->second))
Zachary Turnerd218c262016-07-22 15:46:37 +0000198 return EC;
199 }
200 }
201
202 if (NameBufferWriter.bytesRemaining() > 0)
203 return make_error<RawError>(raw_error_code::invalid_format,
204 "The names buffer contained unexpected data.");
205
Rui Ueyamafb1e6d22016-11-16 00:59:27 +0000206 if (MetadataWriter.bytesRemaining() > sizeof(uint32_t))
Zachary Turnerd218c262016-07-22 15:46:37 +0000207 return make_error<RawError>(
208 raw_error_code::invalid_format,
209 "The metadata buffer contained unexpected data.");
210
211 return Error::success();
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000212}
213
Zachary Turnerd66889c2016-07-28 19:12:28 +0000214Error DbiStreamBuilder::finalize() {
215 if (Header)
216 return Error::success();
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000217
Zachary Turnerea4e6072017-03-15 22:18:53 +0000218 for (auto &MI : ModiList)
219 MI->finalize();
Zachary Turnerd218c262016-07-22 15:46:37 +0000220
Zachary Turnerd218c262016-07-22 15:46:37 +0000221 if (auto EC = generateFileInfoSubstream())
Zachary Turnere98137c2016-07-28 19:18:02 +0000222 return EC;
Zachary Turnerd218c262016-07-22 15:46:37 +0000223
Zachary Turnerea4e6072017-03-15 22:18:53 +0000224 DbiStreamHeader *H = Allocator.Allocate<DbiStreamHeader>();
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000225 H->VersionHeader = *VerHeader;
226 H->VersionSignature = -1;
227 H->Age = Age;
228 H->BuildNumber = BuildNumber;
229 H->Flags = Flags;
230 H->PdbDllRbld = PdbDllRbld;
231 H->PdbDllVersion = PdbDllVersion;
232 H->MachineType = static_cast<uint16_t>(MachineType);
233
234 H->ECSubstreamSize = 0;
Zachary Turnerd218c262016-07-22 15:46:37 +0000235 H->FileInfoSize = FileInfoBuffer.getLength();
Zachary Turnerea4e6072017-03-15 22:18:53 +0000236 H->ModiSubstreamSize = calculateModiSubstreamSize();
Rui Ueyamaf9904042016-10-11 19:43:12 +0000237 H->OptionalDbgHdrSize = DbgStreams.size() * sizeof(uint16_t);
Rui Ueyamaf7c9c322016-11-11 23:41:13 +0000238 H->SecContrSubstreamSize = calculateSectionContribsStreamSize();
Rui Ueyamaddc79222016-10-31 17:38:56 +0000239 H->SectionMapSize = calculateSectionMapStreamSize();
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000240 H->TypeServerSize = 0;
Zachary Turnerb383d622016-07-22 15:46:46 +0000241 H->SymRecordStreamIndex = kInvalidStreamIndex;
242 H->PublicSymbolStreamIndex = kInvalidStreamIndex;
243 H->MFCTypeServerIndex = kInvalidStreamIndex;
244 H->GlobalSymbolStreamIndex = kInvalidStreamIndex;
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000245
Zachary Turnerd66889c2016-07-28 19:12:28 +0000246 Header = H;
247 return Error::success();
248}
249
Zachary Turner620961d2016-09-14 23:00:02 +0000250Error DbiStreamBuilder::finalizeMsfLayout() {
Zachary Turnerea4e6072017-03-15 22:18:53 +0000251 for (auto &MI : ModiList) {
252 if (auto EC = MI->finalizeMsfLayout())
253 return EC;
254 }
255
Zachary Turner620961d2016-09-14 23:00:02 +0000256 uint32_t Length = calculateSerializedLength();
257 if (auto EC = Msf.setStreamSize(StreamDBI, Length))
258 return EC;
259 return Error::success();
260}
261
Rui Ueyamaddc79222016-10-31 17:38:56 +0000262static uint16_t toSecMapFlags(uint32_t Flags) {
263 uint16_t Ret = 0;
264 if (Flags & COFF::IMAGE_SCN_MEM_READ)
265 Ret |= static_cast<uint16_t>(OMFSegDescFlags::Read);
266 if (Flags & COFF::IMAGE_SCN_MEM_WRITE)
267 Ret |= static_cast<uint16_t>(OMFSegDescFlags::Write);
268 if (Flags & COFF::IMAGE_SCN_MEM_EXECUTE)
269 Ret |= static_cast<uint16_t>(OMFSegDescFlags::Execute);
270 if (Flags & COFF::IMAGE_SCN_MEM_EXECUTE)
271 Ret |= static_cast<uint16_t>(OMFSegDescFlags::Execute);
272 if (!(Flags & COFF::IMAGE_SCN_MEM_16BIT))
273 Ret |= static_cast<uint16_t>(OMFSegDescFlags::AddressIs32Bit);
274
275 // This seems always 1.
276 Ret |= static_cast<uint16_t>(OMFSegDescFlags::IsSelector);
277
278 return Ret;
279}
280
Rui Ueyamaf7c9c322016-11-11 23:41:13 +0000281// A utility function to create Section Contributions
282// for a given input sections.
283std::vector<SectionContrib> DbiStreamBuilder::createSectionContribs(
284 ArrayRef<object::coff_section> SecHdrs) {
285 std::vector<SectionContrib> Ret;
286
287 // Create a SectionContrib for each input section.
288 for (auto &Sec : SecHdrs) {
289 Ret.emplace_back();
290 auto &Entry = Ret.back();
291 memset(&Entry, 0, sizeof(Entry));
292
293 Entry.Off = Sec.PointerToRawData;
294 Entry.Size = Sec.SizeOfRawData;
295 Entry.Characteristics = Sec.Characteristics;
296 }
297 return Ret;
298}
299
Rui Ueyamaddc79222016-10-31 17:38:56 +0000300// A utility function to create a Section Map for a given list of COFF sections.
301//
302// A Section Map seem to be a copy of a COFF section list in other format.
303// I don't know why a PDB file contains both a COFF section header and
304// a Section Map, but it seems it must be present in a PDB.
305std::vector<SecMapEntry> DbiStreamBuilder::createSectionMap(
306 ArrayRef<llvm::object::coff_section> SecHdrs) {
307 std::vector<SecMapEntry> Ret;
308 int Idx = 0;
309
310 auto Add = [&]() -> SecMapEntry & {
311 Ret.emplace_back();
312 auto &Entry = Ret.back();
313 memset(&Entry, 0, sizeof(Entry));
314
315 Entry.Frame = Idx + 1;
316
317 // We don't know the meaning of these fields yet.
318 Entry.SecName = UINT16_MAX;
319 Entry.ClassName = UINT16_MAX;
320
321 return Entry;
322 };
323
324 for (auto &Hdr : SecHdrs) {
325 auto &Entry = Add();
326 Entry.Flags = toSecMapFlags(Hdr.Characteristics);
327 Entry.SecByteLength = Hdr.VirtualSize;
328 ++Idx;
329 }
330
331 // The last entry is for absolute symbols.
332 auto &Entry = Add();
333 Entry.Flags = static_cast<uint16_t>(OMFSegDescFlags::AddressIs32Bit) |
334 static_cast<uint16_t>(OMFSegDescFlags::IsAbsoluteAddress);
335 Entry.SecByteLength = UINT32_MAX;
336
337 return Ret;
338}
339
Zachary Turnera3225b02016-07-29 20:56:36 +0000340Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout,
Zachary Turnerea4e6072017-03-15 22:18:53 +0000341 WritableBinaryStreamRef MsfBuffer) {
Rui Ueyamad1d8c8312016-08-03 23:43:23 +0000342 if (auto EC = finalize())
343 return EC;
344
Zachary Turnerea4e6072017-03-15 22:18:53 +0000345 auto DbiS = WritableMappedBlockStream::createIndexedStream(Layout, MsfBuffer,
346 StreamDBI);
Zachary Turnerd66889c2016-07-28 19:12:28 +0000347
Zachary Turnerea4e6072017-03-15 22:18:53 +0000348 BinaryStreamWriter Writer(*DbiS);
Zachary Turnerd66889c2016-07-28 19:12:28 +0000349 if (auto EC = Writer.writeObject(*Header))
350 return EC;
351
Zachary Turnerea4e6072017-03-15 22:18:53 +0000352 for (auto &M : ModiList) {
353 if (auto EC = M->commit(Writer, Layout, MsfBuffer))
354 return EC;
355 }
Rui Ueyamaddc79222016-10-31 17:38:56 +0000356
Rui Ueyamaf7c9c322016-11-11 23:41:13 +0000357 if (!SectionContribs.empty()) {
Zachary Turner695ed562017-02-28 00:04:07 +0000358 if (auto EC = Writer.writeEnum(DbiSecContribVer60))
Rui Ueyamaf7c9c322016-11-11 23:41:13 +0000359 return EC;
360 if (auto EC = Writer.writeArray(SectionContribs))
361 return EC;
362 }
363
Rui Ueyamaddc79222016-10-31 17:38:56 +0000364 if (!SectionMap.empty()) {
365 ulittle16_t Size = static_cast<ulittle16_t>(SectionMap.size());
366 SecMapHeader SMHeader = {Size, Size};
367 if (auto EC = Writer.writeObject(SMHeader))
368 return EC;
369 if (auto EC = Writer.writeArray(SectionMap))
370 return EC;
371 }
372
Zachary Turnerd66889c2016-07-28 19:12:28 +0000373 if (auto EC = Writer.writeStreamRef(FileInfoBuffer))
374 return EC;
Rui Ueyamaddc79222016-10-31 17:38:56 +0000375
Rui Ueyamaf9904042016-10-11 19:43:12 +0000376 for (auto &Stream : DbgStreams)
Zachary Turner695ed562017-02-28 00:04:07 +0000377 if (auto EC = Writer.writeInteger(Stream.StreamNumber))
Rui Ueyamaf9904042016-10-11 19:43:12 +0000378 return EC;
379
380 for (auto &Stream : DbgStreams) {
381 if (Stream.StreamNumber == kInvalidStreamIndex)
382 continue;
Zachary Turner695ed562017-02-28 00:04:07 +0000383 auto WritableStream = WritableMappedBlockStream::createIndexedStream(
Zachary Turnerea4e6072017-03-15 22:18:53 +0000384 Layout, MsfBuffer, Stream.StreamNumber);
Zachary Turner695ed562017-02-28 00:04:07 +0000385 BinaryStreamWriter DbgStreamWriter(*WritableStream);
Rui Ueyamaf9904042016-10-11 19:43:12 +0000386 if (auto EC = DbgStreamWriter.writeArray(Stream.Data))
387 return EC;
388 }
Zachary Turnerd66889c2016-07-28 19:12:28 +0000389
390 if (Writer.bytesRemaining() > 0)
391 return make_error<RawError>(raw_error_code::invalid_format,
392 "Unexpected bytes found in DBI Stream");
393 return Error::success();
394}