blob: 04e6664c68dbb8c8ce21baa843e09ff9182e7bed [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"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000015#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
16#include "llvm/DebugInfo/PDB/Native/RawConstants.h"
17#include "llvm/DebugInfo/PDB/Native/RawError.h"
18#include "llvm/DebugInfo/PDB/Native/RawTypes.h"
Eugene Zelenko570e39a2016-11-23 23:16:32 +000019#include "llvm/DebugInfo/PDB/PDBTypes.h"
Rui Ueyama90db7882016-06-02 18:20:20 +000020#include "llvm/Object/COFF.h"
Zachary Turnerd9dc2822017-03-02 20:52:51 +000021#include "llvm/Support/BinaryStreamArray.h"
22#include "llvm/Support/BinaryStreamReader.h"
Eugene Zelenko570e39a2016-11-23 23:16:32 +000023#include "llvm/Support/Error.h"
24#include <algorithm>
25#include <cstddef>
26#include <cstdint>
Zachary Turner53a65ba2016-04-26 18:42:34 +000027
28using namespace llvm;
Zachary Turner93839cb2016-06-02 05:07:49 +000029using namespace llvm::codeview;
Zachary Turnerbac69d32016-07-22 19:56:05 +000030using namespace llvm::msf;
Zachary Turner2f09b502016-04-29 17:28:47 +000031using namespace llvm::pdb;
Zachary Turner53a65ba2016-04-26 18:42:34 +000032using namespace llvm::support;
33
Zachary Turner93839cb2016-06-02 05:07:49 +000034template <typename ContribType>
Benjamin Kramer4d098922016-07-10 11:28:51 +000035static Error loadSectionContribs(FixedStreamArray<ContribType> &Output,
Zachary Turner120faca2017-02-27 22:11:43 +000036 BinaryStreamReader &Reader) {
Zachary Turner93839cb2016-06-02 05:07:49 +000037 if (Reader.bytesRemaining() % sizeof(ContribType) != 0)
38 return make_error<RawError>(
39 raw_error_code::corrupt_file,
40 "Invalid number of bytes of section contributions");
41
42 uint32_t Count = Reader.bytesRemaining() / sizeof(ContribType);
43 if (auto EC = Reader.readArray(Output, Count))
44 return EC;
45 return Error::success();
46}
47
Zachary Turnera1657a92016-06-08 17:26:39 +000048DbiStream::DbiStream(PDBFile &File, std::unique_ptr<MappedBlockStream> Stream)
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000049 : Pdb(File), Stream(std::move(Stream)), Header(nullptr) {}
Zachary Turner53a65ba2016-04-26 18:42:34 +000050
Eugene Zelenko570e39a2016-11-23 23:16:32 +000051DbiStream::~DbiStream() = default;
Zachary Turner53a65ba2016-04-26 18:42:34 +000052
Zachary Turner819e77d2016-05-06 20:51:57 +000053Error DbiStream::reload() {
Zachary Turner120faca2017-02-27 22:11:43 +000054 BinaryStreamReader Reader(*Stream);
Zachary Turner6ba65de2016-04-29 17:22:58 +000055
Zachary Turnerb383d622016-07-22 15:46:46 +000056 if (Stream->getLength() < sizeof(DbiStreamHeader))
Zachary Turner819e77d2016-05-06 20:51:57 +000057 return make_error<RawError>(raw_error_code::corrupt_file,
58 "DBI Stream does not contain a header.");
Zachary Turner8dbe3622016-05-27 01:54:44 +000059 if (auto EC = Reader.readObject(Header))
Zachary Turner819e77d2016-05-06 20:51:57 +000060 return make_error<RawError>(raw_error_code::corrupt_file,
61 "DBI Stream does not contain a header.");
Zachary Turner53a65ba2016-04-26 18:42:34 +000062
63 if (Header->VersionSignature != -1)
Zachary Turner819e77d2016-05-06 20:51:57 +000064 return make_error<RawError>(raw_error_code::corrupt_file,
65 "Invalid DBI version signature.");
Zachary Turner53a65ba2016-04-26 18:42:34 +000066
Zachary Turner1822af542016-04-27 23:41:42 +000067 // Require at least version 7, which should be present in all PDBs
68 // produced in the last decade and allows us to avoid having to
69 // special case all kinds of complicated arcane formats.
70 if (Header->VersionHeader < PdbDbiV70)
Zachary Turner93839cb2016-06-02 05:07:49 +000071 return make_error<RawError>(raw_error_code::feature_unsupported,
Zachary Turner819e77d2016-05-06 20:51:57 +000072 "Unsupported DBI version.");
Zachary Turner53a65ba2016-04-26 18:42:34 +000073
Zachary Turnera1657a92016-06-08 17:26:39 +000074 if (Stream->getLength() !=
Zachary Turnerb383d622016-07-22 15:46:46 +000075 sizeof(DbiStreamHeader) + Header->ModiSubstreamSize +
Zachary Turner53a65ba2016-04-26 18:42:34 +000076 Header->SecContrSubstreamSize + Header->SectionMapSize +
77 Header->FileInfoSize + Header->TypeServerSize +
78 Header->OptionalDbgHdrSize + Header->ECSubstreamSize)
Zachary Turner819e77d2016-05-06 20:51:57 +000079 return make_error<RawError>(raw_error_code::corrupt_file,
80 "DBI Length does not equal sum of substreams.");
Zachary Turner53a65ba2016-04-26 18:42:34 +000081
Zachary Turner84c3a8b2016-04-28 20:05:18 +000082 // Only certain substreams are guaranteed to be aligned. Validate
83 // them here.
Zachary Turner1822af542016-04-27 23:41:42 +000084 if (Header->ModiSubstreamSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +000085 return make_error<RawError>(raw_error_code::corrupt_file,
86 "DBI MODI substream not aligned.");
Zachary Turner84c3a8b2016-04-28 20:05:18 +000087 if (Header->SecContrSubstreamSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +000088 return make_error<RawError>(
89 raw_error_code::corrupt_file,
90 "DBI section contribution substream not aligned.");
Zachary Turner84c3a8b2016-04-28 20:05:18 +000091 if (Header->SectionMapSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +000092 return make_error<RawError>(raw_error_code::corrupt_file,
93 "DBI section map substream not aligned.");
Zachary Turner84c3a8b2016-04-28 20:05:18 +000094 if (Header->FileInfoSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +000095 return make_error<RawError>(raw_error_code::corrupt_file,
96 "DBI file info substream not aligned.");
Zachary Turner84c3a8b2016-04-28 20:05:18 +000097 if (Header->TypeServerSize % sizeof(uint32_t) != 0)
Zachary Turner819e77d2016-05-06 20:51:57 +000098 return make_error<RawError>(raw_error_code::corrupt_file,
99 "DBI type server substream not aligned.");
Zachary Turner1822af542016-04-27 23:41:42 +0000100
Zachary Turnerdd739682017-06-23 21:11:54 +0000101 if (auto EC = Reader.readSubstream(ModiSubstream, Header->ModiSubstreamSize))
Zachary Turner1de49c92016-05-27 18:47:20 +0000102 return EC;
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000103
Zachary Turnerdd739682017-06-23 21:11:54 +0000104 if (auto EC = Reader.readSubstream(SecContrSubstream,
Zachary Turner8dbe3622016-05-27 01:54:44 +0000105 Header->SecContrSubstreamSize))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000106 return EC;
Zachary Turnerdd739682017-06-23 21:11:54 +0000107 if (auto EC = Reader.readSubstream(SecMapSubstream, Header->SectionMapSize))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000108 return EC;
Zachary Turnerdd739682017-06-23 21:11:54 +0000109 if (auto EC = Reader.readSubstream(FileInfoSubstream, Header->FileInfoSize))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000110 return EC;
Zachary Turner819e77d2016-05-06 20:51:57 +0000111 if (auto EC =
Zachary Turnerdd739682017-06-23 21:11:54 +0000112 Reader.readSubstream(TypeServerMapSubstream, Header->TypeServerSize))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000113 return EC;
Zachary Turnerdd739682017-06-23 21:11:54 +0000114 if (auto EC = Reader.readSubstream(ECSubstream, Header->ECSubstreamSize))
Zachary Turner6ba65de2016-04-29 17:22:58 +0000115 return EC;
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +0000116 if (auto EC = Reader.readArray(
117 DbgStreams, Header->OptionalDbgHdrSize / sizeof(ulittle16_t)))
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000118 return EC;
119
Zachary Turnerdd739682017-06-23 21:11:54 +0000120 if (auto EC = Modules.initialize(ModiSubstream.StreamData,
121 FileInfoSubstream.StreamData))
Zachary Turner1eb9a022017-05-04 23:53:29 +0000122 return EC;
123
Zachary Turner93839cb2016-06-02 05:07:49 +0000124 if (auto EC = initializeSectionContributionData())
125 return EC;
Rui Ueyama90db7882016-06-02 18:20:20 +0000126 if (auto EC = initializeSectionHeadersData())
127 return EC;
Zachary Turner93839cb2016-06-02 05:07:49 +0000128 if (auto EC = initializeSectionMapData())
129 return EC;
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000130 if (auto EC = initializeFpoRecords())
131 return EC;
Zachary Turner1822af542016-04-27 23:41:42 +0000132
Zachary Turner6ba65de2016-04-29 17:22:58 +0000133 if (Reader.bytesRemaining() > 0)
Zachary Turner819e77d2016-05-06 20:51:57 +0000134 return make_error<RawError>(raw_error_code::corrupt_file,
135 "Found unexpected bytes in DBI Stream.");
Zachary Turner6ba65de2016-04-29 17:22:58 +0000136
Zachary Turnerdd739682017-06-23 21:11:54 +0000137 if (!ECSubstream.empty()) {
138 BinaryStreamReader ECReader(ECSubstream.StreamData);
Zachary Turnerc504ae32017-05-03 15:58:37 +0000139 if (auto EC = ECNames.reload(ECReader))
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000140 return EC;
141 }
Zachary Turner0eace0b2016-05-02 18:09:14 +0000142
Zachary Turner819e77d2016-05-06 20:51:57 +0000143 return Error::success();
Zachary Turner53a65ba2016-04-26 18:42:34 +0000144}
145
Zachary Turner2f09b502016-04-29 17:28:47 +0000146PdbRaw_DbiVer DbiStream::getDbiVersion() const {
Zachary Turner53a65ba2016-04-26 18:42:34 +0000147 uint32_t Value = Header->VersionHeader;
148 return static_cast<PdbRaw_DbiVer>(Value);
149}
150
Zachary Turner2f09b502016-04-29 17:28:47 +0000151uint32_t DbiStream::getAge() const { return Header->Age; }
Zachary Turner53a65ba2016-04-26 18:42:34 +0000152
Rui Ueyama1f6b6e22016-05-13 21:21:53 +0000153uint16_t DbiStream::getPublicSymbolStreamIndex() const {
154 return Header->PublicSymbolStreamIndex;
155}
156
Zachary Turner96e60f72016-05-24 20:31:48 +0000157uint16_t DbiStream::getGlobalSymbolStreamIndex() const {
158 return Header->GlobalSymbolStreamIndex;
159}
160
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000161uint16_t DbiStream::getFlags() const { return Header->Flags; }
162
Zachary Turner2f09b502016-04-29 17:28:47 +0000163bool DbiStream::isIncrementallyLinked() const {
Zachary Turnerb383d622016-07-22 15:46:46 +0000164 return (Header->Flags & DbiFlags::FlagIncrementalMask) != 0;
Zachary Turner53a65ba2016-04-26 18:42:34 +0000165}
166
Zachary Turner2f09b502016-04-29 17:28:47 +0000167bool DbiStream::hasCTypes() const {
Zachary Turnerb383d622016-07-22 15:46:46 +0000168 return (Header->Flags & DbiFlags::FlagHasCTypesMask) != 0;
Zachary Turner53a65ba2016-04-26 18:42:34 +0000169}
170
Zachary Turner2f09b502016-04-29 17:28:47 +0000171bool DbiStream::isStripped() const {
Zachary Turnerb383d622016-07-22 15:46:46 +0000172 return (Header->Flags & DbiFlags::FlagStrippedMask) != 0;
Zachary Turner53a65ba2016-04-26 18:42:34 +0000173}
174
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000175uint16_t DbiStream::getBuildNumber() const { return Header->BuildNumber; }
176
Zachary Turner2f09b502016-04-29 17:28:47 +0000177uint16_t DbiStream::getBuildMajorVersion() const {
Zachary Turnerb383d622016-07-22 15:46:46 +0000178 return (Header->BuildNumber & DbiBuildNo::BuildMajorMask) >>
179 DbiBuildNo::BuildMajorShift;
Zachary Turner53a65ba2016-04-26 18:42:34 +0000180}
181
Zachary Turner2f09b502016-04-29 17:28:47 +0000182uint16_t DbiStream::getBuildMinorVersion() const {
Zachary Turnerb383d622016-07-22 15:46:46 +0000183 return (Header->BuildNumber & DbiBuildNo::BuildMinorMask) >>
184 DbiBuildNo::BuildMinorShift;
Zachary Turner53a65ba2016-04-26 18:42:34 +0000185}
186
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000187uint16_t DbiStream::getPdbDllRbld() const { return Header->PdbDllRbld; }
188
Zachary Turner2f09b502016-04-29 17:28:47 +0000189uint32_t DbiStream::getPdbDllVersion() const { return Header->PdbDllVersion; }
Zachary Turner53a65ba2016-04-26 18:42:34 +0000190
Rui Ueyama0376b1a2016-05-19 18:05:58 +0000191uint32_t DbiStream::getSymRecordStreamIndex() const {
192 return Header->SymRecordStreamIndex;
193}
Zachary Turner53a65ba2016-04-26 18:42:34 +0000194
Zachary Turner2f09b502016-04-29 17:28:47 +0000195PDB_Machine DbiStream::getMachineType() const {
Zachary Turner53a65ba2016-04-26 18:42:34 +0000196 uint16_t Machine = Header->MachineType;
197 return static_cast<PDB_Machine>(Machine);
198}
Zachary Turner1822af542016-04-27 23:41:42 +0000199
Zachary Turner120faca2017-02-27 22:11:43 +0000200FixedStreamArray<object::coff_section> DbiStream::getSectionHeaders() {
Rui Ueyama90db7882016-06-02 18:20:20 +0000201 return SectionHeaders;
202}
203
Zachary Turner120faca2017-02-27 22:11:43 +0000204FixedStreamArray<object::FpoData> DbiStream::getFpoRecords() {
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000205 return FpoRecords;
206}
207
Zachary Turner1eb9a022017-05-04 23:53:29 +0000208const DbiModuleList &DbiStream::modules() const { return Modules; }
209
Zachary Turner120faca2017-02-27 22:11:43 +0000210FixedStreamArray<SecMapEntry> DbiStream::getSectionMap() const {
Zachary Turner93839cb2016-06-02 05:07:49 +0000211 return SectionMap;
212}
213
Eugene Zelenko570e39a2016-11-23 23:16:32 +0000214void DbiStream::visitSectionContributions(
Zachary Turner93839cb2016-06-02 05:07:49 +0000215 ISectionContribVisitor &Visitor) const {
Zachary Turner1bfb9f42017-06-06 23:54:23 +0000216 if (!SectionContribs.empty()) {
217 assert(SectionContribVersion == DbiSecContribVer60);
Zachary Turner93839cb2016-06-02 05:07:49 +0000218 for (auto &SC : SectionContribs)
219 Visitor.visit(SC);
Zachary Turner1bfb9f42017-06-06 23:54:23 +0000220 } else if (!SectionContribs2.empty()) {
221 assert(SectionContribVersion == DbiSecContribV2);
Zachary Turner93839cb2016-06-02 05:07:49 +0000222 for (auto &SC : SectionContribs2)
223 Visitor.visit(SC);
224 }
225}
226
Zachary Turner6c4bfba2017-07-07 05:04:36 +0000227Expected<StringRef> DbiStream::getECName(uint32_t NI) const {
228 return ECNames.getStringForID(NI);
229}
230
Zachary Turner93839cb2016-06-02 05:07:49 +0000231Error DbiStream::initializeSectionContributionData() {
Zachary Turnerdd739682017-06-23 21:11:54 +0000232 if (SecContrSubstream.empty())
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000233 return Error::success();
234
Zachary Turnerdd739682017-06-23 21:11:54 +0000235 BinaryStreamReader SCReader(SecContrSubstream.StreamData);
Zachary Turner695ed562017-02-28 00:04:07 +0000236 if (auto EC = SCReader.readEnum(SectionContribVersion))
Zachary Turner93839cb2016-06-02 05:07:49 +0000237 return EC;
238
239 if (SectionContribVersion == DbiSecContribVer60)
240 return loadSectionContribs<SectionContrib>(SectionContribs, SCReader);
241 if (SectionContribVersion == DbiSecContribV2)
242 return loadSectionContribs<SectionContrib2>(SectionContribs2, SCReader);
243
244 return make_error<RawError>(raw_error_code::feature_unsupported,
245 "Unsupported DBI Section Contribution version");
246}
247
Rui Ueyama90db7882016-06-02 18:20:20 +0000248// Initializes this->SectionHeaders.
249Error DbiStream::initializeSectionHeadersData() {
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000250 if (DbgStreams.size() == 0)
251 return Error::success();
252
Rui Ueyama90db7882016-06-02 18:20:20 +0000253 uint32_t StreamNum = getDebugStreamIndex(DbgHeaderType::SectionHdr);
Zachary Turnerc1e93e52017-07-07 18:45:56 +0000254 if (StreamNum == kInvalidStreamIndex)
255 return Error::success();
256
Zachary Turnerd2b2bfe2016-06-08 00:25:08 +0000257 if (StreamNum >= Pdb.getNumStreams())
258 return make_error<RawError>(raw_error_code::no_stream);
259
Zachary Turnerd66889c2016-07-28 19:12:28 +0000260 auto SHS = MappedBlockStream::createIndexedStream(
Zachary Turner5b74ff32017-06-03 00:33:35 +0000261 Pdb.getMsfLayout(), Pdb.getMsfBuffer(), StreamNum, Pdb.getAllocator());
Rui Ueyama90db7882016-06-02 18:20:20 +0000262
Zachary Turnerd66889c2016-07-28 19:12:28 +0000263 size_t StreamLen = SHS->getLength();
Rui Ueyama90db7882016-06-02 18:20:20 +0000264 if (StreamLen % sizeof(object::coff_section))
265 return make_error<RawError>(raw_error_code::corrupt_file,
266 "Corrupted section header stream.");
267
268 size_t NumSections = StreamLen / sizeof(object::coff_section);
Zachary Turner120faca2017-02-27 22:11:43 +0000269 BinaryStreamReader Reader(*SHS);
Rui Ueyama90db7882016-06-02 18:20:20 +0000270 if (auto EC = Reader.readArray(SectionHeaders, NumSections))
271 return make_error<RawError>(raw_error_code::corrupt_file,
272 "Could not read a bitmap.");
Zachary Turnera1657a92016-06-08 17:26:39 +0000273
Zachary Turnerd66889c2016-07-28 19:12:28 +0000274 SectionHeaderStream = std::move(SHS);
Rui Ueyama90db7882016-06-02 18:20:20 +0000275 return Error::success();
276}
277
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000278// Initializes this->Fpos.
279Error DbiStream::initializeFpoRecords() {
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000280 if (DbgStreams.size() == 0)
281 return Error::success();
282
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000283 uint32_t StreamNum = getDebugStreamIndex(DbgHeaderType::NewFPO);
Reid Kleckner11582c52016-06-17 20:38:01 +0000284
285 // This means there is no FPO data.
Zachary Turnerb383d622016-07-22 15:46:46 +0000286 if (StreamNum == kInvalidStreamIndex)
Reid Kleckner11582c52016-06-17 20:38:01 +0000287 return Error::success();
288
Zachary Turnerd2b2bfe2016-06-08 00:25:08 +0000289 if (StreamNum >= Pdb.getNumStreams())
290 return make_error<RawError>(raw_error_code::no_stream);
291
Zachary Turnerd66889c2016-07-28 19:12:28 +0000292 auto FS = MappedBlockStream::createIndexedStream(
Zachary Turner5b74ff32017-06-03 00:33:35 +0000293 Pdb.getMsfLayout(), Pdb.getMsfBuffer(), StreamNum, Pdb.getAllocator());
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000294
Zachary Turnerd66889c2016-07-28 19:12:28 +0000295 size_t StreamLen = FS->getLength();
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000296 if (StreamLen % sizeof(object::FpoData))
297 return make_error<RawError>(raw_error_code::corrupt_file,
298 "Corrupted New FPO stream.");
299
300 size_t NumRecords = StreamLen / sizeof(object::FpoData);
Zachary Turner120faca2017-02-27 22:11:43 +0000301 BinaryStreamReader Reader(*FS);
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000302 if (auto EC = Reader.readArray(FpoRecords, NumRecords))
303 return make_error<RawError>(raw_error_code::corrupt_file,
304 "Corrupted New FPO stream.");
Zachary Turnerd66889c2016-07-28 19:12:28 +0000305 FpoStream = std::move(FS);
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000306 return Error::success();
307}
308
Zachary Turnerdd739682017-06-23 21:11:54 +0000309BinarySubstreamRef DbiStream::getSectionContributionData() const {
310 return SecContrSubstream;
311}
312
313BinarySubstreamRef DbiStream::getSecMapSubstreamData() const {
314 return SecMapSubstream;
315}
316
317BinarySubstreamRef DbiStream::getModiSubstreamData() const {
318 return ModiSubstream;
319}
320
321BinarySubstreamRef DbiStream::getFileInfoSubstreamData() const {
322 return FileInfoSubstream;
323}
324
325BinarySubstreamRef DbiStream::getTypeServerMapSubstreamData() const {
326 return TypeServerMapSubstream;
327}
328
329BinarySubstreamRef DbiStream::getECSubstreamData() const { return ECSubstream; }
330
Zachary Turner93839cb2016-06-02 05:07:49 +0000331Error DbiStream::initializeSectionMapData() {
Zachary Turnerdd739682017-06-23 21:11:54 +0000332 if (SecMapSubstream.empty())
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000333 return Error::success();
334
Zachary Turnerdd739682017-06-23 21:11:54 +0000335 BinaryStreamReader SMReader(SecMapSubstream.StreamData);
Zachary Turner93839cb2016-06-02 05:07:49 +0000336 const SecMapHeader *Header;
337 if (auto EC = SMReader.readObject(Header))
338 return EC;
339 if (auto EC = SMReader.readArray(SectionMap, Header->SecCount))
340 return EC;
341 return Error::success();
342}
Zachary Turner84c3a8b2016-04-28 20:05:18 +0000343
Zachary Turnerd3076ab2016-05-25 05:49:48 +0000344uint32_t DbiStream::getDebugStreamIndex(DbgHeaderType Type) const {
Zachary Turnerd218c262016-07-22 15:46:37 +0000345 uint16_t T = static_cast<uint16_t>(Type);
346 if (T >= DbgStreams.size())
Zachary Turnerb383d622016-07-22 15:46:46 +0000347 return kInvalidStreamIndex;
Zachary Turnerd218c262016-07-22 15:46:37 +0000348 return DbgStreams[T];
Zachary Turnerd3076ab2016-05-25 05:49:48 +0000349}