Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 1 | //===- 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" |
| 11 | #include "llvm/ADT/ArrayRef.h" |
Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 12 | #include "llvm/DebugInfo/PDB/Raw/DbiStream.h" |
| 13 | #include "llvm/DebugInfo/PDB/Raw/InfoStream.h" |
Rui Ueyama | 1f6b6e2 | 2016-05-13 21:21:53 +0000 | [diff] [blame] | 14 | #include "llvm/DebugInfo/PDB/Raw/PublicsStream.h" |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 15 | #include "llvm/DebugInfo/PDB/Raw/RawError.h" |
Rui Ueyama | 0fcd826 | 2016-05-20 19:55:17 +0000 | [diff] [blame] | 16 | #include "llvm/DebugInfo/PDB/Raw/SymbolStream.h" |
Zachary Turner | f5c5965 | 2016-05-03 00:28:21 +0000 | [diff] [blame] | 17 | #include "llvm/DebugInfo/PDB/Raw/TpiStream.h" |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 18 | #include "llvm/Support/Endian.h" |
| 19 | #include "llvm/Support/MemoryBuffer.h" |
| 20 | |
| 21 | using namespace llvm; |
Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 22 | using namespace llvm::pdb; |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 23 | |
| 24 | namespace { |
| 25 | static const char Magic[] = {'M', 'i', 'c', 'r', 'o', 's', 'o', 'f', |
| 26 | 't', ' ', 'C', '/', 'C', '+', '+', ' ', |
| 27 | 'M', 'S', 'F', ' ', '7', '.', '0', '0', |
| 28 | '\r', '\n', '\x1a', 'D', 'S', '\0', '\0', '\0'}; |
| 29 | |
| 30 | // The superblock is overlaid at the beginning of the file (offset 0). |
| 31 | // It starts with a magic header and is followed by information which describes |
| 32 | // the layout of the file system. |
| 33 | struct SuperBlock { |
| 34 | char MagicBytes[sizeof(Magic)]; |
| 35 | // The file system is split into a variable number of fixed size elements. |
| 36 | // These elements are referred to as blocks. The size of a block may vary |
| 37 | // from system to system. |
| 38 | support::ulittle32_t BlockSize; |
| 39 | // This field's purpose is not yet known. |
| 40 | support::ulittle32_t Unknown0; |
| 41 | // This contains the number of blocks resident in the file system. In |
| 42 | // practice, NumBlocks * BlockSize is equivalent to the size of the PDB file. |
| 43 | support::ulittle32_t NumBlocks; |
| 44 | // This contains the number of bytes which make up the directory. |
| 45 | support::ulittle32_t NumDirectoryBytes; |
| 46 | // This field's purpose is not yet known. |
| 47 | support::ulittle32_t Unknown1; |
| 48 | // This contains the block # of the block map. |
| 49 | support::ulittle32_t BlockMapAddr; |
| 50 | }; |
| 51 | } |
| 52 | |
Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 53 | struct llvm::pdb::PDBFileContext { |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 54 | std::unique_ptr<MemoryBuffer> Buffer; |
| 55 | const SuperBlock *SB; |
| 56 | std::vector<uint32_t> StreamSizes; |
| 57 | DenseMap<uint32_t, std::vector<uint32_t>> StreamMap; |
| 58 | }; |
| 59 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 60 | static Error checkOffset(MemoryBufferRef M, uintptr_t Addr, |
| 61 | const uint64_t Size) { |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 62 | if (Addr + Size < Addr || Addr + Size < Size || |
| 63 | Addr + Size > uintptr_t(M.getBufferEnd()) || |
| 64 | Addr < uintptr_t(M.getBufferStart())) { |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 65 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 66 | "Invalid buffer address"); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 67 | } |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 68 | return Error::success(); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | template <typename T> |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 72 | static Error checkOffset(MemoryBufferRef M, ArrayRef<T> AR) { |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 73 | return checkOffset(M, uintptr_t(AR.data()), (uint64_t)AR.size() * sizeof(T)); |
| 74 | } |
| 75 | |
| 76 | PDBFile::PDBFile(std::unique_ptr<MemoryBuffer> MemBuffer) { |
| 77 | Context.reset(new PDBFileContext()); |
| 78 | Context->Buffer = std::move(MemBuffer); |
| 79 | } |
| 80 | |
| 81 | PDBFile::~PDBFile() {} |
| 82 | |
| 83 | uint32_t PDBFile::getBlockSize() const { return Context->SB->BlockSize; } |
| 84 | |
| 85 | uint32_t PDBFile::getUnknown0() const { return Context->SB->Unknown0; } |
| 86 | |
| 87 | uint32_t PDBFile::getBlockCount() const { return Context->SB->NumBlocks; } |
| 88 | |
| 89 | uint32_t PDBFile::getNumDirectoryBytes() const { |
| 90 | return Context->SB->NumDirectoryBytes; |
| 91 | } |
| 92 | |
| 93 | uint32_t PDBFile::getBlockMapIndex() const { return Context->SB->BlockMapAddr; } |
| 94 | |
| 95 | uint32_t PDBFile::getUnknown1() const { return Context->SB->Unknown1; } |
| 96 | |
| 97 | uint32_t PDBFile::getNumDirectoryBlocks() const { |
| 98 | return bytesToBlocks(Context->SB->NumDirectoryBytes, Context->SB->BlockSize); |
| 99 | } |
| 100 | |
| 101 | uint64_t PDBFile::getBlockMapOffset() const { |
| 102 | return (uint64_t)Context->SB->BlockMapAddr * Context->SB->BlockSize; |
| 103 | } |
| 104 | |
| 105 | uint32_t PDBFile::getNumStreams() const { return Context->StreamSizes.size(); } |
| 106 | |
| 107 | uint32_t PDBFile::getStreamByteSize(uint32_t StreamIndex) const { |
| 108 | return Context->StreamSizes[StreamIndex]; |
| 109 | } |
| 110 | |
| 111 | llvm::ArrayRef<uint32_t> |
| 112 | PDBFile::getStreamBlockList(uint32_t StreamIndex) const { |
| 113 | auto &Data = Context->StreamMap[StreamIndex]; |
| 114 | return llvm::ArrayRef<uint32_t>(Data); |
| 115 | } |
| 116 | |
| 117 | StringRef PDBFile::getBlockData(uint32_t BlockIndex, uint32_t NumBytes) const { |
| 118 | uint64_t StreamBlockOffset = blockToOffset(BlockIndex, getBlockSize()); |
| 119 | |
| 120 | return StringRef(Context->Buffer->getBufferStart() + StreamBlockOffset, |
| 121 | NumBytes); |
| 122 | } |
| 123 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 124 | Error PDBFile::parseFileHeaders() { |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 125 | std::error_code EC; |
| 126 | MemoryBufferRef BufferRef = *Context->Buffer; |
Zachary Turner | c59261c | 2016-05-25 03:53:16 +0000 | [diff] [blame] | 127 | |
Zachary Turner | f5c5965 | 2016-05-03 00:28:21 +0000 | [diff] [blame] | 128 | // Make sure the file is sufficiently large to hold a super block. |
| 129 | // Do this before attempting to read the super block. |
Zachary Turner | d6192f4 | 2016-05-02 22:16:57 +0000 | [diff] [blame] | 130 | if (BufferRef.getBufferSize() < sizeof(SuperBlock)) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 131 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 132 | "Does not contain superblock"); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 133 | |
| 134 | Context->SB = |
| 135 | reinterpret_cast<const SuperBlock *>(BufferRef.getBufferStart()); |
| 136 | const SuperBlock *SB = Context->SB; |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 137 | // Check the magic bytes. |
| 138 | if (memcmp(SB->MagicBytes, Magic, sizeof(Magic)) != 0) |
| 139 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 140 | "MSF magic header doesn't match"); |
| 141 | |
David Majnemer | 878cadb | 2016-05-27 15:57:38 +0000 | [diff] [blame] | 142 | // We don't support blocksizes which aren't a multiple of four bytes. |
| 143 | if (SB->BlockSize % sizeof(support::ulittle32_t) != 0) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 144 | return make_error<RawError>(raw_error_code::corrupt_file, |
David Majnemer | 878cadb | 2016-05-27 15:57:38 +0000 | [diff] [blame] | 145 | "Block size is not multiple of 4."); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 146 | |
Zachary Turner | 9213ba5 | 2016-04-29 18:09:19 +0000 | [diff] [blame] | 147 | switch (SB->BlockSize) { |
| 148 | case 512: case 1024: case 2048: case 4096: |
| 149 | break; |
| 150 | default: |
| 151 | // An invalid block size suggests a corrupt PDB file. |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 152 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 153 | "Unsupported block size."); |
Zachary Turner | 9213ba5 | 2016-04-29 18:09:19 +0000 | [diff] [blame] | 154 | } |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 155 | |
David Majnemer | 878cadb | 2016-05-27 15:57:38 +0000 | [diff] [blame] | 156 | if (BufferRef.getBufferSize() % SB->BlockSize != 0) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 157 | return make_error<RawError>(raw_error_code::corrupt_file, |
David Majnemer | 878cadb | 2016-05-27 15:57:38 +0000 | [diff] [blame] | 158 | "File size is not a multiple of block size"); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 159 | |
| 160 | // We don't support directories whose sizes aren't a multiple of four bytes. |
| 161 | if (SB->NumDirectoryBytes % sizeof(support::ulittle32_t) != 0) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 162 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 163 | "Directory size is not multiple of 4."); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 164 | |
| 165 | // The number of blocks which comprise the directory is a simple function of |
| 166 | // the number of bytes it contains. |
| 167 | uint64_t NumDirectoryBlocks = getNumDirectoryBlocks(); |
| 168 | |
| 169 | // The block map, as we understand it, is a block which consists of a list of |
| 170 | // block numbers. |
| 171 | // It is unclear what would happen if the number of blocks couldn't fit on a |
| 172 | // single block. |
| 173 | if (NumDirectoryBlocks > SB->BlockSize / sizeof(support::ulittle32_t)) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 174 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 175 | "Too many directory blocks."); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 176 | |
David Majnemer | 5d842ea | 2016-05-27 16:16:45 +0000 | [diff] [blame] | 177 | // Make sure the directory block array fits within the file. |
| 178 | if (auto EC = checkOffset(BufferRef, getDirectoryBlockArray())) |
| 179 | return EC; |
| 180 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 181 | return Error::success(); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 184 | Error PDBFile::parseStreamData() { |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 185 | assert(Context && Context->SB); |
| 186 | |
| 187 | bool SeenNumStreams = false; |
| 188 | uint32_t NumStreams = 0; |
| 189 | uint32_t StreamIdx = 0; |
| 190 | uint64_t DirectoryBytesRead = 0; |
| 191 | |
| 192 | MemoryBufferRef M = *Context->Buffer; |
| 193 | const SuperBlock *SB = Context->SB; |
| 194 | |
| 195 | auto DirectoryBlocks = getDirectoryBlockArray(); |
| 196 | |
| 197 | // The structure of the directory is as follows: |
| 198 | // struct PDBDirectory { |
| 199 | // uint32_t NumStreams; |
| 200 | // uint32_t StreamSizes[NumStreams]; |
| 201 | // uint32_t StreamMap[NumStreams][]; |
| 202 | // }; |
| 203 | // |
| 204 | // Empty streams don't consume entries in the StreamMap. |
| 205 | for (uint32_t DirectoryBlockAddr : DirectoryBlocks) { |
| 206 | uint64_t DirectoryBlockOffset = |
| 207 | blockToOffset(DirectoryBlockAddr, SB->BlockSize); |
| 208 | auto DirectoryBlock = |
| 209 | makeArrayRef(reinterpret_cast<const support::ulittle32_t *>( |
| 210 | M.getBufferStart() + DirectoryBlockOffset), |
| 211 | SB->BlockSize / sizeof(support::ulittle32_t)); |
| 212 | if (auto EC = checkOffset(M, DirectoryBlock)) |
| 213 | return EC; |
| 214 | |
| 215 | // We read data out of the directory four bytes at a time. Depending on |
| 216 | // where we are in the directory, the contents may be: the number of streams |
| 217 | // in the directory, a stream's size, or a block in the stream map. |
| 218 | for (uint32_t Data : DirectoryBlock) { |
| 219 | // Don't read beyond the end of the directory. |
| 220 | if (DirectoryBytesRead == SB->NumDirectoryBytes) |
| 221 | break; |
| 222 | |
| 223 | DirectoryBytesRead += sizeof(Data); |
| 224 | |
| 225 | // This data must be the number of streams if we haven't seen it yet. |
| 226 | if (!SeenNumStreams) { |
| 227 | NumStreams = Data; |
| 228 | SeenNumStreams = true; |
| 229 | continue; |
| 230 | } |
| 231 | // This data must be a stream size if we have not seen them all yet. |
| 232 | if (Context->StreamSizes.size() < NumStreams) { |
| 233 | // It seems like some streams have their set to -1 when their contents |
| 234 | // are not present. Treat them like empty streams for now. |
| 235 | if (Data == UINT32_MAX) |
| 236 | Context->StreamSizes.push_back(0); |
| 237 | else |
| 238 | Context->StreamSizes.push_back(Data); |
| 239 | continue; |
| 240 | } |
| 241 | |
| 242 | // This data must be a stream block number if we have seen all of the |
| 243 | // stream sizes. |
| 244 | std::vector<uint32_t> *StreamBlocks = nullptr; |
| 245 | // Figure out which stream this block number belongs to. |
| 246 | while (StreamIdx < NumStreams) { |
| 247 | uint64_t NumExpectedStreamBlocks = |
| 248 | bytesToBlocks(Context->StreamSizes[StreamIdx], SB->BlockSize); |
| 249 | StreamBlocks = &Context->StreamMap[StreamIdx]; |
| 250 | if (NumExpectedStreamBlocks > StreamBlocks->size()) |
| 251 | break; |
| 252 | ++StreamIdx; |
| 253 | } |
| 254 | // It seems this block doesn't belong to any stream? The stream is either |
| 255 | // corrupt or something more mysterious is going on. |
| 256 | if (StreamIdx == NumStreams) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 257 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 258 | "Orphaned block found?"); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 259 | |
David Majnemer | 9efba74 | 2016-05-27 16:16:48 +0000 | [diff] [blame^] | 260 | uint64_t BlockOffset = blockToOffset(Data, getBlockSize()); |
| 261 | if (BlockOffset + getBlockSize() < BlockOffset) |
| 262 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 263 | "Bogus stream block number"); |
| 264 | if (BlockOffset + getBlockSize() > M.getBufferSize()) |
| 265 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 266 | "Stream block number is out of bounds"); |
| 267 | |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 268 | StreamBlocks->push_back(Data); |
| 269 | } |
| 270 | } |
| 271 | |
David Majnemer | 9efba74 | 2016-05-27 16:16:48 +0000 | [diff] [blame^] | 272 | for (uint32_t SI = 0; SI != NumStreams; ++SI) { |
| 273 | uint64_t NumExpectedStreamBlocks = |
| 274 | bytesToBlocks(getStreamByteSize(SI), getBlockSize()); |
| 275 | size_t NumStreamBlocks = getStreamBlockList(SI).size(); |
| 276 | if (NumExpectedStreamBlocks != NumStreamBlocks) |
| 277 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 278 | "The number of stream blocks is not " |
| 279 | "sufficient for the size of this stream"); |
| 280 | } |
| 281 | |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 282 | // We should have read exactly SB->NumDirectoryBytes bytes. |
| 283 | assert(DirectoryBytesRead == SB->NumDirectoryBytes); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 284 | return Error::success(); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | llvm::ArrayRef<support::ulittle32_t> PDBFile::getDirectoryBlockArray() { |
| 288 | return makeArrayRef( |
| 289 | reinterpret_cast<const support::ulittle32_t *>( |
| 290 | Context->Buffer->getBufferStart() + getBlockMapOffset()), |
| 291 | getNumDirectoryBlocks()); |
| 292 | } |
Zachary Turner | 53a65ba | 2016-04-26 18:42:34 +0000 | [diff] [blame] | 293 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 294 | Expected<InfoStream &> PDBFile::getPDBInfoStream() { |
Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 295 | if (!Info) { |
| 296 | Info.reset(new InfoStream(*this)); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 297 | if (auto EC = Info->reload()) |
| 298 | return std::move(EC); |
Zachary Turner | 53a65ba | 2016-04-26 18:42:34 +0000 | [diff] [blame] | 299 | } |
Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 300 | return *Info; |
Zachary Turner | 53a65ba | 2016-04-26 18:42:34 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 303 | Expected<DbiStream &> PDBFile::getPDBDbiStream() { |
Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 304 | if (!Dbi) { |
| 305 | Dbi.reset(new DbiStream(*this)); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 306 | if (auto EC = Dbi->reload()) |
| 307 | return std::move(EC); |
Zachary Turner | 53a65ba | 2016-04-26 18:42:34 +0000 | [diff] [blame] | 308 | } |
Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 309 | return *Dbi; |
Zachary Turner | 53a65ba | 2016-04-26 18:42:34 +0000 | [diff] [blame] | 310 | } |
Zachary Turner | f5c5965 | 2016-05-03 00:28:21 +0000 | [diff] [blame] | 311 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 312 | Expected<TpiStream &> PDBFile::getPDBTpiStream() { |
Zachary Turner | f5c5965 | 2016-05-03 00:28:21 +0000 | [diff] [blame] | 313 | if (!Tpi) { |
Zachary Turner | c9972c6 | 2016-05-25 04:35:22 +0000 | [diff] [blame] | 314 | Tpi.reset(new TpiStream(*this, StreamTPI)); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 315 | if (auto EC = Tpi->reload()) |
| 316 | return std::move(EC); |
Zachary Turner | f5c5965 | 2016-05-03 00:28:21 +0000 | [diff] [blame] | 317 | } |
| 318 | return *Tpi; |
| 319 | } |
Rui Ueyama | 1f6b6e2 | 2016-05-13 21:21:53 +0000 | [diff] [blame] | 320 | |
Zachary Turner | c9972c6 | 2016-05-25 04:35:22 +0000 | [diff] [blame] | 321 | Expected<TpiStream &> PDBFile::getPDBIpiStream() { |
| 322 | if (!Ipi) { |
| 323 | Ipi.reset(new TpiStream(*this, StreamIPI)); |
| 324 | if (auto EC = Ipi->reload()) |
| 325 | return std::move(EC); |
| 326 | } |
| 327 | return *Ipi; |
| 328 | } |
| 329 | |
Rui Ueyama | 1f6b6e2 | 2016-05-13 21:21:53 +0000 | [diff] [blame] | 330 | Expected<PublicsStream &> PDBFile::getPDBPublicsStream() { |
| 331 | if (!Publics) { |
| 332 | auto DbiS = getPDBDbiStream(); |
| 333 | if (auto EC = DbiS.takeError()) |
| 334 | return std::move(EC); |
| 335 | uint32_t PublicsStreamNum = DbiS->getPublicSymbolStreamIndex(); |
| 336 | |
| 337 | Publics.reset(new PublicsStream(*this, PublicsStreamNum)); |
| 338 | if (auto EC = Publics->reload()) |
| 339 | return std::move(EC); |
| 340 | } |
| 341 | return *Publics; |
| 342 | } |
Rui Ueyama | 0fcd826 | 2016-05-20 19:55:17 +0000 | [diff] [blame] | 343 | |
| 344 | Expected<SymbolStream &> PDBFile::getPDBSymbolStream() { |
| 345 | if (!Symbols) { |
| 346 | auto DbiS = getPDBDbiStream(); |
| 347 | if (auto EC = DbiS.takeError()) |
| 348 | return std::move(EC); |
| 349 | uint32_t SymbolStreamNum = DbiS->getSymRecordStreamIndex(); |
| 350 | |
| 351 | Symbols.reset(new SymbolStream(*this, SymbolStreamNum)); |
| 352 | if (auto EC = Symbols->reload()) |
| 353 | return std::move(EC); |
| 354 | } |
| 355 | return *Symbols; |
| 356 | } |