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" |
Zachary Turner | d844799 | 2016-06-07 05:28:55 +0000 | [diff] [blame] | 11 | |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 12 | #include "llvm/ADT/ArrayRef.h" |
Zachary Turner | d844799 | 2016-06-07 05:28:55 +0000 | [diff] [blame] | 13 | #include "llvm/DebugInfo/CodeView/StreamArray.h" |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 14 | #include "llvm/DebugInfo/CodeView/StreamInterface.h" |
Zachary Turner | d844799 | 2016-06-07 05:28:55 +0000 | [diff] [blame] | 15 | #include "llvm/DebugInfo/CodeView/StreamReader.h" |
Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 16 | #include "llvm/DebugInfo/PDB/Raw/DbiStream.h" |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 17 | #include "llvm/DebugInfo/PDB/Raw/DirectoryStreamData.h" |
Zachary Turner | d844799 | 2016-06-07 05:28:55 +0000 | [diff] [blame] | 18 | #include "llvm/DebugInfo/PDB/Raw/IndexedStreamData.h" |
Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 19 | #include "llvm/DebugInfo/PDB/Raw/InfoStream.h" |
Zachary Turner | 3df1bfa | 2016-06-03 05:52:57 +0000 | [diff] [blame] | 20 | #include "llvm/DebugInfo/PDB/Raw/NameHashTable.h" |
Rui Ueyama | 1f6b6e2 | 2016-05-13 21:21:53 +0000 | [diff] [blame] | 21 | #include "llvm/DebugInfo/PDB/Raw/PublicsStream.h" |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 22 | #include "llvm/DebugInfo/PDB/Raw/RawError.h" |
Rui Ueyama | 0fcd826 | 2016-05-20 19:55:17 +0000 | [diff] [blame] | 23 | #include "llvm/DebugInfo/PDB/Raw/SymbolStream.h" |
Zachary Turner | f5c5965 | 2016-05-03 00:28:21 +0000 | [diff] [blame] | 24 | #include "llvm/DebugInfo/PDB/Raw/TpiStream.h" |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Endian.h" |
Zachary Turner | 1dc9fd3 | 2016-06-14 20:48:36 +0000 | [diff] [blame^] | 26 | #include "llvm/Support/FileOutputBuffer.h" |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 27 | #include "llvm/Support/MemoryBuffer.h" |
| 28 | |
| 29 | using namespace llvm; |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 30 | using namespace llvm::codeview; |
Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 31 | using namespace llvm::pdb; |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 32 | |
| 33 | namespace { |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 34 | typedef FixedStreamArray<support::ulittle32_t> ulittle_array; |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 37 | PDBFile::PDBFile(std::unique_ptr<StreamInterface> PdbFileBuffer) |
| 38 | : Buffer(std::move(PdbFileBuffer)), SB(nullptr) {} |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 39 | |
| 40 | PDBFile::~PDBFile() {} |
| 41 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 42 | uint32_t PDBFile::getBlockSize() const { return SB->BlockSize; } |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 43 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 44 | uint32_t PDBFile::getUnknown0() const { return SB->Unknown0; } |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 45 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 46 | uint32_t PDBFile::getBlockCount() const { return SB->NumBlocks; } |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 47 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 48 | uint32_t PDBFile::getNumDirectoryBytes() const { return SB->NumDirectoryBytes; } |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 49 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 50 | uint32_t PDBFile::getBlockMapIndex() const { return SB->BlockMapAddr; } |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 51 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 52 | uint32_t PDBFile::getUnknown1() const { return SB->Unknown1; } |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 53 | |
| 54 | uint32_t PDBFile::getNumDirectoryBlocks() const { |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 55 | return bytesToBlocks(SB->NumDirectoryBytes, SB->BlockSize); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | uint64_t PDBFile::getBlockMapOffset() const { |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 59 | return (uint64_t)SB->BlockMapAddr * SB->BlockSize; |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 62 | uint32_t PDBFile::getNumStreams() const { return StreamSizes.size(); } |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 63 | |
| 64 | uint32_t PDBFile::getStreamByteSize(uint32_t StreamIndex) const { |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 65 | return StreamSizes[StreamIndex]; |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Zachary Turner | d844799 | 2016-06-07 05:28:55 +0000 | [diff] [blame] | 68 | ArrayRef<support::ulittle32_t> |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 69 | PDBFile::getStreamBlockList(uint32_t StreamIndex) const { |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 70 | return StreamMap[StreamIndex]; |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Zachary Turner | 1dc9fd3 | 2016-06-14 20:48:36 +0000 | [diff] [blame^] | 73 | size_t PDBFile::getFileSize() const { return Buffer->getLength(); } |
| 74 | |
Zachary Turner | e6fee88 | 2016-06-07 20:38:37 +0000 | [diff] [blame] | 75 | ArrayRef<uint8_t> PDBFile::getBlockData(uint32_t BlockIndex, |
| 76 | uint32_t NumBytes) const { |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 77 | uint64_t StreamBlockOffset = blockToOffset(BlockIndex, getBlockSize()); |
| 78 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 79 | ArrayRef<uint8_t> Result; |
| 80 | if (auto EC = Buffer->readBytes(StreamBlockOffset, NumBytes, Result)) |
| 81 | consumeError(std::move(EC)); |
| 82 | return Result; |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Zachary Turner | 5acb4ac | 2016-06-10 05:09:12 +0000 | [diff] [blame] | 85 | Error PDBFile::setBlockData(uint32_t BlockIndex, uint32_t Offset, |
| 86 | ArrayRef<uint8_t> Data) const { |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 87 | if (Offset >= getBlockSize()) |
| 88 | return make_error<RawError>( |
| 89 | raw_error_code::invalid_block_address, |
| 90 | "setBlockData attempted to write out of block bounds."); |
| 91 | if (Data.size() >= getBlockSize() - Offset) |
| 92 | return make_error<RawError>( |
| 93 | raw_error_code::invalid_block_address, |
| 94 | "setBlockData attempted to write out of block bounds."); |
Zachary Turner | 5acb4ac | 2016-06-10 05:09:12 +0000 | [diff] [blame] | 95 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 96 | uint64_t StreamBlockOffset = blockToOffset(BlockIndex, getBlockSize()); |
| 97 | StreamBlockOffset += Offset; |
| 98 | return Buffer->writeBytes(StreamBlockOffset, Data); |
Zachary Turner | 5acb4ac | 2016-06-10 05:09:12 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 101 | Error PDBFile::parseFileHeaders() { |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 102 | StreamReader Reader(*Buffer); |
Zachary Turner | c59261c | 2016-05-25 03:53:16 +0000 | [diff] [blame] | 103 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 104 | if (auto EC = Reader.readObject(SB)) { |
| 105 | consumeError(std::move(EC)); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 106 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 107 | "Does not contain superblock"); |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 108 | } |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 109 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 110 | // Check the magic bytes. |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 111 | if (memcmp(SB->MagicBytes, MsfMagic, sizeof(MsfMagic)) != 0) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 112 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 113 | "MSF magic header doesn't match"); |
| 114 | |
David Majnemer | 878cadb | 2016-05-27 15:57:38 +0000 | [diff] [blame] | 115 | // We don't support blocksizes which aren't a multiple of four bytes. |
| 116 | if (SB->BlockSize % sizeof(support::ulittle32_t) != 0) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 117 | return make_error<RawError>(raw_error_code::corrupt_file, |
David Majnemer | 878cadb | 2016-05-27 15:57:38 +0000 | [diff] [blame] | 118 | "Block size is not multiple of 4."); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 119 | |
Zachary Turner | 9213ba5 | 2016-04-29 18:09:19 +0000 | [diff] [blame] | 120 | switch (SB->BlockSize) { |
| 121 | case 512: case 1024: case 2048: case 4096: |
| 122 | break; |
| 123 | default: |
| 124 | // An invalid block size suggests a corrupt PDB file. |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 125 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 126 | "Unsupported block size."); |
Zachary Turner | 9213ba5 | 2016-04-29 18:09:19 +0000 | [diff] [blame] | 127 | } |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 128 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 129 | if (Buffer->getLength() % SB->BlockSize != 0) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 130 | return make_error<RawError>(raw_error_code::corrupt_file, |
David Majnemer | 878cadb | 2016-05-27 15:57:38 +0000 | [diff] [blame] | 131 | "File size is not a multiple of block size"); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 132 | |
| 133 | // We don't support directories whose sizes aren't a multiple of four bytes. |
| 134 | if (SB->NumDirectoryBytes % sizeof(support::ulittle32_t) != 0) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 135 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 136 | "Directory size is not multiple of 4."); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 137 | |
| 138 | // The number of blocks which comprise the directory is a simple function of |
| 139 | // the number of bytes it contains. |
| 140 | uint64_t NumDirectoryBlocks = getNumDirectoryBlocks(); |
| 141 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 142 | // The directory, as we understand it, is a block which consists of a list of |
| 143 | // block numbers. It is unclear what would happen if the number of blocks |
| 144 | // couldn't fit on a single block. |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 145 | if (NumDirectoryBlocks > SB->BlockSize / sizeof(support::ulittle32_t)) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 146 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 147 | "Too many directory blocks."); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 148 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 149 | return Error::success(); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 152 | Error PDBFile::parseStreamData() { |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 153 | assert(SB); |
Zachary Turner | d844799 | 2016-06-07 05:28:55 +0000 | [diff] [blame] | 154 | if (DirectoryStream) |
| 155 | return Error::success(); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 156 | |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 157 | uint32_t NumStreams = 0; |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 158 | |
Zachary Turner | d844799 | 2016-06-07 05:28:55 +0000 | [diff] [blame] | 159 | // Normally you can't use a MappedBlockStream without having fully parsed the |
| 160 | // PDB file, because it accesses the directory and various other things, which |
| 161 | // is exactly what we are attempting to parse. By specifying a custom |
| 162 | // subclass of IPDBStreamData which only accesses the fields that have already |
| 163 | // been parsed, we can avoid this and reuse MappedBlockStream. |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 164 | auto DS = MappedBlockStream::createDirectoryStream(*this); |
| 165 | if (!DS) |
| 166 | return DS.takeError(); |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 167 | StreamReader Reader(**DS); |
Zachary Turner | d844799 | 2016-06-07 05:28:55 +0000 | [diff] [blame] | 168 | if (auto EC = Reader.readInteger(NumStreams)) |
| 169 | return EC; |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 170 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 171 | if (auto EC = Reader.readArray(StreamSizes, NumStreams)) |
Zachary Turner | d844799 | 2016-06-07 05:28:55 +0000 | [diff] [blame] | 172 | return EC; |
| 173 | for (uint32_t I = 0; I < NumStreams; ++I) { |
David Majnemer | 9efba74 | 2016-05-27 16:16:48 +0000 | [diff] [blame] | 174 | uint64_t NumExpectedStreamBlocks = |
Zachary Turner | d844799 | 2016-06-07 05:28:55 +0000 | [diff] [blame] | 175 | bytesToBlocks(getStreamByteSize(I), SB->BlockSize); |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 176 | |
| 177 | // For convenience, we store the block array contiguously. This is because |
| 178 | // if someone calls setStreamMap(), it is more convenient to be able to call |
| 179 | // it with an ArrayRef instead of setting up a StreamRef. Since the |
| 180 | // DirectoryStream is cached in the class and thus lives for the life of the |
| 181 | // class, we can be guaranteed that readArray() will return a stable |
| 182 | // reference, even if it has to allocate from its internal pool. |
| 183 | ArrayRef<support::ulittle32_t> Blocks; |
Zachary Turner | d844799 | 2016-06-07 05:28:55 +0000 | [diff] [blame] | 184 | if (auto EC = Reader.readArray(Blocks, NumExpectedStreamBlocks)) |
| 185 | return EC; |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 186 | StreamMap.push_back(Blocks); |
David Majnemer | 9efba74 | 2016-05-27 16:16:48 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 189 | // We should have read exactly SB->NumDirectoryBytes bytes. |
Zachary Turner | d844799 | 2016-06-07 05:28:55 +0000 | [diff] [blame] | 190 | assert(Reader.bytesRemaining() == 0); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 191 | DirectoryStream = std::move(*DS); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 192 | return Error::success(); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Zachary Turner | d844799 | 2016-06-07 05:28:55 +0000 | [diff] [blame] | 195 | llvm::ArrayRef<support::ulittle32_t> PDBFile::getDirectoryBlockArray() const { |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 196 | StreamReader Reader(*Buffer); |
| 197 | Reader.setOffset(getBlockMapOffset()); |
| 198 | llvm::ArrayRef<support::ulittle32_t> Result; |
| 199 | if (auto EC = Reader.readArray(Result, getNumDirectoryBlocks())) |
| 200 | consumeError(std::move(EC)); |
| 201 | return Result; |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 202 | } |
Zachary Turner | 53a65ba | 2016-04-26 18:42:34 +0000 | [diff] [blame] | 203 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 204 | Expected<InfoStream &> PDBFile::getPDBInfoStream() { |
Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 205 | if (!Info) { |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 206 | auto InfoS = MappedBlockStream::createIndexedStream(StreamPDB, *this); |
| 207 | if (!InfoS) |
| 208 | return InfoS.takeError(); |
| 209 | auto TempInfo = llvm::make_unique<InfoStream>(std::move(*InfoS)); |
| 210 | if (auto EC = TempInfo->reload()) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 211 | return std::move(EC); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 212 | Info = std::move(TempInfo); |
Zachary Turner | 53a65ba | 2016-04-26 18:42:34 +0000 | [diff] [blame] | 213 | } |
Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 214 | return *Info; |
Zachary Turner | 53a65ba | 2016-04-26 18:42:34 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 217 | Expected<DbiStream &> PDBFile::getPDBDbiStream() { |
Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 218 | if (!Dbi) { |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 219 | auto DbiS = MappedBlockStream::createIndexedStream(StreamDBI, *this); |
| 220 | if (!DbiS) |
| 221 | return DbiS.takeError(); |
| 222 | auto TempDbi = llvm::make_unique<DbiStream>(*this, std::move(*DbiS)); |
| 223 | if (auto EC = TempDbi->reload()) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 224 | return std::move(EC); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 225 | Dbi = std::move(TempDbi); |
Zachary Turner | 53a65ba | 2016-04-26 18:42:34 +0000 | [diff] [blame] | 226 | } |
Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 227 | return *Dbi; |
Zachary Turner | 53a65ba | 2016-04-26 18:42:34 +0000 | [diff] [blame] | 228 | } |
Zachary Turner | f5c5965 | 2016-05-03 00:28:21 +0000 | [diff] [blame] | 229 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 230 | Expected<TpiStream &> PDBFile::getPDBTpiStream() { |
Zachary Turner | f5c5965 | 2016-05-03 00:28:21 +0000 | [diff] [blame] | 231 | if (!Tpi) { |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 232 | auto TpiS = MappedBlockStream::createIndexedStream(StreamTPI, *this); |
| 233 | if (!TpiS) |
| 234 | return TpiS.takeError(); |
| 235 | auto TempTpi = llvm::make_unique<TpiStream>(*this, std::move(*TpiS)); |
| 236 | if (auto EC = TempTpi->reload()) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 237 | return std::move(EC); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 238 | Tpi = std::move(TempTpi); |
Zachary Turner | f5c5965 | 2016-05-03 00:28:21 +0000 | [diff] [blame] | 239 | } |
| 240 | return *Tpi; |
| 241 | } |
Rui Ueyama | 1f6b6e2 | 2016-05-13 21:21:53 +0000 | [diff] [blame] | 242 | |
Zachary Turner | c9972c6 | 2016-05-25 04:35:22 +0000 | [diff] [blame] | 243 | Expected<TpiStream &> PDBFile::getPDBIpiStream() { |
| 244 | if (!Ipi) { |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 245 | auto IpiS = MappedBlockStream::createIndexedStream(StreamIPI, *this); |
| 246 | if (!IpiS) |
| 247 | return IpiS.takeError(); |
| 248 | auto TempIpi = llvm::make_unique<TpiStream>(*this, std::move(*IpiS)); |
| 249 | if (auto EC = TempIpi->reload()) |
Zachary Turner | c9972c6 | 2016-05-25 04:35:22 +0000 | [diff] [blame] | 250 | return std::move(EC); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 251 | Ipi = std::move(TempIpi); |
Zachary Turner | c9972c6 | 2016-05-25 04:35:22 +0000 | [diff] [blame] | 252 | } |
| 253 | return *Ipi; |
| 254 | } |
| 255 | |
Rui Ueyama | 1f6b6e2 | 2016-05-13 21:21:53 +0000 | [diff] [blame] | 256 | Expected<PublicsStream &> PDBFile::getPDBPublicsStream() { |
| 257 | if (!Publics) { |
| 258 | auto DbiS = getPDBDbiStream(); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 259 | if (!DbiS) |
| 260 | return DbiS.takeError(); |
| 261 | |
Rui Ueyama | 1f6b6e2 | 2016-05-13 21:21:53 +0000 | [diff] [blame] | 262 | uint32_t PublicsStreamNum = DbiS->getPublicSymbolStreamIndex(); |
| 263 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 264 | auto PublicS = |
| 265 | MappedBlockStream::createIndexedStream(PublicsStreamNum, *this); |
| 266 | if (!PublicS) |
| 267 | return PublicS.takeError(); |
| 268 | auto TempPublics = |
| 269 | llvm::make_unique<PublicsStream>(*this, std::move(*PublicS)); |
| 270 | if (auto EC = TempPublics->reload()) |
Rui Ueyama | 1f6b6e2 | 2016-05-13 21:21:53 +0000 | [diff] [blame] | 271 | return std::move(EC); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 272 | Publics = std::move(TempPublics); |
Rui Ueyama | 1f6b6e2 | 2016-05-13 21:21:53 +0000 | [diff] [blame] | 273 | } |
| 274 | return *Publics; |
| 275 | } |
Rui Ueyama | 0fcd826 | 2016-05-20 19:55:17 +0000 | [diff] [blame] | 276 | |
| 277 | Expected<SymbolStream &> PDBFile::getPDBSymbolStream() { |
| 278 | if (!Symbols) { |
| 279 | auto DbiS = getPDBDbiStream(); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 280 | if (!DbiS) |
| 281 | return DbiS.takeError(); |
| 282 | |
Rui Ueyama | 0fcd826 | 2016-05-20 19:55:17 +0000 | [diff] [blame] | 283 | uint32_t SymbolStreamNum = DbiS->getSymRecordStreamIndex(); |
| 284 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 285 | auto SymbolS = |
| 286 | MappedBlockStream::createIndexedStream(SymbolStreamNum, *this); |
| 287 | if (!SymbolS) |
| 288 | return SymbolS.takeError(); |
| 289 | auto TempSymbols = llvm::make_unique<SymbolStream>(std::move(*SymbolS)); |
| 290 | if (auto EC = TempSymbols->reload()) |
Rui Ueyama | 0fcd826 | 2016-05-20 19:55:17 +0000 | [diff] [blame] | 291 | return std::move(EC); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 292 | Symbols = std::move(TempSymbols); |
Rui Ueyama | 0fcd826 | 2016-05-20 19:55:17 +0000 | [diff] [blame] | 293 | } |
| 294 | return *Symbols; |
| 295 | } |
Zachary Turner | 3df1bfa | 2016-06-03 05:52:57 +0000 | [diff] [blame] | 296 | |
| 297 | Expected<NameHashTable &> PDBFile::getStringTable() { |
| 298 | if (!StringTable || !StringTableStream) { |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 299 | auto IS = getPDBInfoStream(); |
| 300 | if (!IS) |
| 301 | return IS.takeError(); |
| 302 | |
| 303 | uint32_t NameStreamIndex = IS->getNamedStreamIndex("/names"); |
Zachary Turner | 3df1bfa | 2016-06-03 05:52:57 +0000 | [diff] [blame] | 304 | |
| 305 | if (NameStreamIndex == 0) |
| 306 | return make_error<RawError>(raw_error_code::no_stream); |
Zachary Turner | d2b2bfe | 2016-06-08 00:25:08 +0000 | [diff] [blame] | 307 | if (NameStreamIndex >= getNumStreams()) |
| 308 | return make_error<RawError>(raw_error_code::no_stream); |
| 309 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 310 | auto NS = MappedBlockStream::createIndexedStream(NameStreamIndex, *this); |
| 311 | if (!NS) |
| 312 | return NS.takeError(); |
| 313 | |
Zachary Turner | b84faa8 | 2016-06-10 05:10:19 +0000 | [diff] [blame] | 314 | StreamReader Reader(**NS); |
Zachary Turner | 3df1bfa | 2016-06-03 05:52:57 +0000 | [diff] [blame] | 315 | auto N = llvm::make_unique<NameHashTable>(); |
| 316 | if (auto EC = N->load(Reader)) |
| 317 | return std::move(EC); |
| 318 | StringTable = std::move(N); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 319 | StringTableStream = std::move(*NS); |
Zachary Turner | 3df1bfa | 2016-06-03 05:52:57 +0000 | [diff] [blame] | 320 | } |
| 321 | return *StringTable; |
| 322 | } |
Zachary Turner | 1dc9fd3 | 2016-06-14 20:48:36 +0000 | [diff] [blame^] | 323 | |
| 324 | void PDBFile::setSuperBlock(const SuperBlock *Block) { SB = Block; } |
| 325 | |
| 326 | void PDBFile::setStreamSizes(ArrayRef<support::ulittle32_t> Sizes) { |
| 327 | StreamSizes = Sizes; |
| 328 | } |
| 329 | |
| 330 | void PDBFile::setStreamMap(ArrayRef<ArrayRef<support::ulittle32_t>> Blocks) { |
| 331 | StreamMap = Blocks; |
| 332 | } |
| 333 | |
| 334 | void PDBFile::commit() {} |