annotate lib/DebugInfo/PDB/Native/PDBFile.cpp @ 121:803732b1fca8

LLVM 5.0
author kono
date Fri, 27 Oct 2017 17:07:41 +0900
parents
children c2174574ed3a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 //===- PDBFile.cpp - Low level interface to a PDB file ----------*- C++ -*-===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
4 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11 #include "llvm/ADT/ArrayRef.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 #include "llvm/ADT/STLExtras.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13 #include "llvm/DebugInfo/MSF/MSFCommon.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15 #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16 #include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18 #include "llvm/DebugInfo/PDB/Native/PDBStringTable.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19 #include "llvm/DebugInfo/PDB/Native/PublicsStream.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20 #include "llvm/DebugInfo/PDB/Native/RawError.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21 #include "llvm/DebugInfo/PDB/Native/SymbolStream.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22 #include "llvm/DebugInfo/PDB/Native/TpiStream.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23 #include "llvm/Support/BinaryStream.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 #include "llvm/Support/BinaryStreamArray.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 #include "llvm/Support/BinaryStreamReader.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26 #include "llvm/Support/Endian.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 #include "llvm/Support/Error.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 #include "llvm/Support/Path.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29 #include <algorithm>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 #include <cassert>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 #include <cstdint>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 using namespace llvm;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 using namespace llvm::codeview;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 using namespace llvm::msf;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 using namespace llvm::pdb;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38 namespace {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39 typedef FixedStreamArray<support::ulittle32_t> ulittle_array;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40 } // end anonymous namespace
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 PDBFile::PDBFile(StringRef Path, std::unique_ptr<BinaryStream> PdbFileBuffer,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43 BumpPtrAllocator &Allocator)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44 : FilePath(Path), Allocator(Allocator), Buffer(std::move(PdbFileBuffer)) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46 PDBFile::~PDBFile() = default;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 StringRef PDBFile::getFilePath() const { return FilePath; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50 StringRef PDBFile::getFileDirectory() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 return sys::path::parent_path(FilePath);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54 uint32_t PDBFile::getBlockSize() const { return ContainerLayout.SB->BlockSize; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56 uint32_t PDBFile::getFreeBlockMapBlock() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57 return ContainerLayout.SB->FreeBlockMapBlock;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
58 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
59
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
60 uint32_t PDBFile::getBlockCount() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
61 return ContainerLayout.SB->NumBlocks;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
63
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
64 uint32_t PDBFile::getNumDirectoryBytes() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
65 return ContainerLayout.SB->NumDirectoryBytes;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
66 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
67
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
68 uint32_t PDBFile::getBlockMapIndex() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
69 return ContainerLayout.SB->BlockMapAddr;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
70 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
71
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
72 uint32_t PDBFile::getUnknown1() const { return ContainerLayout.SB->Unknown1; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
73
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
74 uint32_t PDBFile::getNumDirectoryBlocks() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
75 return msf::bytesToBlocks(ContainerLayout.SB->NumDirectoryBytes,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
76 ContainerLayout.SB->BlockSize);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
77 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
78
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
79 uint64_t PDBFile::getBlockMapOffset() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
80 return (uint64_t)ContainerLayout.SB->BlockMapAddr *
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
81 ContainerLayout.SB->BlockSize;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
82 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
83
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
84 uint32_t PDBFile::getNumStreams() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
85 return ContainerLayout.StreamSizes.size();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
86 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
87
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
88 uint32_t PDBFile::getMaxStreamSize() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
89 return *std::max_element(ContainerLayout.StreamSizes.begin(),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
90 ContainerLayout.StreamSizes.end());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
91 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
92
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
93 uint32_t PDBFile::getStreamByteSize(uint32_t StreamIndex) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
94 return ContainerLayout.StreamSizes[StreamIndex];
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
95 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
96
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
97 ArrayRef<support::ulittle32_t>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
98 PDBFile::getStreamBlockList(uint32_t StreamIndex) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
99 return ContainerLayout.StreamMap[StreamIndex];
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
100 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
101
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
102 uint32_t PDBFile::getFileSize() const { return Buffer->getLength(); }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
103
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
104 Expected<ArrayRef<uint8_t>> PDBFile::getBlockData(uint32_t BlockIndex,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
105 uint32_t NumBytes) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
106 uint64_t StreamBlockOffset = msf::blockToOffset(BlockIndex, getBlockSize());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
107
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
108 ArrayRef<uint8_t> Result;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
109 if (auto EC = Buffer->readBytes(StreamBlockOffset, NumBytes, Result))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
110 return std::move(EC);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
111 return Result;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
112 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
113
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
114 Error PDBFile::setBlockData(uint32_t BlockIndex, uint32_t Offset,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
115 ArrayRef<uint8_t> Data) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
116 return make_error<RawError>(raw_error_code::not_writable,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
117 "PDBFile is immutable");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
118 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
119
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
120 Error PDBFile::parseFileHeaders() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
121 BinaryStreamReader Reader(*Buffer);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
122
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
123 // Initialize SB.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
124 const msf::SuperBlock *SB = nullptr;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
125 if (auto EC = Reader.readObject(SB)) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
126 consumeError(std::move(EC));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
127 return make_error<RawError>(raw_error_code::corrupt_file,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
128 "Does not contain superblock");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
129 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
130
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
131 if (auto EC = msf::validateSuperBlock(*SB))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
132 return EC;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
133
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
134 if (Buffer->getLength() % SB->BlockSize != 0)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
135 return make_error<RawError>(raw_error_code::corrupt_file,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
136 "File size is not a multiple of block size");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
137 ContainerLayout.SB = SB;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
138
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
139 // Initialize Free Page Map.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
140 ContainerLayout.FreePageMap.resize(SB->NumBlocks);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
141 // The Fpm exists either at block 1 or block 2 of the MSF. However, this
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
142 // allows for a maximum of getBlockSize() * 8 blocks bits in the Fpm, and
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
143 // thusly an equal number of total blocks in the file. For a block size
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
144 // of 4KiB (very common), this would yield 32KiB total blocks in file, for a
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
145 // maximum file size of 32KiB * 4KiB = 128MiB. Obviously this won't do, so
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
146 // the Fpm is split across the file at `getBlockSize()` intervals. As a
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
147 // result, every block whose index is of the form |{1,2} + getBlockSize() * k|
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
148 // for any non-negative integer k is an Fpm block. In theory, we only really
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
149 // need to reserve blocks of the form |{1,2} + getBlockSize() * 8 * k|, but
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
150 // current versions of the MSF format already expect the Fpm to be arranged
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
151 // at getBlockSize() intervals, so we have to be compatible.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
152 // See the function fpmPn() for more information:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
153 // https://github.com/Microsoft/microsoft-pdb/blob/master/PDB/msf/msf.cpp#L489
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
154 auto FpmStream =
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
155 MappedBlockStream::createFpmStream(ContainerLayout, *Buffer, Allocator);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
156 BinaryStreamReader FpmReader(*FpmStream);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
157 ArrayRef<uint8_t> FpmBytes;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
158 if (auto EC = FpmReader.readBytes(FpmBytes, FpmReader.bytesRemaining()))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
159 return EC;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
160 uint32_t BlocksRemaining = getBlockCount();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
161 uint32_t BI = 0;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
162 for (auto Byte : FpmBytes) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
163 uint32_t BlocksThisByte = std::min(BlocksRemaining, 8U);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
164 for (uint32_t I = 0; I < BlocksThisByte; ++I) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
165 if (Byte & (1 << I))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
166 ContainerLayout.FreePageMap[BI] = true;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
167 --BlocksRemaining;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
168 ++BI;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
169 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
170 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
171
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
172 Reader.setOffset(getBlockMapOffset());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
173 if (auto EC = Reader.readArray(ContainerLayout.DirectoryBlocks,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
174 getNumDirectoryBlocks()))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
175 return EC;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
176
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
177 return Error::success();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
178 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
179
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
180 Error PDBFile::parseStreamData() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
181 assert(ContainerLayout.SB);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
182 if (DirectoryStream)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
183 return Error::success();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
184
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
185 uint32_t NumStreams = 0;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
186
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
187 // Normally you can't use a MappedBlockStream without having fully parsed the
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
188 // PDB file, because it accesses the directory and various other things, which
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
189 // is exactly what we are attempting to parse. By specifying a custom
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
190 // subclass of IPDBStreamData which only accesses the fields that have already
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
191 // been parsed, we can avoid this and reuse MappedBlockStream.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
192 auto DS = MappedBlockStream::createDirectoryStream(ContainerLayout, *Buffer,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
193 Allocator);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
194 BinaryStreamReader Reader(*DS);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
195 if (auto EC = Reader.readInteger(NumStreams))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
196 return EC;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
197
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
198 if (auto EC = Reader.readArray(ContainerLayout.StreamSizes, NumStreams))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
199 return EC;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
200 for (uint32_t I = 0; I < NumStreams; ++I) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
201 uint32_t StreamSize = getStreamByteSize(I);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
202 // FIXME: What does StreamSize ~0U mean?
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
203 uint64_t NumExpectedStreamBlocks =
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
204 StreamSize == UINT32_MAX
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
205 ? 0
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
206 : msf::bytesToBlocks(StreamSize, ContainerLayout.SB->BlockSize);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
207
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
208 // For convenience, we store the block array contiguously. This is because
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
209 // if someone calls setStreamMap(), it is more convenient to be able to call
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
210 // it with an ArrayRef instead of setting up a StreamRef. Since the
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
211 // DirectoryStream is cached in the class and thus lives for the life of the
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
212 // class, we can be guaranteed that readArray() will return a stable
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
213 // reference, even if it has to allocate from its internal pool.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
214 ArrayRef<support::ulittle32_t> Blocks;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
215 if (auto EC = Reader.readArray(Blocks, NumExpectedStreamBlocks))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
216 return EC;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
217 for (uint32_t Block : Blocks) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
218 uint64_t BlockEndOffset =
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
219 (uint64_t)(Block + 1) * ContainerLayout.SB->BlockSize;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
220 if (BlockEndOffset > getFileSize())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
221 return make_error<RawError>(raw_error_code::corrupt_file,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
222 "Stream block map is corrupt.");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
223 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
224 ContainerLayout.StreamMap.push_back(Blocks);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
225 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
226
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
227 // We should have read exactly SB->NumDirectoryBytes bytes.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
228 assert(Reader.bytesRemaining() == 0);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
229 DirectoryStream = std::move(DS);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
230 return Error::success();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
231 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
232
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
233 ArrayRef<support::ulittle32_t> PDBFile::getDirectoryBlockArray() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
234 return ContainerLayout.DirectoryBlocks;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
235 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
236
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
237 std::unique_ptr<MappedBlockStream> PDBFile::createIndexedStream(uint16_t SN) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
238 if (SN == kInvalidStreamIndex)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
239 return nullptr;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
240 return MappedBlockStream::createIndexedStream(ContainerLayout, *Buffer, SN,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
241 Allocator);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
242 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
243
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
244 MSFStreamLayout PDBFile::getStreamLayout(uint32_t StreamIdx) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
245 MSFStreamLayout Result;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
246 auto Blocks = getStreamBlockList(StreamIdx);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
247 Result.Blocks.assign(Blocks.begin(), Blocks.end());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
248 Result.Length = getStreamByteSize(StreamIdx);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
249 return Result;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
250 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
251
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
252 msf::MSFStreamLayout PDBFile::getFpmStreamLayout() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
253 return msf::getFpmStreamLayout(ContainerLayout);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
254 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
255
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
256 Expected<GlobalsStream &> PDBFile::getPDBGlobalsStream() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
257 if (!Globals) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
258 auto DbiS = getPDBDbiStream();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
259 if (!DbiS)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
260 return DbiS.takeError();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
261
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
262 auto GlobalS = safelyCreateIndexedStream(
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
263 ContainerLayout, *Buffer, DbiS->getGlobalSymbolStreamIndex());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
264 if (!GlobalS)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
265 return GlobalS.takeError();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
266 auto TempGlobals = llvm::make_unique<GlobalsStream>(std::move(*GlobalS));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
267 if (auto EC = TempGlobals->reload())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
268 return std::move(EC);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
269 Globals = std::move(TempGlobals);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
270 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
271 return *Globals;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
272 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
273
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
274 Expected<InfoStream &> PDBFile::getPDBInfoStream() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
275 if (!Info) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
276 auto InfoS = safelyCreateIndexedStream(ContainerLayout, *Buffer, StreamPDB);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
277 if (!InfoS)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
278 return InfoS.takeError();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
279 auto TempInfo = llvm::make_unique<InfoStream>(std::move(*InfoS));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
280 if (auto EC = TempInfo->reload())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
281 return std::move(EC);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
282 Info = std::move(TempInfo);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
283 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
284 return *Info;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
285 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
286
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
287 Expected<DbiStream &> PDBFile::getPDBDbiStream() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
288 if (!Dbi) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
289 auto DbiS = safelyCreateIndexedStream(ContainerLayout, *Buffer, StreamDBI);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
290 if (!DbiS)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
291 return DbiS.takeError();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
292 auto TempDbi = llvm::make_unique<DbiStream>(*this, std::move(*DbiS));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
293 if (auto EC = TempDbi->reload())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
294 return std::move(EC);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
295 Dbi = std::move(TempDbi);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
296 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
297 return *Dbi;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
298 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
299
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
300 Expected<TpiStream &> PDBFile::getPDBTpiStream() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
301 if (!Tpi) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
302 auto TpiS = safelyCreateIndexedStream(ContainerLayout, *Buffer, StreamTPI);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
303 if (!TpiS)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
304 return TpiS.takeError();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
305 auto TempTpi = llvm::make_unique<TpiStream>(*this, std::move(*TpiS));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
306 if (auto EC = TempTpi->reload())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
307 return std::move(EC);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
308 Tpi = std::move(TempTpi);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
309 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
310 return *Tpi;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
311 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
312
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
313 Expected<TpiStream &> PDBFile::getPDBIpiStream() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
314 if (!Ipi) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
315 if (!hasPDBIpiStream())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
316 return make_error<RawError>(raw_error_code::no_stream);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
317
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
318 auto IpiS = safelyCreateIndexedStream(ContainerLayout, *Buffer, StreamIPI);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
319 if (!IpiS)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
320 return IpiS.takeError();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
321 auto TempIpi = llvm::make_unique<TpiStream>(*this, std::move(*IpiS));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
322 if (auto EC = TempIpi->reload())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
323 return std::move(EC);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
324 Ipi = std::move(TempIpi);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
325 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
326 return *Ipi;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
327 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
328
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
329 Expected<PublicsStream &> PDBFile::getPDBPublicsStream() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
330 if (!Publics) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
331 auto DbiS = getPDBDbiStream();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
332 if (!DbiS)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
333 return DbiS.takeError();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
334
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
335 auto PublicS = safelyCreateIndexedStream(
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
336 ContainerLayout, *Buffer, DbiS->getPublicSymbolStreamIndex());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
337 if (!PublicS)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
338 return PublicS.takeError();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
339 auto TempPublics = llvm::make_unique<PublicsStream>(std::move(*PublicS));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
340 if (auto EC = TempPublics->reload())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
341 return std::move(EC);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
342 Publics = std::move(TempPublics);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
343 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
344 return *Publics;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
345 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
346
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
347 Expected<SymbolStream &> PDBFile::getPDBSymbolStream() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
348 if (!Symbols) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
349 auto DbiS = getPDBDbiStream();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
350 if (!DbiS)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
351 return DbiS.takeError();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
352
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
353 uint32_t SymbolStreamNum = DbiS->getSymRecordStreamIndex();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
354 auto SymbolS =
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
355 safelyCreateIndexedStream(ContainerLayout, *Buffer, SymbolStreamNum);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
356 if (!SymbolS)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
357 return SymbolS.takeError();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
358
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
359 auto TempSymbols = llvm::make_unique<SymbolStream>(std::move(*SymbolS));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
360 if (auto EC = TempSymbols->reload())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
361 return std::move(EC);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
362 Symbols = std::move(TempSymbols);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
363 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
364 return *Symbols;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
365 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
366
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
367 Expected<PDBStringTable &> PDBFile::getStringTable() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
368 if (!Strings) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
369 auto IS = getPDBInfoStream();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
370 if (!IS)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
371 return IS.takeError();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
372
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
373 uint32_t NameStreamIndex = IS->getNamedStreamIndex("/names");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
374
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
375 auto NS =
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
376 safelyCreateIndexedStream(ContainerLayout, *Buffer, NameStreamIndex);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
377 if (!NS)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
378 return NS.takeError();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
379
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
380 auto N = llvm::make_unique<PDBStringTable>();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
381 BinaryStreamReader Reader(**NS);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
382 if (auto EC = N->reload(Reader))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
383 return std::move(EC);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
384 assert(Reader.bytesRemaining() == 0);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
385 StringTableStream = std::move(*NS);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
386 Strings = std::move(N);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
387 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
388 return *Strings;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
389 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
390
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
391 uint32_t PDBFile::getPointerSize() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
392 auto DbiS = getPDBDbiStream();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
393 if (!DbiS)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
394 return 0;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
395 PDB_Machine Machine = DbiS->getMachineType();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
396 if (Machine == PDB_Machine::Amd64)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
397 return 8;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
398 return 4;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
399 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
400
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
401 bool PDBFile::hasPDBDbiStream() const { return StreamDBI < getNumStreams(); }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
402
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
403 bool PDBFile::hasPDBGlobalsStream() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
404 auto DbiS = getPDBDbiStream();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
405 if (!DbiS) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
406 consumeError(DbiS.takeError());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
407 return false;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
408 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
409
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
410 return DbiS->getGlobalSymbolStreamIndex() < getNumStreams();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
411 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
412
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
413 bool PDBFile::hasPDBInfoStream() const { return StreamPDB < getNumStreams(); }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
414
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
415 bool PDBFile::hasPDBIpiStream() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
416 if (!hasPDBInfoStream())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
417 return false;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
418
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
419 if (StreamIPI >= getNumStreams())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
420 return false;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
421
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
422 auto &InfoStream = cantFail(const_cast<PDBFile *>(this)->getPDBInfoStream());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
423 return InfoStream.containsIdStream();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
424 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
425
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
426 bool PDBFile::hasPDBPublicsStream() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
427 auto DbiS = getPDBDbiStream();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
428 if (!DbiS) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
429 consumeError(DbiS.takeError());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
430 return false;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
431 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
432 return DbiS->getPublicSymbolStreamIndex() < getNumStreams();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
433 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
434
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
435 bool PDBFile::hasPDBSymbolStream() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
436 auto DbiS = getPDBDbiStream();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
437 if (!DbiS)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
438 return false;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
439 return DbiS->getSymRecordStreamIndex() < getNumStreams();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
440 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
441
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
442 bool PDBFile::hasPDBTpiStream() const { return StreamTPI < getNumStreams(); }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
443
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
444 bool PDBFile::hasPDBStringTable() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
445 auto IS = getPDBInfoStream();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
446 if (!IS)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
447 return false;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
448 return IS->getNamedStreamIndex("/names") < getNumStreams();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
449 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
450
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
451 /// Wrapper around MappedBlockStream::createIndexedStream() that checks if a
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
452 /// stream with that index actually exists. If it does not, the return value
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
453 /// will have an MSFError with code msf_error_code::no_stream. Else, the return
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
454 /// value will contain the stream returned by createIndexedStream().
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
455 Expected<std::unique_ptr<MappedBlockStream>>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
456 PDBFile::safelyCreateIndexedStream(const MSFLayout &Layout,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
457 BinaryStreamRef MsfData,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
458 uint32_t StreamIndex) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
459 if (StreamIndex >= getNumStreams())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
460 return make_error<RawError>(raw_error_code::no_stream);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
461 return MappedBlockStream::createIndexedStream(Layout, MsfData, StreamIndex,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
462 Allocator);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
463 }