blob: 78cf2c551c2a0daf78649d915981882fccd8689d [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 if (Stream->getLength() !=
Zachary Turnerb383d622016-07-22 15:46:46 +000076 sizeof(DbiStreamHeader) + Header->ModiSubstreamSize +
Zachary Turner53a65ba2016-04-26 18:42:34 +000077 Header->SecContrSubstreamSize + Header->SectionMapSize +
78 Header->FileInfoSize + Header->TypeServerSize +
79 Header->OptionalDbgHdrSize + Header->ECSubstreamSize)
Zachary Turner819e77d2016-05-06 20:51:57 +000080 return make_error<RawError>(raw_error_code::corrupt_file,
81 "DBI Length does not equal sum of substreams.");
Zachary Turner53a65ba2016-04-26 18:42:34 +000082
Zachary Turner84c3a8b2016-04-28 20:05:18 +000083 // Only certain substreams are guaranteed to be aligned. Validate
84 // them here.
Zachary Turner1822af542016-04-27 23:41:42 +000085 if (Header->ModiSubstreamSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +000086 return make_error<RawError>(raw_error_code::corrupt_file,
87 "DBI MODI substream not aligned.");
Zachary Turner84c3a8b2016-04-28 20:05:18 +000088 if (Header->SecContrSubstreamSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +000089 return make_error<RawError>(
90 raw_error_code::corrupt_file,
91 "DBI section contribution substream not aligned.");
Zachary Turner84c3a8b2016-04-28 20:05:18 +000092 if (Header->SectionMapSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +000093 return make_error<RawError>(raw_error_code::corrupt_file,
94 "DBI section map substream not aligned.");
Zachary Turner84c3a8b2016-04-28 20:05:18 +000095 if (Header->FileInfoSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +000096 return make_error<RawError>(raw_error_code::corrupt_file,
97 "DBI file info substream not aligned.");
Zachary Turner84c3a8b2016-04-28 20:05:18 +000098 if (Header->TypeServerSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +000099 return make_error<RawError>(raw_error_code::corrupt_file,
100 "DBI type server substream not aligned.");
Zachary Turner1822af542016-04-27 23:41:42 +0000101
Zachary Turnerdd739682017-06-23 21:11:54 +0000102 if (auto EC = Reader.readSubstream(ModiSubstream, Header->ModiSubstreamSize))
Zachary Turner1de49c92016-05-27 18:47:20 +0000103 return EC;
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000104
Zachary Turnerdd739682017-06-23 21:11:54 +0000105 if (auto EC = Reader.readSubstream(SecContrSubstream,
Zachary Turner8dbe3622016-05-27 01:54:44 +0000106 Header->SecContrSubstreamSize))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000107 return EC;
Zachary Turnerdd739682017-06-23 21:11:54 +0000108 if (auto EC = Reader.readSubstream(SecMapSubstream, Header->SectionMapSize))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000109 return EC;
Zachary Turnerdd739682017-06-23 21:11:54 +0000110 if (auto EC = Reader.readSubstream(FileInfoSubstream, Header->FileInfoSize))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000111 return EC;
Zachary Turner819e77d2016-05-06 20:51:57 +0000112 if (auto EC =
Zachary Turnerdd739682017-06-23 21:11:54 +0000113 Reader.readSubstream(TypeServerMapSubstream, Header->TypeServerSize))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000114 return EC;
Zachary Turnerdd739682017-06-23 21:11:54 +0000115 if (auto EC = Reader.readSubstream(ECSubstream, Header->ECSubstreamSize))
Zachary Turner6ba65de2016-04-29 17:22:58 +0000116 return EC;
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +0000117 if (auto EC = Reader.readArray(
118 DbgStreams, Header->OptionalDbgHdrSize / sizeof(ulittle16_t)))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000119 return EC;
120
Zachary Turnerdd739682017-06-23 21:11:54 +0000121 if (auto EC = Modules.initialize(ModiSubstream.StreamData,
122 FileInfoSubstream.StreamData))
Zachary Turner1eb9a022017-05-04 23:53:29 +0000123 return EC;
124
Zachary Turner93839cb2016-06-02 05:07:49 +0000125 if (auto EC = initializeSectionContributionData())
126 return EC;
Rui Ueyama90db7882016-06-02 18:20:20 +0000127 if (auto EC = initializeSectionHeadersData())
128 return EC;
Zachary Turner93839cb2016-06-02 05:07:49 +0000129 if (auto EC = initializeSectionMapData())
130 return EC;
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000131 if (auto EC = initializeFpoRecords())
132 return EC;
Zachary Turner1822af542016-04-27 23:41:42 +0000133
Zachary Turner6ba65de2016-04-29 17:22:58 +0000134 if (Reader.bytesRemaining() > 0)
Zachary Turner819e77d2016-05-06 20:51:57 +0000135 return make_error<RawError>(raw_error_code::corrupt_file,
136 "Found unexpected bytes in DBI Stream.");
Zachary Turner6ba65de2016-04-29 17:22:58 +0000137
Zachary Turnerdd739682017-06-23 21:11:54 +0000138 if (!ECSubstream.empty()) {
139 BinaryStreamReader ECReader(ECSubstream.StreamData);
Zachary Turnerc504ae32017-05-03 15:58:37 +0000140 if (auto EC = ECNames.reload(ECReader))
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000141 return EC;
142 }
Zachary Turner0eace0b2016-05-02 18:09:14 +0000143
Zachary Turner819e77d2016-05-06 20:51:57 +0000144 return Error::success();
Zachary Turner53a65ba2016-04-26 18:42:34 +0000145}
146
Zachary Turner2f09b502016-04-29 17:28:47 +0000147PdbRaw_DbiVer DbiStream::getDbiVersion() const {
Zachary Turner53a65ba2016-04-26 18:42:34 +0000148 uint32_t Value = Header->VersionHeader;
149 return static_cast<PdbRaw_DbiVer>(Value);
150}
151
Zachary Turner2f09b502016-04-29 17:28:47 +0000152uint32_t DbiStream::getAge() const { return Header->Age; }
Zachary Turner53a65ba2016-04-26 18:42:34 +0000153
Rui Ueyama1f6b6e22016-05-13 21:21:53 +0000154uint16_t DbiStream::getPublicSymbolStreamIndex() const {
155 return Header->PublicSymbolStreamIndex;
156}
157
Zachary Turner96e60f72016-05-24 20:31:48 +0000158uint16_t DbiStream::getGlobalSymbolStreamIndex() const {
159 return Header->GlobalSymbolStreamIndex;
160}
161
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000162uint16_t DbiStream::getFlags() const { return Header->Flags; }
163
Zachary Turner2f09b502016-04-29 17:28:47 +0000164bool DbiStream::isIncrementallyLinked() const {
Zachary Turnerb383d622016-07-22 15:46:46 +0000165 return (Header->Flags & DbiFlags::FlagIncrementalMask) != 0;
Zachary Turner53a65ba2016-04-26 18:42:34 +0000166}
167
Zachary Turner2f09b502016-04-29 17:28:47 +0000168bool DbiStream::hasCTypes() const {
Zachary Turnerb383d622016-07-22 15:46:46 +0000169 return (Header->Flags & DbiFlags::FlagHasCTypesMask) != 0;
Zachary Turner53a65ba2016-04-26 18:42:34 +0000170}
171
Zachary Turner2f09b502016-04-29 17:28:47 +0000172bool DbiStream::isStripped() const {
Zachary Turnerb383d622016-07-22 15:46:46 +0000173 return (Header->Flags & DbiFlags::FlagStrippedMask) != 0;
Zachary Turner53a65ba2016-04-26 18:42:34 +0000174}
175
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000176uint16_t DbiStream::getBuildNumber() const { return Header->BuildNumber; }
177
Zachary Turner2f09b502016-04-29 17:28:47 +0000178uint16_t DbiStream::getBuildMajorVersion() const {
Zachary Turnerb383d622016-07-22 15:46:46 +0000179 return (Header->BuildNumber & DbiBuildNo::BuildMajorMask) >>
180 DbiBuildNo::BuildMajorShift;
Zachary Turner53a65ba2016-04-26 18:42:34 +0000181}
182
Zachary Turner2f09b502016-04-29 17:28:47 +0000183uint16_t DbiStream::getBuildMinorVersion() const {
Zachary Turnerb383d622016-07-22 15:46:46 +0000184 return (Header->BuildNumber & DbiBuildNo::BuildMinorMask) >>
185 DbiBuildNo::BuildMinorShift;
Zachary Turner53a65ba2016-04-26 18:42:34 +0000186}
187
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000188uint16_t DbiStream::getPdbDllRbld() const { return Header->PdbDllRbld; }
189
Zachary Turner2f09b502016-04-29 17:28:47 +0000190uint32_t DbiStream::getPdbDllVersion() const { return Header->PdbDllVersion; }
Zachary Turner53a65ba2016-04-26 18:42:34 +0000191
Rui Ueyama0376b1a2016-05-19 18:05:58 +0000192uint32_t DbiStream::getSymRecordStreamIndex() const {
193 return Header->SymRecordStreamIndex;
194}
Zachary Turner53a65ba2016-04-26 18:42:34 +0000195
Zachary Turner2f09b502016-04-29 17:28:47 +0000196PDB_Machine DbiStream::getMachineType() const {
Zachary Turner53a65ba2016-04-26 18:42:34 +0000197 uint16_t Machine = Header->MachineType;
198 return static_cast<PDB_Machine>(Machine);
199}
Zachary Turner1822af542016-04-27 23:41:42 +0000200
Zachary Turner120faca2017-02-27 22:11:43 +0000201FixedStreamArray<object::coff_section> DbiStream::getSectionHeaders() {
Rui Ueyama90db7882016-06-02 18:20:20 +0000202 return SectionHeaders;
203}
204
Zachary Turner120faca2017-02-27 22:11:43 +0000205FixedStreamArray<object::FpoData> DbiStream::getFpoRecords() {
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000206 return FpoRecords;
207}
208
Zachary Turner1eb9a022017-05-04 23:53:29 +0000209const DbiModuleList &DbiStream::modules() const { return Modules; }
210
Zachary Turner120faca2017-02-27 22:11:43 +0000211FixedStreamArray<SecMapEntry> DbiStream::getSectionMap() const {
Zachary Turner93839cb2016-06-02 05:07:49 +0000212 return SectionMap;
213}
214
Eugene Zelenko570e39a2016-11-23 23:16:32 +0000215void DbiStream::visitSectionContributions(
Zachary Turner93839cb2016-06-02 05:07:49 +0000216 ISectionContribVisitor &Visitor) const {
Zachary Turner1bfb9f42017-06-06 23:54:23 +0000217 if (!SectionContribs.empty()) {
218 assert(SectionContribVersion == DbiSecContribVer60);
Zachary Turner93839cb2016-06-02 05:07:49 +0000219 for (auto &SC : SectionContribs)
220 Visitor.visit(SC);
Zachary Turner1bfb9f42017-06-06 23:54:23 +0000221 } else if (!SectionContribs2.empty()) {
222 assert(SectionContribVersion == DbiSecContribV2);
Zachary Turner93839cb2016-06-02 05:07:49 +0000223 for (auto &SC : SectionContribs2)
224 Visitor.visit(SC);
225 }
226}
227
Zachary Turner6c4bfba2017-07-07 05:04:36 +0000228Expected<StringRef> DbiStream::getECName(uint32_t NI) const {
229 return ECNames.getStringForID(NI);
230}
231
Zachary Turner93839cb2016-06-02 05:07:49 +0000232Error DbiStream::initializeSectionContributionData() {
Zachary Turnerdd739682017-06-23 21:11:54 +0000233 if (SecContrSubstream.empty())
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000234 return Error::success();
235
Zachary Turnerdd739682017-06-23 21:11:54 +0000236 BinaryStreamReader SCReader(SecContrSubstream.StreamData);
Zachary Turner695ed562017-02-28 00:04:07 +0000237 if (auto EC = SCReader.readEnum(SectionContribVersion))
Zachary Turner93839cb2016-06-02 05:07:49 +0000238 return EC;
239
240 if (SectionContribVersion == DbiSecContribVer60)
241 return loadSectionContribs<SectionContrib>(SectionContribs, SCReader);
242 if (SectionContribVersion == DbiSecContribV2)
243 return loadSectionContribs<SectionContrib2>(SectionContribs2, SCReader);
244
245 return make_error<RawError>(raw_error_code::feature_unsupported,
246 "Unsupported DBI Section Contribution version");
247}
248
Rui Ueyama90db7882016-06-02 18:20:20 +0000249// Initializes this->SectionHeaders.
250Error DbiStream::initializeSectionHeadersData() {
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000251 if (DbgStreams.size() == 0)
252 return Error::success();
253
Rui Ueyama90db7882016-06-02 18:20:20 +0000254 uint32_t StreamNum = getDebugStreamIndex(DbgHeaderType::SectionHdr);
Zachary Turnerd2b2bfe2016-06-08 00:25:08 +0000255 if (StreamNum >= Pdb.getNumStreams())
256 return make_error<RawError>(raw_error_code::no_stream);
257
Zachary Turnerd66889c2016-07-28 19:12:28 +0000258 auto SHS = MappedBlockStream::createIndexedStream(
Zachary Turner5b74ff32017-06-03 00:33:35 +0000259 Pdb.getMsfLayout(), Pdb.getMsfBuffer(), StreamNum, Pdb.getAllocator());
Rui Ueyama90db7882016-06-02 18:20:20 +0000260
Zachary Turnerd66889c2016-07-28 19:12:28 +0000261 size_t StreamLen = SHS->getLength();
Rui Ueyama90db7882016-06-02 18:20:20 +0000262 if (StreamLen % sizeof(object::coff_section))
263 return make_error<RawError>(raw_error_code::corrupt_file,
264 "Corrupted section header stream.");
265
266 size_t NumSections = StreamLen / sizeof(object::coff_section);
Zachary Turner120faca2017-02-27 22:11:43 +0000267 BinaryStreamReader Reader(*SHS);
Rui Ueyama90db7882016-06-02 18:20:20 +0000268 if (auto EC = Reader.readArray(SectionHeaders, NumSections))
269 return make_error<RawError>(raw_error_code::corrupt_file,
270 "Could not read a bitmap.");
Zachary Turnera1657a92016-06-08 17:26:39 +0000271
Zachary Turnerd66889c2016-07-28 19:12:28 +0000272 SectionHeaderStream = std::move(SHS);
Rui Ueyama90db7882016-06-02 18:20:20 +0000273 return Error::success();
274}
275
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000276// Initializes this->Fpos.
277Error DbiStream::initializeFpoRecords() {
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000278 if (DbgStreams.size() == 0)
279 return Error::success();
280
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000281 uint32_t StreamNum = getDebugStreamIndex(DbgHeaderType::NewFPO);
Reid Kleckner11582c52016-06-17 20:38:01 +0000282
283 // This means there is no FPO data.
Zachary Turnerb383d622016-07-22 15:46:46 +0000284 if (StreamNum == kInvalidStreamIndex)
Reid Kleckner11582c52016-06-17 20:38:01 +0000285 return Error::success();
286
Zachary Turnerd2b2bfe2016-06-08 00:25:08 +0000287 if (StreamNum >= Pdb.getNumStreams())
288 return make_error<RawError>(raw_error_code::no_stream);
289
Zachary Turnerd66889c2016-07-28 19:12:28 +0000290 auto FS = MappedBlockStream::createIndexedStream(
Zachary Turner5b74ff32017-06-03 00:33:35 +0000291 Pdb.getMsfLayout(), Pdb.getMsfBuffer(), StreamNum, Pdb.getAllocator());
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000292
Zachary Turnerd66889c2016-07-28 19:12:28 +0000293 size_t StreamLen = FS->getLength();
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000294 if (StreamLen % sizeof(object::FpoData))
295 return make_error<RawError>(raw_error_code::corrupt_file,
296 "Corrupted New FPO stream.");
297
298 size_t NumRecords = StreamLen / sizeof(object::FpoData);
Zachary Turner120faca2017-02-27 22:11:43 +0000299 BinaryStreamReader Reader(*FS);
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000300 if (auto EC = Reader.readArray(FpoRecords, NumRecords))
301 return make_error<RawError>(raw_error_code::corrupt_file,
302 "Corrupted New FPO stream.");
Zachary Turnerd66889c2016-07-28 19:12:28 +0000303 FpoStream = std::move(FS);
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000304 return Error::success();
305}
306
Zachary Turnerdd739682017-06-23 21:11:54 +0000307BinarySubstreamRef DbiStream::getSectionContributionData() const {
308 return SecContrSubstream;
309}
310
311BinarySubstreamRef DbiStream::getSecMapSubstreamData() const {
312 return SecMapSubstream;
313}
314
315BinarySubstreamRef DbiStream::getModiSubstreamData() const {
316 return ModiSubstream;
317}
318
319BinarySubstreamRef DbiStream::getFileInfoSubstreamData() const {
320 return FileInfoSubstream;
321}
322
323BinarySubstreamRef DbiStream::getTypeServerMapSubstreamData() const {
324 return TypeServerMapSubstream;
325}
326
327BinarySubstreamRef DbiStream::getECSubstreamData() const { return ECSubstream; }
328
Zachary Turner93839cb2016-06-02 05:07:49 +0000329Error DbiStream::initializeSectionMapData() {
Zachary Turnerdd739682017-06-23 21:11:54 +0000330 if (SecMapSubstream.empty())
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000331 return Error::success();
332
Zachary Turnerdd739682017-06-23 21:11:54 +0000333 BinaryStreamReader SMReader(SecMapSubstream.StreamData);
Zachary Turner93839cb2016-06-02 05:07:49 +0000334 const SecMapHeader *Header;
335 if (auto EC = SMReader.readObject(Header))
336 return EC;
337 if (auto EC = SMReader.readArray(SectionMap, Header->SecCount))
338 return EC;
339 return Error::success();
340}
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000341
Zachary Turnerd3076ab2016-05-25 05:49:48 +0000342uint32_t DbiStream::getDebugStreamIndex(DbgHeaderType Type) const {
Zachary Turnerd218c262016-07-22 15:46:37 +0000343 uint16_t T = static_cast<uint16_t>(Type);
344 if (T >= DbgStreams.size())
Zachary Turnerb383d622016-07-22 15:46:46 +0000345 return kInvalidStreamIndex;
Zachary Turnerd218c262016-07-22 15:46:37 +0000346 return DbgStreams[T];
Zachary Turnerd3076ab2016-05-25 05:49:48 +0000347}