blob: f7538c580ba452aa41dc8f24b9ca061308e52fd3 [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//===----------------------------------------------------------------------===//
Rui Ueyama90db7882016-06-02 18:20:20 +00009
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000010#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
Eugene Zelenko570e39a2016-11-23 23:16:32 +000011#include "llvm/ADT/StringRef.h"
12#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
Zachary Turner67c56012017-04-27 16:11:19 +000013#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000014#include "llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h"
15#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000016#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
17#include "llvm/DebugInfo/PDB/Native/RawConstants.h"
18#include "llvm/DebugInfo/PDB/Native/RawError.h"
19#include "llvm/DebugInfo/PDB/Native/RawTypes.h"
Eugene Zelenko570e39a2016-11-23 23:16:32 +000020#include "llvm/DebugInfo/PDB/PDBTypes.h"
Rui Ueyama90db7882016-06-02 18:20:20 +000021#include "llvm/Object/COFF.h"
Zachary Turnerd9dc2822017-03-02 20:52:51 +000022#include "llvm/Support/BinaryStreamArray.h"
23#include "llvm/Support/BinaryStreamReader.h"
Eugene Zelenko570e39a2016-11-23 23:16:32 +000024#include "llvm/Support/Error.h"
25#include <algorithm>
26#include <cstddef>
27#include <cstdint>
Zachary Turner53a65ba2016-04-26 18:42:34 +000028
29using namespace llvm;
Zachary Turner93839cb2016-06-02 05:07:49 +000030using namespace llvm::codeview;
Zachary Turnerbac69d32016-07-22 19:56:05 +000031using namespace llvm::msf;
Zachary Turner2f09b502016-04-29 17:28:47 +000032using namespace llvm::pdb;
Zachary Turner53a65ba2016-04-26 18:42:34 +000033using namespace llvm::support;
34
Zachary Turner93839cb2016-06-02 05:07:49 +000035template <typename ContribType>
Benjamin Kramer4d098922016-07-10 11:28:51 +000036static Error loadSectionContribs(FixedStreamArray<ContribType> &Output,
Zachary Turner120faca2017-02-27 22:11:43 +000037 BinaryStreamReader &Reader) {
Zachary Turner93839cb2016-06-02 05:07:49 +000038 if (Reader.bytesRemaining() % sizeof(ContribType) != 0)
39 return make_error<RawError>(
40 raw_error_code::corrupt_file,
41 "Invalid number of bytes of section contributions");
42
43 uint32_t Count = Reader.bytesRemaining() / sizeof(ContribType);
44 if (auto EC = Reader.readArray(Output, Count))
45 return EC;
46 return Error::success();
47}
48
Zachary Turnera1657a92016-06-08 17:26:39 +000049DbiStream::DbiStream(PDBFile &File, std::unique_ptr<MappedBlockStream> Stream)
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000050 : Pdb(File), Stream(std::move(Stream)), Header(nullptr) {}
Zachary Turner53a65ba2016-04-26 18:42:34 +000051
Eugene Zelenko570e39a2016-11-23 23:16:32 +000052DbiStream::~DbiStream() = default;
Zachary Turner53a65ba2016-04-26 18:42:34 +000053
Zachary Turner819e77d2016-05-06 20:51:57 +000054Error DbiStream::reload() {
Zachary Turner120faca2017-02-27 22:11:43 +000055 BinaryStreamReader Reader(*Stream);
Zachary Turner6ba65de2016-04-29 17:22:58 +000056
Zachary Turnerb383d622016-07-22 15:46:46 +000057 if (Stream->getLength() < sizeof(DbiStreamHeader))
Zachary Turner819e77d2016-05-06 20:51:57 +000058 return make_error<RawError>(raw_error_code::corrupt_file,
59 "DBI Stream does not contain a header.");
Zachary Turner8dbe3622016-05-27 01:54:44 +000060 if (auto EC = Reader.readObject(Header))
Zachary Turner819e77d2016-05-06 20:51:57 +000061 return make_error<RawError>(raw_error_code::corrupt_file,
62 "DBI Stream does not contain a header.");
Zachary Turner53a65ba2016-04-26 18:42:34 +000063
64 if (Header->VersionSignature != -1)
Zachary Turner819e77d2016-05-06 20:51:57 +000065 return make_error<RawError>(raw_error_code::corrupt_file,
66 "Invalid DBI version signature.");
Zachary Turner53a65ba2016-04-26 18:42:34 +000067
Zachary Turner1822af542016-04-27 23:41:42 +000068 // Require at least version 7, which should be present in all PDBs
69 // produced in the last decade and allows us to avoid having to
70 // special case all kinds of complicated arcane formats.
71 if (Header->VersionHeader < PdbDbiV70)
Zachary Turner93839cb2016-06-02 05:07:49 +000072 return make_error<RawError>(raw_error_code::feature_unsupported,
Zachary Turner819e77d2016-05-06 20:51:57 +000073 "Unsupported DBI version.");
Zachary Turner53a65ba2016-04-26 18:42:34 +000074
Zachary Turnera1657a92016-06-08 17:26:39 +000075 auto IS = Pdb.getPDBInfoStream();
76 if (!IS)
77 return IS.takeError();
Zachary Turner819e77d2016-05-06 20:51:57 +000078
Zachary Turnera1657a92016-06-08 17:26:39 +000079 if (Header->Age != IS->getAge())
Zachary Turner819e77d2016-05-06 20:51:57 +000080 return make_error<RawError>(raw_error_code::corrupt_file,
81 "DBI Age does not match PDB Age.");
Zachary Turner53a65ba2016-04-26 18:42:34 +000082
Zachary Turnera1657a92016-06-08 17:26:39 +000083 if (Stream->getLength() !=
Zachary Turnerb383d622016-07-22 15:46:46 +000084 sizeof(DbiStreamHeader) + Header->ModiSubstreamSize +
Zachary Turner53a65ba2016-04-26 18:42:34 +000085 Header->SecContrSubstreamSize + Header->SectionMapSize +
86 Header->FileInfoSize + Header->TypeServerSize +
87 Header->OptionalDbgHdrSize + Header->ECSubstreamSize)
Zachary Turner819e77d2016-05-06 20:51:57 +000088 return make_error<RawError>(raw_error_code::corrupt_file,
89 "DBI Length does not equal sum of substreams.");
Zachary Turner53a65ba2016-04-26 18:42:34 +000090
Zachary Turner84c3a8b2016-04-28 20:05:18 +000091 // Only certain substreams are guaranteed to be aligned. Validate
92 // them here.
Zachary Turner1822af542016-04-27 23:41:42 +000093 if (Header->ModiSubstreamSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +000094 return make_error<RawError>(raw_error_code::corrupt_file,
95 "DBI MODI substream not aligned.");
Zachary Turner84c3a8b2016-04-28 20:05:18 +000096 if (Header->SecContrSubstreamSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +000097 return make_error<RawError>(
98 raw_error_code::corrupt_file,
99 "DBI section contribution substream not aligned.");
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000100 if (Header->SectionMapSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +0000101 return make_error<RawError>(raw_error_code::corrupt_file,
102 "DBI section map substream not aligned.");
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000103 if (Header->FileInfoSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +0000104 return make_error<RawError>(raw_error_code::corrupt_file,
105 "DBI file info substream not aligned.");
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000106 if (Header->TypeServerSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +0000107 return make_error<RawError>(raw_error_code::corrupt_file,
108 "DBI type server substream not aligned.");
Zachary Turner1822af542016-04-27 23:41:42 +0000109
Zachary Turner1eb9a022017-05-04 23:53:29 +0000110 BinaryStreamRef ModInfoSubstream;
111 BinaryStreamRef FileInfoSubstream;
Zachary Turnerd218c262016-07-22 15:46:37 +0000112 if (auto EC =
113 Reader.readStreamRef(ModInfoSubstream, Header->ModiSubstreamSize))
Zachary Turner1de49c92016-05-27 18:47:20 +0000114 return EC;
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000115
Zachary Turner8dbe3622016-05-27 01:54:44 +0000116 if (auto EC = Reader.readStreamRef(SecContrSubstream,
117 Header->SecContrSubstreamSize))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000118 return EC;
Zachary Turner8dbe3622016-05-27 01:54:44 +0000119 if (auto EC = Reader.readStreamRef(SecMapSubstream, Header->SectionMapSize))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000120 return EC;
Zachary Turner8dbe3622016-05-27 01:54:44 +0000121 if (auto EC = Reader.readStreamRef(FileInfoSubstream, Header->FileInfoSize))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000122 return EC;
Zachary Turner819e77d2016-05-06 20:51:57 +0000123 if (auto EC =
Zachary Turner8dbe3622016-05-27 01:54:44 +0000124 Reader.readStreamRef(TypeServerMapSubstream, Header->TypeServerSize))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000125 return EC;
Zachary Turner8dbe3622016-05-27 01:54:44 +0000126 if (auto EC = Reader.readStreamRef(ECSubstream, Header->ECSubstreamSize))
Zachary Turner6ba65de2016-04-29 17:22:58 +0000127 return EC;
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +0000128 if (auto EC = Reader.readArray(
129 DbgStreams, Header->OptionalDbgHdrSize / sizeof(ulittle16_t)))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000130 return EC;
131
Zachary Turner1eb9a022017-05-04 23:53:29 +0000132 if (auto EC = Modules.initialize(ModInfoSubstream, FileInfoSubstream))
133 return EC;
134
Zachary Turner93839cb2016-06-02 05:07:49 +0000135 if (auto EC = initializeSectionContributionData())
136 return EC;
Rui Ueyama90db7882016-06-02 18:20:20 +0000137 if (auto EC = initializeSectionHeadersData())
138 return EC;
Zachary Turner93839cb2016-06-02 05:07:49 +0000139 if (auto EC = initializeSectionMapData())
140 return EC;
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000141 if (auto EC = initializeFpoRecords())
142 return EC;
Zachary Turner1822af542016-04-27 23:41:42 +0000143
Zachary Turner6ba65de2016-04-29 17:22:58 +0000144 if (Reader.bytesRemaining() > 0)
Zachary Turner819e77d2016-05-06 20:51:57 +0000145 return make_error<RawError>(raw_error_code::corrupt_file,
146 "Found unexpected bytes in DBI Stream.");
Zachary Turner6ba65de2016-04-29 17:22:58 +0000147
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000148 if (ECSubstream.getLength() > 0) {
Zachary Turner120faca2017-02-27 22:11:43 +0000149 BinaryStreamReader ECReader(ECSubstream);
Zachary Turnerc504ae32017-05-03 15:58:37 +0000150 if (auto EC = ECNames.reload(ECReader))
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000151 return EC;
152 }
Zachary Turner0eace0b2016-05-02 18:09:14 +0000153
Zachary Turner819e77d2016-05-06 20:51:57 +0000154 return Error::success();
Zachary Turner53a65ba2016-04-26 18:42:34 +0000155}
156
Zachary Turner2f09b502016-04-29 17:28:47 +0000157PdbRaw_DbiVer DbiStream::getDbiVersion() const {
Zachary Turner53a65ba2016-04-26 18:42:34 +0000158 uint32_t Value = Header->VersionHeader;
159 return static_cast<PdbRaw_DbiVer>(Value);
160}
161
Zachary Turner2f09b502016-04-29 17:28:47 +0000162uint32_t DbiStream::getAge() const { return Header->Age; }
Zachary Turner53a65ba2016-04-26 18:42:34 +0000163
Rui Ueyama1f6b6e22016-05-13 21:21:53 +0000164uint16_t DbiStream::getPublicSymbolStreamIndex() const {
165 return Header->PublicSymbolStreamIndex;
166}
167
Zachary Turner96e60f72016-05-24 20:31:48 +0000168uint16_t DbiStream::getGlobalSymbolStreamIndex() const {
169 return Header->GlobalSymbolStreamIndex;
170}
171
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000172uint16_t DbiStream::getFlags() const { return Header->Flags; }
173
Zachary Turner2f09b502016-04-29 17:28:47 +0000174bool DbiStream::isIncrementallyLinked() const {
Zachary Turnerb383d622016-07-22 15:46:46 +0000175 return (Header->Flags & DbiFlags::FlagIncrementalMask) != 0;
Zachary Turner53a65ba2016-04-26 18:42:34 +0000176}
177
Zachary Turner2f09b502016-04-29 17:28:47 +0000178bool DbiStream::hasCTypes() const {
Zachary Turnerb383d622016-07-22 15:46:46 +0000179 return (Header->Flags & DbiFlags::FlagHasCTypesMask) != 0;
Zachary Turner53a65ba2016-04-26 18:42:34 +0000180}
181
Zachary Turner2f09b502016-04-29 17:28:47 +0000182bool DbiStream::isStripped() const {
Zachary Turnerb383d622016-07-22 15:46:46 +0000183 return (Header->Flags & DbiFlags::FlagStrippedMask) != 0;
Zachary Turner53a65ba2016-04-26 18:42:34 +0000184}
185
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000186uint16_t DbiStream::getBuildNumber() const { return Header->BuildNumber; }
187
Zachary Turner2f09b502016-04-29 17:28:47 +0000188uint16_t DbiStream::getBuildMajorVersion() const {
Zachary Turnerb383d622016-07-22 15:46:46 +0000189 return (Header->BuildNumber & DbiBuildNo::BuildMajorMask) >>
190 DbiBuildNo::BuildMajorShift;
Zachary Turner53a65ba2016-04-26 18:42:34 +0000191}
192
Zachary Turner2f09b502016-04-29 17:28:47 +0000193uint16_t DbiStream::getBuildMinorVersion() const {
Zachary Turnerb383d622016-07-22 15:46:46 +0000194 return (Header->BuildNumber & DbiBuildNo::BuildMinorMask) >>
195 DbiBuildNo::BuildMinorShift;
Zachary Turner53a65ba2016-04-26 18:42:34 +0000196}
197
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000198uint16_t DbiStream::getPdbDllRbld() const { return Header->PdbDllRbld; }
199
Zachary Turner2f09b502016-04-29 17:28:47 +0000200uint32_t DbiStream::getPdbDllVersion() const { return Header->PdbDllVersion; }
Zachary Turner53a65ba2016-04-26 18:42:34 +0000201
Rui Ueyama0376b1a2016-05-19 18:05:58 +0000202uint32_t DbiStream::getSymRecordStreamIndex() const {
203 return Header->SymRecordStreamIndex;
204}
Zachary Turner53a65ba2016-04-26 18:42:34 +0000205
Zachary Turner2f09b502016-04-29 17:28:47 +0000206PDB_Machine DbiStream::getMachineType() const {
Zachary Turner53a65ba2016-04-26 18:42:34 +0000207 uint16_t Machine = Header->MachineType;
208 return static_cast<PDB_Machine>(Machine);
209}
Zachary Turner1822af542016-04-27 23:41:42 +0000210
Zachary Turner120faca2017-02-27 22:11:43 +0000211FixedStreamArray<object::coff_section> DbiStream::getSectionHeaders() {
Rui Ueyama90db7882016-06-02 18:20:20 +0000212 return SectionHeaders;
213}
214
Zachary Turner120faca2017-02-27 22:11:43 +0000215FixedStreamArray<object::FpoData> DbiStream::getFpoRecords() {
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000216 return FpoRecords;
217}
218
Zachary Turner1eb9a022017-05-04 23:53:29 +0000219const DbiModuleList &DbiStream::modules() const { return Modules; }
220
Zachary Turner120faca2017-02-27 22:11:43 +0000221FixedStreamArray<SecMapEntry> DbiStream::getSectionMap() const {
Zachary Turner93839cb2016-06-02 05:07:49 +0000222 return SectionMap;
223}
224
Eugene Zelenko570e39a2016-11-23 23:16:32 +0000225void DbiStream::visitSectionContributions(
Zachary Turner93839cb2016-06-02 05:07:49 +0000226 ISectionContribVisitor &Visitor) const {
227 if (SectionContribVersion == DbiSecContribVer60) {
228 for (auto &SC : SectionContribs)
229 Visitor.visit(SC);
230 } else if (SectionContribVersion == DbiSecContribV2) {
231 for (auto &SC : SectionContribs2)
232 Visitor.visit(SC);
233 }
234}
235
236Error DbiStream::initializeSectionContributionData() {
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000237 if (SecContrSubstream.getLength() == 0)
238 return Error::success();
239
Zachary Turner120faca2017-02-27 22:11:43 +0000240 BinaryStreamReader SCReader(SecContrSubstream);
Zachary Turner695ed562017-02-28 00:04:07 +0000241 if (auto EC = SCReader.readEnum(SectionContribVersion))
Zachary Turner93839cb2016-06-02 05:07:49 +0000242 return EC;
243
244 if (SectionContribVersion == DbiSecContribVer60)
245 return loadSectionContribs<SectionContrib>(SectionContribs, SCReader);
246 if (SectionContribVersion == DbiSecContribV2)
247 return loadSectionContribs<SectionContrib2>(SectionContribs2, SCReader);
248
249 return make_error<RawError>(raw_error_code::feature_unsupported,
250 "Unsupported DBI Section Contribution version");
251}
252
Rui Ueyama90db7882016-06-02 18:20:20 +0000253// Initializes this->SectionHeaders.
254Error DbiStream::initializeSectionHeadersData() {
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000255 if (DbgStreams.size() == 0)
256 return Error::success();
257
Rui Ueyama90db7882016-06-02 18:20:20 +0000258 uint32_t StreamNum = getDebugStreamIndex(DbgHeaderType::SectionHdr);
Zachary Turnerd2b2bfe2016-06-08 00:25:08 +0000259 if (StreamNum >= Pdb.getNumStreams())
260 return make_error<RawError>(raw_error_code::no_stream);
261
Zachary Turnerd66889c2016-07-28 19:12:28 +0000262 auto SHS = MappedBlockStream::createIndexedStream(
263 Pdb.getMsfLayout(), Pdb.getMsfBuffer(), StreamNum);
Rui Ueyama90db7882016-06-02 18:20:20 +0000264
Zachary Turnerd66889c2016-07-28 19:12:28 +0000265 size_t StreamLen = SHS->getLength();
Rui Ueyama90db7882016-06-02 18:20:20 +0000266 if (StreamLen % sizeof(object::coff_section))
267 return make_error<RawError>(raw_error_code::corrupt_file,
268 "Corrupted section header stream.");
269
270 size_t NumSections = StreamLen / sizeof(object::coff_section);
Zachary Turner120faca2017-02-27 22:11:43 +0000271 BinaryStreamReader Reader(*SHS);
Rui Ueyama90db7882016-06-02 18:20:20 +0000272 if (auto EC = Reader.readArray(SectionHeaders, NumSections))
273 return make_error<RawError>(raw_error_code::corrupt_file,
274 "Could not read a bitmap.");
Zachary Turnera1657a92016-06-08 17:26:39 +0000275
Zachary Turnerd66889c2016-07-28 19:12:28 +0000276 SectionHeaderStream = std::move(SHS);
Rui Ueyama90db7882016-06-02 18:20:20 +0000277 return Error::success();
278}
279
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000280// Initializes this->Fpos.
281Error DbiStream::initializeFpoRecords() {
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000282 if (DbgStreams.size() == 0)
283 return Error::success();
284
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000285 uint32_t StreamNum = getDebugStreamIndex(DbgHeaderType::NewFPO);
Reid Kleckner11582c52016-06-17 20:38:01 +0000286
287 // This means there is no FPO data.
Zachary Turnerb383d622016-07-22 15:46:46 +0000288 if (StreamNum == kInvalidStreamIndex)
Reid Kleckner11582c52016-06-17 20:38:01 +0000289 return Error::success();
290
Zachary Turnerd2b2bfe2016-06-08 00:25:08 +0000291 if (StreamNum >= Pdb.getNumStreams())
292 return make_error<RawError>(raw_error_code::no_stream);
293
Zachary Turnerd66889c2016-07-28 19:12:28 +0000294 auto FS = MappedBlockStream::createIndexedStream(
295 Pdb.getMsfLayout(), Pdb.getMsfBuffer(), StreamNum);
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000296
Zachary Turnerd66889c2016-07-28 19:12:28 +0000297 size_t StreamLen = FS->getLength();
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000298 if (StreamLen % sizeof(object::FpoData))
299 return make_error<RawError>(raw_error_code::corrupt_file,
300 "Corrupted New FPO stream.");
301
302 size_t NumRecords = StreamLen / sizeof(object::FpoData);
Zachary Turner120faca2017-02-27 22:11:43 +0000303 BinaryStreamReader Reader(*FS);
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000304 if (auto EC = Reader.readArray(FpoRecords, NumRecords))
305 return make_error<RawError>(raw_error_code::corrupt_file,
306 "Corrupted New FPO stream.");
Zachary Turnerd66889c2016-07-28 19:12:28 +0000307 FpoStream = std::move(FS);
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000308 return Error::success();
309}
310
Zachary Turner93839cb2016-06-02 05:07:49 +0000311Error DbiStream::initializeSectionMapData() {
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000312 if (SecMapSubstream.getLength() == 0)
313 return Error::success();
314
Zachary Turner120faca2017-02-27 22:11:43 +0000315 BinaryStreamReader SMReader(SecMapSubstream);
Zachary Turner93839cb2016-06-02 05:07:49 +0000316 const SecMapHeader *Header;
317 if (auto EC = SMReader.readObject(Header))
318 return EC;
319 if (auto EC = SMReader.readArray(SectionMap, Header->SecCount))
320 return EC;
321 return Error::success();
322}
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000323
Zachary Turnerd3076ab2016-05-25 05:49:48 +0000324uint32_t DbiStream::getDebugStreamIndex(DbgHeaderType Type) const {
Zachary Turnerd218c262016-07-22 15:46:37 +0000325 uint16_t T = static_cast<uint16_t>(Type);
326 if (T >= DbgStreams.size())
Zachary Turnerb383d622016-07-22 15:46:46 +0000327 return kInvalidStreamIndex;
Zachary Turnerd218c262016-07-22 15:46:37 +0000328 return DbgStreams[T];
Zachary Turnerd3076ab2016-05-25 05:49:48 +0000329}