blob: 8520408ebd3b9d73cca021791985a7cebcc6c236 [file] [log] [blame]
Zachary Turner0a43efe2016-04-25 17:38:08 +00001//===- PDBFile.cpp - Low level interface to a PDB file ----------*- C++ -*-===//
2//
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//===----------------------------------------------------------------------===//
9
10#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
Zachary Turnerd8447992016-06-07 05:28:55 +000011
Zachary Turner0a43efe2016-04-25 17:38:08 +000012#include "llvm/ADT/ArrayRef.h"
Zachary Turnera3225b02016-07-29 20:56:36 +000013#include "llvm/DebugInfo/MSF/StreamArray.h"
14#include "llvm/DebugInfo/MSF/StreamInterface.h"
15#include "llvm/DebugInfo/MSF/StreamReader.h"
16#include "llvm/DebugInfo/MSF/StreamWriter.h"
Zachary Turner2f09b502016-04-29 17:28:47 +000017#include "llvm/DebugInfo/PDB/Raw/DbiStream.h"
18#include "llvm/DebugInfo/PDB/Raw/InfoStream.h"
Zachary Turner3df1bfa2016-06-03 05:52:57 +000019#include "llvm/DebugInfo/PDB/Raw/NameHashTable.h"
Rui Ueyama1f6b6e22016-05-13 21:21:53 +000020#include "llvm/DebugInfo/PDB/Raw/PublicsStream.h"
Zachary Turner819e77d2016-05-06 20:51:57 +000021#include "llvm/DebugInfo/PDB/Raw/RawError.h"
Rui Ueyama0fcd8262016-05-20 19:55:17 +000022#include "llvm/DebugInfo/PDB/Raw/SymbolStream.h"
Zachary Turnerf5c59652016-05-03 00:28:21 +000023#include "llvm/DebugInfo/PDB/Raw/TpiStream.h"
Zachary Turner0a43efe2016-04-25 17:38:08 +000024#include "llvm/Support/Endian.h"
Zachary Turner1dc9fd32016-06-14 20:48:36 +000025#include "llvm/Support/FileOutputBuffer.h"
Zachary Turner0a43efe2016-04-25 17:38:08 +000026#include "llvm/Support/MemoryBuffer.h"
27
28using namespace llvm;
Zachary Turnerb84faa82016-06-10 05:10:19 +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 Turner0a43efe2016-04-25 17:38:08 +000032
33namespace {
Zachary Turnerb84faa82016-06-10 05:10:19 +000034typedef FixedStreamArray<support::ulittle32_t> ulittle_array;
Zachary Turner0a43efe2016-04-25 17:38:08 +000035}
36
Zachary Turnerd66889c2016-07-28 19:12:28 +000037PDBFile::PDBFile(std::unique_ptr<ReadableStream> PdbFileBuffer,
Zachary Turnere109dc62016-07-22 19:56:26 +000038 BumpPtrAllocator &Allocator)
Zachary Turnere4a4f332016-07-22 19:56:33 +000039 : Allocator(Allocator), Buffer(std::move(PdbFileBuffer)) {}
Zachary Turner0a43efe2016-04-25 17:38:08 +000040
41PDBFile::~PDBFile() {}
42
Zachary Turnerd66889c2016-07-28 19:12:28 +000043uint32_t PDBFile::getBlockSize() const { return ContainerLayout.SB->BlockSize; }
Zachary Turner0a43efe2016-04-25 17:38:08 +000044
Zachary Turnere4a4f332016-07-22 19:56:33 +000045uint32_t PDBFile::getFreeBlockMapBlock() const {
Zachary Turnerd66889c2016-07-28 19:12:28 +000046 return ContainerLayout.SB->FreeBlockMapBlock;
Zachary Turnere4a4f332016-07-22 19:56:33 +000047}
Zachary Turner0a43efe2016-04-25 17:38:08 +000048
Zachary Turnerd66889c2016-07-28 19:12:28 +000049uint32_t PDBFile::getBlockCount() const {
50 return ContainerLayout.SB->NumBlocks;
51}
Zachary Turner0a43efe2016-04-25 17:38:08 +000052
Zachary Turnere4a4f332016-07-22 19:56:33 +000053uint32_t PDBFile::getNumDirectoryBytes() const {
Zachary Turnerd66889c2016-07-28 19:12:28 +000054 return ContainerLayout.SB->NumDirectoryBytes;
Zachary Turnere4a4f332016-07-22 19:56:33 +000055}
Zachary Turner0a43efe2016-04-25 17:38:08 +000056
Zachary Turnere4a4f332016-07-22 19:56:33 +000057uint32_t PDBFile::getBlockMapIndex() const {
Zachary Turnerd66889c2016-07-28 19:12:28 +000058 return ContainerLayout.SB->BlockMapAddr;
Zachary Turnere4a4f332016-07-22 19:56:33 +000059}
Zachary Turner0a43efe2016-04-25 17:38:08 +000060
Zachary Turnerd66889c2016-07-28 19:12:28 +000061uint32_t PDBFile::getUnknown1() const { return ContainerLayout.SB->Unknown1; }
Zachary Turner0a43efe2016-04-25 17:38:08 +000062
63uint32_t PDBFile::getNumDirectoryBlocks() const {
Zachary Turnerd66889c2016-07-28 19:12:28 +000064 return msf::bytesToBlocks(ContainerLayout.SB->NumDirectoryBytes,
65 ContainerLayout.SB->BlockSize);
Zachary Turner0a43efe2016-04-25 17:38:08 +000066}
67
68uint64_t PDBFile::getBlockMapOffset() const {
Zachary Turnerd66889c2016-07-28 19:12:28 +000069 return (uint64_t)ContainerLayout.SB->BlockMapAddr *
70 ContainerLayout.SB->BlockSize;
Zachary Turner0a43efe2016-04-25 17:38:08 +000071}
72
Zachary Turnerd66889c2016-07-28 19:12:28 +000073uint32_t PDBFile::getNumStreams() const {
74 return ContainerLayout.StreamSizes.size();
75}
Zachary Turner0a43efe2016-04-25 17:38:08 +000076
77uint32_t PDBFile::getStreamByteSize(uint32_t StreamIndex) const {
Zachary Turnerd66889c2016-07-28 19:12:28 +000078 return ContainerLayout.StreamSizes[StreamIndex];
Zachary Turner0a43efe2016-04-25 17:38:08 +000079}
80
Zachary Turnerd8447992016-06-07 05:28:55 +000081ArrayRef<support::ulittle32_t>
Zachary Turner0a43efe2016-04-25 17:38:08 +000082PDBFile::getStreamBlockList(uint32_t StreamIndex) const {
Zachary Turnerd66889c2016-07-28 19:12:28 +000083 return ContainerLayout.StreamMap[StreamIndex];
Zachary Turner0a43efe2016-04-25 17:38:08 +000084}
85
David Majnemer1b79e9a2016-07-10 05:32:05 +000086uint32_t PDBFile::getFileSize() const { return Buffer->getLength(); }
Zachary Turner1dc9fd32016-06-14 20:48:36 +000087
David Majnemer6211b1f2016-07-10 03:34:47 +000088Expected<ArrayRef<uint8_t>> PDBFile::getBlockData(uint32_t BlockIndex,
89 uint32_t NumBytes) const {
Zachary Turnerfaa554b2016-07-15 22:16:56 +000090 uint64_t StreamBlockOffset = msf::blockToOffset(BlockIndex, getBlockSize());
Zachary Turner0a43efe2016-04-25 17:38:08 +000091
Zachary Turnerb84faa82016-06-10 05:10:19 +000092 ArrayRef<uint8_t> Result;
93 if (auto EC = Buffer->readBytes(StreamBlockOffset, NumBytes, Result))
David Majnemer6211b1f2016-07-10 03:34:47 +000094 return std::move(EC);
Zachary Turnerb84faa82016-06-10 05:10:19 +000095 return Result;
Zachary Turner0a43efe2016-04-25 17:38:08 +000096}
97
Zachary Turner5acb4ac2016-06-10 05:09:12 +000098Error PDBFile::setBlockData(uint32_t BlockIndex, uint32_t Offset,
99 ArrayRef<uint8_t> Data) const {
Zachary Turnerd66889c2016-07-28 19:12:28 +0000100 return make_error<RawError>(raw_error_code::not_writable,
101 "PDBFile is immutable");
Zachary Turner5acb4ac2016-06-10 05:09:12 +0000102}
103
Zachary Turner819e77d2016-05-06 20:51:57 +0000104Error PDBFile::parseFileHeaders() {
Zachary Turnerb84faa82016-06-10 05:10:19 +0000105 StreamReader Reader(*Buffer);
Zachary Turnerc59261c2016-05-25 03:53:16 +0000106
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000107 // Initialize SB.
Zachary Turnere4a4f332016-07-22 19:56:33 +0000108 const msf::SuperBlock *SB = nullptr;
Zachary Turnerb84faa82016-06-10 05:10:19 +0000109 if (auto EC = Reader.readObject(SB)) {
110 consumeError(std::move(EC));
Zachary Turner819e77d2016-05-06 20:51:57 +0000111 return make_error<RawError>(raw_error_code::corrupt_file,
112 "Does not contain superblock");
Zachary Turnerb84faa82016-06-10 05:10:19 +0000113 }
Zachary Turner0a43efe2016-04-25 17:38:08 +0000114
Zachary Turnere4a4f332016-07-22 19:56:33 +0000115 if (auto EC = msf::validateSuperBlock(*SB))
Zachary Turnerab58ae82016-06-30 17:43:00 +0000116 return EC;
Zachary Turner819e77d2016-05-06 20:51:57 +0000117
Zachary Turnere4a4f332016-07-22 19:56:33 +0000118 if (Buffer->getLength() % SB->BlockSize != 0)
119 return make_error<RawError>(raw_error_code::corrupt_file,
120 "File size is not a multiple of block size");
Zachary Turnerd66889c2016-07-28 19:12:28 +0000121 ContainerLayout.SB = SB;
Zachary Turnere4a4f332016-07-22 19:56:33 +0000122
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000123 // Initialize Free Page Map.
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000124 ContainerLayout.FreePageMap.resize(SB->NumBlocks);
125 ArrayRef<uint8_t> FpmBytes;
126 // The Fpm exists either at block 1 or block 2 of the MSF. However, this
127 // allows for a maximum of getBlockSize() * 8 blocks bits in the Fpm, and
128 // thusly an equal number of total blocks in the file. For a block size
129 // of 4KiB (very common), this would yield 32KiB total blocks in file, for a
130 // maximum file size of 32KiB * 4KiB = 128MiB. Obviously this won't do, so
131 // the Fpm is split across the file at `getBlockSize()` intervals. As a
132 // result, every block whose index is of the form |{1,2} + getBlockSize() * k|
133 // for any non-negative integer k is an Fpm block. In theory, we only really
134 // need to reserve blocks of the form |{1,2} + getBlockSize() * 8 * k|, but
135 // current versions of the MSF format already expect the Fpm to be arranged
136 // at getBlockSize() intervals, so we have to be compatible.
137 // See the function fpmPn() for more information:
138 // https://github.com/Microsoft/microsoft-pdb/blob/master/PDB/msf/msf.cpp#L489
139
140 uint32_t BlocksPerSection = getBlockSize();
141 uint64_t FpmBlockOffset = SB->FreeBlockMapBlock;
142 uint32_t BlocksRemaining = getBlockCount();
143 for (uint32_t SI = 0; BlocksRemaining > 0; ++SI) {
144 uint32_t FpmFileOffset = FpmBlockOffset * getBlockSize();
145
146 if (auto EC = Buffer->readBytes(FpmFileOffset, getBlockSize(), FpmBytes))
147 return EC;
148
149 uint32_t BlocksThisSection = std::min(BlocksRemaining, BlocksPerSection);
150 for (uint32_t I = 0; I < BlocksThisSection; ++I) {
151 uint32_t BI = I + BlocksPerSection * SI;
152
153 if (FpmBytes[I / 8] & (1 << (I % 8)))
154 ContainerLayout.FreePageMap[BI] = true;
155 }
156 BlocksRemaining -= BlocksThisSection;
157 FpmBlockOffset += BlocksPerSection;
158 }
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000159
Zachary Turnerab58ae82016-06-30 17:43:00 +0000160 Reader.setOffset(getBlockMapOffset());
Zachary Turnerd66889c2016-07-28 19:12:28 +0000161 if (auto EC = Reader.readArray(ContainerLayout.DirectoryBlocks,
162 getNumDirectoryBlocks()))
Zachary Turnerab58ae82016-06-30 17:43:00 +0000163 return EC;
Zachary Turner0a43efe2016-04-25 17:38:08 +0000164
Zachary Turner819e77d2016-05-06 20:51:57 +0000165 return Error::success();
Zachary Turner0a43efe2016-04-25 17:38:08 +0000166}
167
Zachary Turner819e77d2016-05-06 20:51:57 +0000168Error PDBFile::parseStreamData() {
Zachary Turnerd66889c2016-07-28 19:12:28 +0000169 assert(ContainerLayout.SB);
Zachary Turnerd8447992016-06-07 05:28:55 +0000170 if (DirectoryStream)
171 return Error::success();
Zachary Turner0a43efe2016-04-25 17:38:08 +0000172
Zachary Turner0a43efe2016-04-25 17:38:08 +0000173 uint32_t NumStreams = 0;
Zachary Turner0a43efe2016-04-25 17:38:08 +0000174
Zachary Turnerd8447992016-06-07 05:28:55 +0000175 // Normally you can't use a MappedBlockStream without having fully parsed the
176 // PDB file, because it accesses the directory and various other things, which
177 // is exactly what we are attempting to parse. By specifying a custom
178 // subclass of IPDBStreamData which only accesses the fields that have already
179 // been parsed, we can avoid this and reuse MappedBlockStream.
Zachary Turnerd66889c2016-07-28 19:12:28 +0000180 auto DS = MappedBlockStream::createDirectoryStream(ContainerLayout, *Buffer);
181 StreamReader Reader(*DS);
Zachary Turnerd8447992016-06-07 05:28:55 +0000182 if (auto EC = Reader.readInteger(NumStreams))
183 return EC;
Zachary Turner0a43efe2016-04-25 17:38:08 +0000184
Zachary Turnerd66889c2016-07-28 19:12:28 +0000185 if (auto EC = Reader.readArray(ContainerLayout.StreamSizes, NumStreams))
Zachary Turnerd8447992016-06-07 05:28:55 +0000186 return EC;
187 for (uint32_t I = 0; I < NumStreams; ++I) {
Reid Kleckner5aba52f2016-06-22 22:42:24 +0000188 uint32_t StreamSize = getStreamByteSize(I);
189 // FIXME: What does StreamSize ~0U mean?
David Majnemer9efba742016-05-27 16:16:48 +0000190 uint64_t NumExpectedStreamBlocks =
Zachary Turnere4a4f332016-07-22 19:56:33 +0000191 StreamSize == UINT32_MAX
192 ? 0
Zachary Turnerd66889c2016-07-28 19:12:28 +0000193 : msf::bytesToBlocks(StreamSize, ContainerLayout.SB->BlockSize);
Zachary Turnerb84faa82016-06-10 05:10:19 +0000194
195 // For convenience, we store the block array contiguously. This is because
196 // if someone calls setStreamMap(), it is more convenient to be able to call
197 // it with an ArrayRef instead of setting up a StreamRef. Since the
198 // DirectoryStream is cached in the class and thus lives for the life of the
199 // class, we can be guaranteed that readArray() will return a stable
200 // reference, even if it has to allocate from its internal pool.
201 ArrayRef<support::ulittle32_t> Blocks;
Zachary Turnerd8447992016-06-07 05:28:55 +0000202 if (auto EC = Reader.readArray(Blocks, NumExpectedStreamBlocks))
203 return EC;
David Majnemer1b79e9a2016-07-10 05:32:05 +0000204 for (uint32_t Block : Blocks) {
Zachary Turnerd66889c2016-07-28 19:12:28 +0000205 uint64_t BlockEndOffset =
206 (uint64_t)(Block + 1) * ContainerLayout.SB->BlockSize;
David Majnemer1b79e9a2016-07-10 05:32:05 +0000207 if (BlockEndOffset > getFileSize())
208 return make_error<RawError>(raw_error_code::corrupt_file,
209 "Stream block map is corrupt.");
210 }
Zachary Turnerd66889c2016-07-28 19:12:28 +0000211 ContainerLayout.StreamMap.push_back(Blocks);
David Majnemer9efba742016-05-27 16:16:48 +0000212 }
213
Zachary Turner0a43efe2016-04-25 17:38:08 +0000214 // We should have read exactly SB->NumDirectoryBytes bytes.
Zachary Turnerd8447992016-06-07 05:28:55 +0000215 assert(Reader.bytesRemaining() == 0);
Zachary Turnerd66889c2016-07-28 19:12:28 +0000216 DirectoryStream = std::move(DS);
Zachary Turner819e77d2016-05-06 20:51:57 +0000217 return Error::success();
Zachary Turner0a43efe2016-04-25 17:38:08 +0000218}
219
Zachary Turnerd8447992016-06-07 05:28:55 +0000220llvm::ArrayRef<support::ulittle32_t> PDBFile::getDirectoryBlockArray() const {
Zachary Turnerd66889c2016-07-28 19:12:28 +0000221 return ContainerLayout.DirectoryBlocks;
Zachary Turner0a43efe2016-04-25 17:38:08 +0000222}
Zachary Turner53a65ba2016-04-26 18:42:34 +0000223
Zachary Turner819e77d2016-05-06 20:51:57 +0000224Expected<InfoStream &> PDBFile::getPDBInfoStream() {
Zachary Turner2f09b502016-04-29 17:28:47 +0000225 if (!Info) {
Zachary Turnerd66889c2016-07-28 19:12:28 +0000226 auto InfoS = MappedBlockStream::createIndexedStream(ContainerLayout,
227 *Buffer, StreamPDB);
228 auto TempInfo = llvm::make_unique<InfoStream>(std::move(InfoS));
Zachary Turnera1657a92016-06-08 17:26:39 +0000229 if (auto EC = TempInfo->reload())
Zachary Turner819e77d2016-05-06 20:51:57 +0000230 return std::move(EC);
Zachary Turnera1657a92016-06-08 17:26:39 +0000231 Info = std::move(TempInfo);
Zachary Turner53a65ba2016-04-26 18:42:34 +0000232 }
Zachary Turner2f09b502016-04-29 17:28:47 +0000233 return *Info;
Zachary Turner53a65ba2016-04-26 18:42:34 +0000234}
235
Zachary Turner819e77d2016-05-06 20:51:57 +0000236Expected<DbiStream &> PDBFile::getPDBDbiStream() {
Zachary Turner2f09b502016-04-29 17:28:47 +0000237 if (!Dbi) {
Zachary Turnerd66889c2016-07-28 19:12:28 +0000238 auto DbiS = MappedBlockStream::createIndexedStream(ContainerLayout, *Buffer,
239 StreamDBI);
240 auto TempDbi = llvm::make_unique<DbiStream>(*this, std::move(DbiS));
Zachary Turnera1657a92016-06-08 17:26:39 +0000241 if (auto EC = TempDbi->reload())
Zachary Turner819e77d2016-05-06 20:51:57 +0000242 return std::move(EC);
Zachary Turnera1657a92016-06-08 17:26:39 +0000243 Dbi = std::move(TempDbi);
Zachary Turner53a65ba2016-04-26 18:42:34 +0000244 }
Zachary Turner2f09b502016-04-29 17:28:47 +0000245 return *Dbi;
Zachary Turner53a65ba2016-04-26 18:42:34 +0000246}
Zachary Turnerf5c59652016-05-03 00:28:21 +0000247
Zachary Turner819e77d2016-05-06 20:51:57 +0000248Expected<TpiStream &> PDBFile::getPDBTpiStream() {
Zachary Turnerf5c59652016-05-03 00:28:21 +0000249 if (!Tpi) {
Zachary Turnerd66889c2016-07-28 19:12:28 +0000250 auto TpiS = MappedBlockStream::createIndexedStream(ContainerLayout, *Buffer,
251 StreamTPI);
252 auto TempTpi = llvm::make_unique<TpiStream>(*this, std::move(TpiS));
Zachary Turnera1657a92016-06-08 17:26:39 +0000253 if (auto EC = TempTpi->reload())
Zachary Turner819e77d2016-05-06 20:51:57 +0000254 return std::move(EC);
Zachary Turnera1657a92016-06-08 17:26:39 +0000255 Tpi = std::move(TempTpi);
Zachary Turnerf5c59652016-05-03 00:28:21 +0000256 }
257 return *Tpi;
258}
Rui Ueyama1f6b6e22016-05-13 21:21:53 +0000259
Zachary Turnerc9972c62016-05-25 04:35:22 +0000260Expected<TpiStream &> PDBFile::getPDBIpiStream() {
261 if (!Ipi) {
Zachary Turnerd66889c2016-07-28 19:12:28 +0000262 auto IpiS = MappedBlockStream::createIndexedStream(ContainerLayout, *Buffer,
263 StreamIPI);
264 auto TempIpi = llvm::make_unique<TpiStream>(*this, std::move(IpiS));
Zachary Turnera1657a92016-06-08 17:26:39 +0000265 if (auto EC = TempIpi->reload())
Zachary Turnerc9972c62016-05-25 04:35:22 +0000266 return std::move(EC);
Zachary Turnera1657a92016-06-08 17:26:39 +0000267 Ipi = std::move(TempIpi);
Zachary Turnerc9972c62016-05-25 04:35:22 +0000268 }
269 return *Ipi;
270}
271
Rui Ueyama1f6b6e22016-05-13 21:21:53 +0000272Expected<PublicsStream &> PDBFile::getPDBPublicsStream() {
273 if (!Publics) {
274 auto DbiS = getPDBDbiStream();
Zachary Turnera1657a92016-06-08 17:26:39 +0000275 if (!DbiS)
276 return DbiS.takeError();
277
Rui Ueyama1f6b6e22016-05-13 21:21:53 +0000278 uint32_t PublicsStreamNum = DbiS->getPublicSymbolStreamIndex();
279
Zachary Turnerd66889c2016-07-28 19:12:28 +0000280 auto PublicS = MappedBlockStream::createIndexedStream(
281 ContainerLayout, *Buffer, PublicsStreamNum);
Zachary Turnera1657a92016-06-08 17:26:39 +0000282 auto TempPublics =
Zachary Turnerd66889c2016-07-28 19:12:28 +0000283 llvm::make_unique<PublicsStream>(*this, std::move(PublicS));
Zachary Turnera1657a92016-06-08 17:26:39 +0000284 if (auto EC = TempPublics->reload())
Rui Ueyama1f6b6e22016-05-13 21:21:53 +0000285 return std::move(EC);
Zachary Turnera1657a92016-06-08 17:26:39 +0000286 Publics = std::move(TempPublics);
Rui Ueyama1f6b6e22016-05-13 21:21:53 +0000287 }
288 return *Publics;
289}
Rui Ueyama0fcd8262016-05-20 19:55:17 +0000290
291Expected<SymbolStream &> PDBFile::getPDBSymbolStream() {
292 if (!Symbols) {
293 auto DbiS = getPDBDbiStream();
Zachary Turnera1657a92016-06-08 17:26:39 +0000294 if (!DbiS)
295 return DbiS.takeError();
296
Rui Ueyama0fcd8262016-05-20 19:55:17 +0000297 uint32_t SymbolStreamNum = DbiS->getSymRecordStreamIndex();
Zachary Turnerd66889c2016-07-28 19:12:28 +0000298 auto SymbolS = MappedBlockStream::createIndexedStream(
299 ContainerLayout, *Buffer, SymbolStreamNum);
Rui Ueyama0fcd8262016-05-20 19:55:17 +0000300
Zachary Turnerd66889c2016-07-28 19:12:28 +0000301 auto TempSymbols = llvm::make_unique<SymbolStream>(std::move(SymbolS));
Zachary Turnera1657a92016-06-08 17:26:39 +0000302 if (auto EC = TempSymbols->reload())
Rui Ueyama0fcd8262016-05-20 19:55:17 +0000303 return std::move(EC);
Zachary Turnera1657a92016-06-08 17:26:39 +0000304 Symbols = std::move(TempSymbols);
Rui Ueyama0fcd8262016-05-20 19:55:17 +0000305 }
306 return *Symbols;
307}
Zachary Turner3df1bfa2016-06-03 05:52:57 +0000308
309Expected<NameHashTable &> PDBFile::getStringTable() {
310 if (!StringTable || !StringTableStream) {
Zachary Turnera1657a92016-06-08 17:26:39 +0000311 auto IS = getPDBInfoStream();
312 if (!IS)
313 return IS.takeError();
314
315 uint32_t NameStreamIndex = IS->getNamedStreamIndex("/names");
Zachary Turner3df1bfa2016-06-03 05:52:57 +0000316
317 if (NameStreamIndex == 0)
318 return make_error<RawError>(raw_error_code::no_stream);
Zachary Turnerd2b2bfe2016-06-08 00:25:08 +0000319 if (NameStreamIndex >= getNumStreams())
320 return make_error<RawError>(raw_error_code::no_stream);
Zachary Turnerd66889c2016-07-28 19:12:28 +0000321 auto NS = MappedBlockStream::createIndexedStream(ContainerLayout, *Buffer,
322 NameStreamIndex);
Zachary Turnerd2b2bfe2016-06-08 00:25:08 +0000323
Zachary Turnerd66889c2016-07-28 19:12:28 +0000324 StreamReader Reader(*NS);
Zachary Turner3df1bfa2016-06-03 05:52:57 +0000325 auto N = llvm::make_unique<NameHashTable>();
326 if (auto EC = N->load(Reader))
327 return std::move(EC);
328 StringTable = std::move(N);
Zachary Turnerd66889c2016-07-28 19:12:28 +0000329 StringTableStream = std::move(NS);
Zachary Turner3df1bfa2016-06-03 05:52:57 +0000330 }
331 return *StringTable;
332}