blob: 96a68b6caa6ac07962c44dc6b1a8fda4d921b22b [file] [log] [blame]
Zachary Turner2f09b502016-04-29 17:28:47 +00001//===- DbiStream.cpp - PDB Dbi Stream (Stream 3) Access -------------------===//
Zachary Turner53a65ba2016-04-26 18:42:34 +00002//
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//===----------------------------------------------------------------------===//
Zachary Turner2f09b502016-04-29 17:28:47 +00009#include "llvm/DebugInfo/PDB/Raw/DbiStream.h"
Zachary Turner819e77d2016-05-06 20:51:57 +000010
Zachary Turner8dbe3622016-05-27 01:54:44 +000011#include "llvm/DebugInfo/CodeView/StreamArray.h"
Zachary Turnerd5d37dc2016-05-25 20:37:03 +000012#include "llvm/DebugInfo/CodeView/StreamReader.h"
Zachary Turner93839cb2016-06-02 05:07:49 +000013#include "llvm/DebugInfo/PDB/Raw/ISectionContribVisitor.h"
Zachary Turner2f09b502016-04-29 17:28:47 +000014#include "llvm/DebugInfo/PDB/Raw/InfoStream.h"
Zachary Turner1822af542016-04-27 23:41:42 +000015#include "llvm/DebugInfo/PDB/Raw/ModInfo.h"
Zachary Turner0eace0b2016-05-02 18:09:14 +000016#include "llvm/DebugInfo/PDB/Raw/NameHashTable.h"
Zachary Turner53a65ba2016-04-26 18:42:34 +000017#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
Zachary Turner2f09b502016-04-29 17:28:47 +000018#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
Zachary Turner819e77d2016-05-06 20:51:57 +000019#include "llvm/DebugInfo/PDB/Raw/RawError.h"
Zachary Turner93839cb2016-06-02 05:07:49 +000020#include "llvm/DebugInfo/PDB/Raw/RawTypes.h"
Zachary Turner53a65ba2016-04-26 18:42:34 +000021
22using namespace llvm;
Zachary Turner93839cb2016-06-02 05:07:49 +000023using namespace llvm::codeview;
Zachary Turner2f09b502016-04-29 17:28:47 +000024using namespace llvm::pdb;
Zachary Turner53a65ba2016-04-26 18:42:34 +000025using namespace llvm::support;
26
27namespace {
28// Some of the values are stored in bitfields. Since this needs to be portable
29// across compilers and architectures (big / little endian in particular) we
30// can't use the actual structures below, but must instead do the shifting
31// and masking ourselves. The struct definitions are provided for reference.
32
33// struct DbiFlags {
34// uint16_t IncrementalLinking : 1; // True if linked incrementally
35// uint16_t IsStripped : 1; // True if private symbols were stripped.
36// uint16_t HasCTypes : 1; // True if linked with /debug:ctypes.
37// uint16_t Reserved : 13;
38//};
39const uint16_t FlagIncrementalMask = 0x0001;
40const uint16_t FlagStrippedMask = 0x0002;
41const uint16_t FlagHasCTypesMask = 0x0004;
42
43// struct DbiBuildNo {
44// uint16_t MinorVersion : 8;
45// uint16_t MajorVersion : 7;
46// uint16_t NewVersionFormat : 1;
47//};
48const uint16_t BuildMinorMask = 0x00FF;
49const uint16_t BuildMinorShift = 0;
50
51const uint16_t BuildMajorMask = 0x7F00;
52const uint16_t BuildMajorShift = 8;
Zachary Turner53a65ba2016-04-26 18:42:34 +000053}
54
Zachary Turner2f09b502016-04-29 17:28:47 +000055struct DbiStream::HeaderInfo {
Zachary Turnerff788aa2016-04-26 19:24:10 +000056 little32_t VersionSignature;
Zachary Turner53a65ba2016-04-26 18:42:34 +000057 ulittle32_t VersionHeader;
Rui Ueyama1f6b6e22016-05-13 21:21:53 +000058 ulittle32_t Age; // Should match InfoStream.
Rui Ueyama0376b1a2016-05-19 18:05:58 +000059 ulittle16_t GlobalSymbolStreamIndex; // Global symbol stream #
Rui Ueyama1f6b6e22016-05-13 21:21:53 +000060 ulittle16_t BuildNumber; // See DbiBuildNo structure.
Rui Ueyama0376b1a2016-05-19 18:05:58 +000061 ulittle16_t PublicSymbolStreamIndex; // Public symbols stream #
Rui Ueyama1f6b6e22016-05-13 21:21:53 +000062 ulittle16_t PdbDllVersion; // version of mspdbNNN.dll
Rui Ueyama0376b1a2016-05-19 18:05:58 +000063 ulittle16_t SymRecordStreamIndex; // Symbol records stream #
Rui Ueyama1f6b6e22016-05-13 21:21:53 +000064 ulittle16_t PdbDllRbld; // rbld number of mspdbNNN.dll
65 little32_t ModiSubstreamSize; // Size of module info stream
66 little32_t SecContrSubstreamSize; // Size of sec. contribution stream
67 little32_t SectionMapSize; // Size of sec. map substream
68 little32_t FileInfoSize; // Size of file info substream
Zachary Turner2f09b502016-04-29 17:28:47 +000069 little32_t TypeServerSize; // Size of type server map
70 ulittle32_t MFCTypeServerIndex; // Index of MFC Type Server
71 little32_t OptionalDbgHdrSize; // Size of DbgHeader info
72 little32_t ECSubstreamSize; // Size of EC stream (what is EC?)
73 ulittle16_t Flags; // See DbiFlags enum.
74 ulittle16_t MachineType; // See PDB_MachineType enum.
Zachary Turner53a65ba2016-04-26 18:42:34 +000075
76 ulittle32_t Reserved; // Pad to 64 bytes
77};
78
Zachary Turner93839cb2016-06-02 05:07:49 +000079template <typename ContribType>
80Error loadSectionContribs(FixedStreamArray<ContribType> &Output,
81 StreamReader &Reader) {
82 if (Reader.bytesRemaining() % sizeof(ContribType) != 0)
83 return make_error<RawError>(
84 raw_error_code::corrupt_file,
85 "Invalid number of bytes of section contributions");
86
87 uint32_t Count = Reader.bytesRemaining() / sizeof(ContribType);
88 if (auto EC = Reader.readArray(Output, Count))
89 return EC;
90 return Error::success();
91}
92
Zachary Turner8dbe3622016-05-27 01:54:44 +000093DbiStream::DbiStream(PDBFile &File)
94 : Pdb(File), Stream(StreamDBI, File), Header(nullptr) {
Zachary Turner53a65ba2016-04-26 18:42:34 +000095 static_assert(sizeof(HeaderInfo) == 64, "Invalid HeaderInfo size!");
96}
97
Zachary Turner2f09b502016-04-29 17:28:47 +000098DbiStream::~DbiStream() {}
Zachary Turner53a65ba2016-04-26 18:42:34 +000099
Zachary Turner819e77d2016-05-06 20:51:57 +0000100Error DbiStream::reload() {
Zachary Turner93839cb2016-06-02 05:07:49 +0000101 StreamReader Reader(Stream);
Zachary Turner6ba65de2016-04-29 17:22:58 +0000102
Zachary Turner53a65ba2016-04-26 18:42:34 +0000103 if (Stream.getLength() < sizeof(HeaderInfo))
Zachary Turner819e77d2016-05-06 20:51:57 +0000104 return make_error<RawError>(raw_error_code::corrupt_file,
105 "DBI Stream does not contain a header.");
Zachary Turner8dbe3622016-05-27 01:54:44 +0000106 if (auto EC = Reader.readObject(Header))
Zachary Turner819e77d2016-05-06 20:51:57 +0000107 return make_error<RawError>(raw_error_code::corrupt_file,
108 "DBI Stream does not contain a header.");
Zachary Turner53a65ba2016-04-26 18:42:34 +0000109
110 if (Header->VersionSignature != -1)
Zachary Turner819e77d2016-05-06 20:51:57 +0000111 return make_error<RawError>(raw_error_code::corrupt_file,
112 "Invalid DBI version signature.");
Zachary Turner53a65ba2016-04-26 18:42:34 +0000113
Zachary Turner1822af542016-04-27 23:41:42 +0000114 // Require at least version 7, which should be present in all PDBs
115 // produced in the last decade and allows us to avoid having to
116 // special case all kinds of complicated arcane formats.
117 if (Header->VersionHeader < PdbDbiV70)
Zachary Turner93839cb2016-06-02 05:07:49 +0000118 return make_error<RawError>(raw_error_code::feature_unsupported,
Zachary Turner819e77d2016-05-06 20:51:57 +0000119 "Unsupported DBI version.");
Zachary Turner53a65ba2016-04-26 18:42:34 +0000120
Zachary Turner819e77d2016-05-06 20:51:57 +0000121 auto InfoStream = Pdb.getPDBInfoStream();
122 if (auto EC = InfoStream.takeError())
123 return EC;
124
125 if (Header->Age != InfoStream.get().getAge())
126 return make_error<RawError>(raw_error_code::corrupt_file,
127 "DBI Age does not match PDB Age.");
Zachary Turner53a65ba2016-04-26 18:42:34 +0000128
129 if (Stream.getLength() !=
130 sizeof(HeaderInfo) + Header->ModiSubstreamSize +
131 Header->SecContrSubstreamSize + Header->SectionMapSize +
132 Header->FileInfoSize + Header->TypeServerSize +
133 Header->OptionalDbgHdrSize + Header->ECSubstreamSize)
Zachary Turner819e77d2016-05-06 20:51:57 +0000134 return make_error<RawError>(raw_error_code::corrupt_file,
135 "DBI Length does not equal sum of substreams.");
Zachary Turner53a65ba2016-04-26 18:42:34 +0000136
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000137 // Only certain substreams are guaranteed to be aligned. Validate
138 // them here.
Zachary Turner1822af542016-04-27 23:41:42 +0000139 if (Header->ModiSubstreamSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +0000140 return make_error<RawError>(raw_error_code::corrupt_file,
141 "DBI MODI substream not aligned.");
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000142 if (Header->SecContrSubstreamSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +0000143 return make_error<RawError>(
144 raw_error_code::corrupt_file,
145 "DBI section contribution substream not aligned.");
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000146 if (Header->SectionMapSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +0000147 return make_error<RawError>(raw_error_code::corrupt_file,
148 "DBI section map substream not aligned.");
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000149 if (Header->FileInfoSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +0000150 return make_error<RawError>(raw_error_code::corrupt_file,
151 "DBI file info substream not aligned.");
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000152 if (Header->TypeServerSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +0000153 return make_error<RawError>(raw_error_code::corrupt_file,
154 "DBI type server substream not aligned.");
Zachary Turner1822af542016-04-27 23:41:42 +0000155
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000156 // Since each ModInfo in the stream is a variable length, we have to iterate
157 // them to know how many there actually are.
Zachary Turner93839cb2016-06-02 05:07:49 +0000158 VarStreamArray<ModInfo> ModInfoArray;
Zachary Turner1de49c92016-05-27 18:47:20 +0000159 if (auto EC = Reader.readArray(ModInfoArray, Header->ModiSubstreamSize))
160 return EC;
161 for (auto &Info : ModInfoArray) {
Zachary Turner8dbe3622016-05-27 01:54:44 +0000162 ModuleInfos.emplace_back(Info);
163 }
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000164
Zachary Turner8dbe3622016-05-27 01:54:44 +0000165 if (auto EC = Reader.readStreamRef(SecContrSubstream,
166 Header->SecContrSubstreamSize))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000167 return EC;
Zachary Turner8dbe3622016-05-27 01:54:44 +0000168 if (auto EC = Reader.readStreamRef(SecMapSubstream, Header->SectionMapSize))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000169 return EC;
Zachary Turner8dbe3622016-05-27 01:54:44 +0000170 if (auto EC = Reader.readStreamRef(FileInfoSubstream, Header->FileInfoSize))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000171 return EC;
Zachary Turner819e77d2016-05-06 20:51:57 +0000172 if (auto EC =
Zachary Turner8dbe3622016-05-27 01:54:44 +0000173 Reader.readStreamRef(TypeServerMapSubstream, Header->TypeServerSize))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000174 return EC;
Zachary Turner8dbe3622016-05-27 01:54:44 +0000175 if (auto EC = Reader.readStreamRef(ECSubstream, Header->ECSubstreamSize))
Zachary Turner6ba65de2016-04-29 17:22:58 +0000176 return EC;
Zachary Turner8dbe3622016-05-27 01:54:44 +0000177 if (auto EC = Reader.readArray(DbgStreams, Header->OptionalDbgHdrSize /
178 sizeof(ulittle16_t)))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000179 return EC;
180
Zachary Turner93839cb2016-06-02 05:07:49 +0000181 if (auto EC = initializeSectionContributionData())
182 return EC;
183
184 if (auto EC = initializeSectionMapData())
185 return EC;
186
Zachary Turner819e77d2016-05-06 20:51:57 +0000187 if (auto EC = initializeFileInfo())
Zachary Turner1822af542016-04-27 23:41:42 +0000188 return EC;
189
Zachary Turner6ba65de2016-04-29 17:22:58 +0000190 if (Reader.bytesRemaining() > 0)
Zachary Turner819e77d2016-05-06 20:51:57 +0000191 return make_error<RawError>(raw_error_code::corrupt_file,
192 "Found unexpected bytes in DBI Stream.");
Zachary Turner6ba65de2016-04-29 17:22:58 +0000193
Zachary Turner93839cb2016-06-02 05:07:49 +0000194 StreamReader ECReader(ECSubstream);
Zachary Turner819e77d2016-05-06 20:51:57 +0000195 if (auto EC = ECNames.load(ECReader))
196 return EC;
Zachary Turner0eace0b2016-05-02 18:09:14 +0000197
Zachary Turner819e77d2016-05-06 20:51:57 +0000198 return Error::success();
Zachary Turner53a65ba2016-04-26 18:42:34 +0000199}
200
Zachary Turner2f09b502016-04-29 17:28:47 +0000201PdbRaw_DbiVer DbiStream::getDbiVersion() const {
Zachary Turner53a65ba2016-04-26 18:42:34 +0000202 uint32_t Value = Header->VersionHeader;
203 return static_cast<PdbRaw_DbiVer>(Value);
204}
205
Zachary Turner2f09b502016-04-29 17:28:47 +0000206uint32_t DbiStream::getAge() const { return Header->Age; }
Zachary Turner53a65ba2016-04-26 18:42:34 +0000207
Rui Ueyama1f6b6e22016-05-13 21:21:53 +0000208uint16_t DbiStream::getPublicSymbolStreamIndex() const {
209 return Header->PublicSymbolStreamIndex;
210}
211
Zachary Turner96e60f72016-05-24 20:31:48 +0000212uint16_t DbiStream::getGlobalSymbolStreamIndex() const {
213 return Header->GlobalSymbolStreamIndex;
214}
215
Zachary Turner2f09b502016-04-29 17:28:47 +0000216bool DbiStream::isIncrementallyLinked() const {
Zachary Turner53a65ba2016-04-26 18:42:34 +0000217 return (Header->Flags & FlagIncrementalMask) != 0;
218}
219
Zachary Turner2f09b502016-04-29 17:28:47 +0000220bool DbiStream::hasCTypes() const {
Zachary Turner53a65ba2016-04-26 18:42:34 +0000221 return (Header->Flags & FlagHasCTypesMask) != 0;
222}
223
Zachary Turner2f09b502016-04-29 17:28:47 +0000224bool DbiStream::isStripped() const {
Zachary Turner53a65ba2016-04-26 18:42:34 +0000225 return (Header->Flags & FlagStrippedMask) != 0;
226}
227
Zachary Turner2f09b502016-04-29 17:28:47 +0000228uint16_t DbiStream::getBuildMajorVersion() const {
Zachary Turner53a65ba2016-04-26 18:42:34 +0000229 return (Header->BuildNumber & BuildMajorMask) >> BuildMajorShift;
230}
231
Zachary Turner2f09b502016-04-29 17:28:47 +0000232uint16_t DbiStream::getBuildMinorVersion() const {
Zachary Turner53a65ba2016-04-26 18:42:34 +0000233 return (Header->BuildNumber & BuildMinorMask) >> BuildMinorShift;
234}
235
Zachary Turner2f09b502016-04-29 17:28:47 +0000236uint32_t DbiStream::getPdbDllVersion() const { return Header->PdbDllVersion; }
Zachary Turner53a65ba2016-04-26 18:42:34 +0000237
Rui Ueyama0376b1a2016-05-19 18:05:58 +0000238uint32_t DbiStream::getSymRecordStreamIndex() const {
239 return Header->SymRecordStreamIndex;
240}
Zachary Turner53a65ba2016-04-26 18:42:34 +0000241
Zachary Turner2f09b502016-04-29 17:28:47 +0000242PDB_Machine DbiStream::getMachineType() const {
Zachary Turner53a65ba2016-04-26 18:42:34 +0000243 uint16_t Machine = Header->MachineType;
244 return static_cast<PDB_Machine>(Machine);
245}
Zachary Turner1822af542016-04-27 23:41:42 +0000246
Zachary Turner2f09b502016-04-29 17:28:47 +0000247ArrayRef<ModuleInfoEx> DbiStream::modules() const { return ModuleInfos; }
Zachary Turner93839cb2016-06-02 05:07:49 +0000248codeview::FixedStreamArray<SecMapEntry> DbiStream::getSectionMap() const {
249 return SectionMap;
250}
251
252void llvm::pdb::DbiStream::visitSectionContributions(
253 ISectionContribVisitor &Visitor) const {
254 if (SectionContribVersion == DbiSecContribVer60) {
255 for (auto &SC : SectionContribs)
256 Visitor.visit(SC);
257 } else if (SectionContribVersion == DbiSecContribV2) {
258 for (auto &SC : SectionContribs2)
259 Visitor.visit(SC);
260 }
261}
262
263Error DbiStream::initializeSectionContributionData() {
264 StreamReader SCReader(SecContrSubstream);
265 if (auto EC = SCReader.readEnum(SectionContribVersion))
266 return EC;
267
268 if (SectionContribVersion == DbiSecContribVer60)
269 return loadSectionContribs<SectionContrib>(SectionContribs, SCReader);
270 if (SectionContribVersion == DbiSecContribV2)
271 return loadSectionContribs<SectionContrib2>(SectionContribs2, SCReader);
272
273 return make_error<RawError>(raw_error_code::feature_unsupported,
274 "Unsupported DBI Section Contribution version");
275}
276
277Error DbiStream::initializeSectionMapData() {
278 StreamReader SMReader(SecMapSubstream);
279 const SecMapHeader *Header;
280 if (auto EC = SMReader.readObject(Header))
281 return EC;
282 if (auto EC = SMReader.readArray(SectionMap, Header->SecCount))
283 return EC;
284 return Error::success();
285}
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000286
Zachary Turner819e77d2016-05-06 20:51:57 +0000287Error DbiStream::initializeFileInfo() {
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000288 struct FileInfoSubstreamHeader {
289 ulittle16_t NumModules; // Total # of modules, should match number of
290 // records in the ModuleInfo substream.
291 ulittle16_t NumSourceFiles; // Total # of source files. This value is not
292 // accurate because PDB actually supports more
293 // than 64k source files, so we ignore it and
294 // compute the value from other stream fields.
295 };
296
297 // The layout of the FileInfoSubstream is like this:
298 // struct {
299 // ulittle16_t NumModules;
300 // ulittle16_t NumSourceFiles;
301 // ulittle16_t ModIndices[NumModules];
302 // ulittle16_t ModFileCounts[NumModules];
303 // ulittle32_t FileNameOffsets[NumSourceFiles];
304 // char Names[][NumSourceFiles];
305 // };
306 // with the caveat that `NumSourceFiles` cannot be trusted, so
307 // it is computed by summing `ModFileCounts`.
308 //
Zachary Turner8dbe3622016-05-27 01:54:44 +0000309 const FileInfoSubstreamHeader *FH;
Zachary Turner93839cb2016-06-02 05:07:49 +0000310 StreamReader FISR(FileInfoSubstream);
Zachary Turner8dbe3622016-05-27 01:54:44 +0000311 if (auto EC = FISR.readObject(FH))
312 return EC;
313
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000314 // The number of modules in the stream should be the same as reported by
315 // the FileInfoSubstreamHeader.
Zachary Turner8dbe3622016-05-27 01:54:44 +0000316 if (FH->NumModules != ModuleInfos.size())
Zachary Turner819e77d2016-05-06 20:51:57 +0000317 return make_error<RawError>(raw_error_code::corrupt_file,
318 "FileInfo substream count doesn't match DBI.");
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000319
Zachary Turner93839cb2016-06-02 05:07:49 +0000320 FixedStreamArray<ulittle16_t> ModIndexArray;
321 FixedStreamArray<ulittle16_t> ModFileCountArray;
322 FixedStreamArray<little32_t> FileNameOffsets;
Zachary Turner8dbe3622016-05-27 01:54:44 +0000323
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000324 // First is an array of `NumModules` module indices. This is not used for the
325 // same reason that `NumSourceFiles` is not used. It's an array of uint16's,
326 // but it's possible there are more than 64k source files, which would imply
327 // more than 64k modules (e.g. object files) as well. So we ignore this
328 // field.
Zachary Turner8dbe3622016-05-27 01:54:44 +0000329 if (auto EC = FISR.readArray(ModIndexArray, ModuleInfos.size()))
330 return EC;
331 if (auto EC = FISR.readArray(ModFileCountArray, ModuleInfos.size()))
332 return EC;
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000333
334 // Compute the real number of source files.
335 uint32_t NumSourceFiles = 0;
336 for (auto Count : ModFileCountArray)
337 NumSourceFiles += Count;
338
339 // This is the array that in the reference implementation corresponds to
340 // `ModInfo::FileLayout::FileNameOffs`, which is commented there as being a
341 // pointer. Due to the mentioned problems of pointers causing difficulty
342 // when reading from the file on 64-bit systems, we continue to ignore that
343 // field in `ModInfo`, and instead build a vector of StringRefs and stores
344 // them in `ModuleInfoEx`. The value written to and read from the file is
345 // not used anyway, it is only there as a way to store the offsets for the
346 // purposes of later accessing the names at runtime.
Zachary Turner8dbe3622016-05-27 01:54:44 +0000347 if (auto EC = FISR.readArray(FileNameOffsets, NumSourceFiles))
348 return EC;
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000349
Zachary Turner93839cb2016-06-02 05:07:49 +0000350 StreamRef NamesBufferRef;
Zachary Turner8dbe3622016-05-27 01:54:44 +0000351 if (auto EC = FISR.readStreamRef(NamesBufferRef))
352 return EC;
Zachary Turner93839cb2016-06-02 05:07:49 +0000353 StreamReader Names(NamesBufferRef);
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000354
355 // We go through each ModuleInfo, determine the number N of source files for
356 // that module, and then get the next N offsets from the Offsets array, using
357 // them to get the corresponding N names from the Names buffer and associating
358 // each one with the corresponding module.
359 uint32_t NextFileIndex = 0;
360 for (size_t I = 0; I < ModuleInfos.size(); ++I) {
361 uint32_t NumFiles = ModFileCountArray[I];
362 ModuleInfos[I].SourceFiles.resize(NumFiles);
363 for (size_t J = 0; J < NumFiles; ++J, ++NextFileIndex) {
Zachary Turner8dbe3622016-05-27 01:54:44 +0000364 uint32_t FileOffset = FileNameOffsets[NextFileIndex];
365 Names.setOffset(FileOffset);
366 if (auto EC = Names.readZeroString(ModuleInfos[I].SourceFiles[J]))
367 return EC;
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000368 }
369 }
370
Zachary Turner819e77d2016-05-06 20:51:57 +0000371 return Error::success();
Zachary Turner1822af542016-04-27 23:41:42 +0000372}
Zachary Turnerd3076ab2016-05-25 05:49:48 +0000373
374uint32_t DbiStream::getDebugStreamIndex(DbgHeaderType Type) const {
Zachary Turner8dbe3622016-05-27 01:54:44 +0000375 return DbgStreams[static_cast<uint16_t>(Type)];
Zachary Turnerd3076ab2016-05-25 05:49:48 +0000376}