diff options
author | Zachary Turner <zturner@google.com> | 2016-07-15 22:16:56 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-07-15 22:16:56 +0000 |
commit | faa554b2fd6c327cb9cc0ac9983bd3c178f2276c (patch) | |
tree | 7cb1be7bc7dfee1244fb8d6767036955aa276875 /llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp | |
parent | 93be6e8c0ada7f77b93db16c81b2160f82780ae6 (diff) | |
download | llvm-faa554b2fd6c327cb9cc0ac9983bd3c178f2276c.zip llvm-faa554b2fd6c327cb9cc0ac9983bd3c178f2276c.tar.gz llvm-faa554b2fd6c327cb9cc0ac9983bd3c178f2276c.tar.bz2 |
[pdb] Use MsfBuilder to handle the writing PDBs.
Previously we would read a PDB, then write some of it back out,
but write the directory, super block, and other pertinent metadata
back out unchanged. This generates incorrect PDBs since the amount
of data written was not always the same as the amount of data read.
This patch changes things to use the newly introduced `MsfBuilder`
class to write out a correct and accurate set of Msf metadata for
the data *actually* written, which opens up the door for adding and
removing type records, symbol records, and other types of data to
an existing PDB.
llvm-svn: 275627
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp | 53 |
1 files changed, 9 insertions, 44 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp index 2aa4d4c..8b09dc5 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp @@ -53,7 +53,7 @@ uint32_t PDBFile::getBlockMapIndex() const { return SB->BlockMapAddr; } uint32_t PDBFile::getUnknown1() const { return SB->Unknown1; } uint32_t PDBFile::getNumDirectoryBlocks() const { - return bytesToBlocks(SB->NumDirectoryBytes, SB->BlockSize); + return msf::bytesToBlocks(SB->NumDirectoryBytes, SB->BlockSize); } uint64_t PDBFile::getBlockMapOffset() const { @@ -75,7 +75,7 @@ uint32_t PDBFile::getFileSize() const { return Buffer->getLength(); } Expected<ArrayRef<uint8_t>> PDBFile::getBlockData(uint32_t BlockIndex, uint32_t NumBytes) const { - uint64_t StreamBlockOffset = blockToOffset(BlockIndex, getBlockSize()); + uint64_t StreamBlockOffset = msf::blockToOffset(BlockIndex, getBlockSize()); ArrayRef<uint8_t> Result; if (auto EC = Buffer->readBytes(StreamBlockOffset, NumBytes, Result)) @@ -94,7 +94,7 @@ Error PDBFile::setBlockData(uint32_t BlockIndex, uint32_t Offset, raw_error_code::invalid_block_address, "setBlockData attempted to write out of block bounds."); - uint64_t StreamBlockOffset = blockToOffset(BlockIndex, getBlockSize()); + uint64_t StreamBlockOffset = msf::blockToOffset(BlockIndex, getBlockSize()); StreamBlockOffset += Offset; return Buffer->writeBytes(StreamBlockOffset, Data); } @@ -143,7 +143,8 @@ Error PDBFile::parseStreamData() { uint32_t StreamSize = getStreamByteSize(I); // FIXME: What does StreamSize ~0U mean? uint64_t NumExpectedStreamBlocks = - StreamSize == UINT32_MAX ? 0 : bytesToBlocks(StreamSize, SB->BlockSize); + StreamSize == UINT32_MAX ? 0 : msf::bytesToBlocks(StreamSize, + SB->BlockSize); // For convenience, we store the block array contiguously. This is because // if someone calls setStreamMap(), it is more convenient to be able to call @@ -293,51 +294,15 @@ Expected<NameHashTable &> PDBFile::getStringTable() { return *StringTable; } -Error PDBFile::setSuperBlock(const SuperBlock *Block) { - SB = Block; - - // Check the magic bytes. - if (memcmp(SB->MagicBytes, MsfMagic, sizeof(MsfMagic)) != 0) - return make_error<RawError>(raw_error_code::corrupt_file, - "MSF magic header doesn't match"); - - // We don't support blocksizes which aren't a multiple of four bytes. - if (SB->BlockSize % sizeof(support::ulittle32_t) != 0) - return make_error<RawError>(raw_error_code::corrupt_file, - "Block size is not multiple of 4."); - - switch (SB->BlockSize) { - case 512: - case 1024: - case 2048: - case 4096: - break; - default: - // An invalid block size suggests a corrupt PDB file. - return make_error<RawError>(raw_error_code::corrupt_file, - "Unsupported block size."); - } +Error PDBFile::setSuperBlock(const msf::SuperBlock *Block) { + if (auto EC = msf::validateSuperBlock(*Block)) + return EC; if (Buffer->getLength() % SB->BlockSize != 0) return make_error<RawError>(raw_error_code::corrupt_file, "File size is not a multiple of block size"); - // We don't support directories whose sizes aren't a multiple of four bytes. - if (SB->NumDirectoryBytes % sizeof(support::ulittle32_t) != 0) - return make_error<RawError>(raw_error_code::corrupt_file, - "Directory size is not multiple of 4."); - - // The number of blocks which comprise the directory is a simple function of - // the number of bytes it contains. - uint64_t NumDirectoryBlocks = getNumDirectoryBlocks(); - - // The directory, as we understand it, is a block which consists of a list of - // block numbers. It is unclear what would happen if the number of blocks - // couldn't fit on a single block. - if (NumDirectoryBlocks > SB->BlockSize / sizeof(support::ulittle32_t)) - return make_error<RawError>(raw_error_code::corrupt_file, - "Too many directory blocks."); - + SB = Block; return Error::success(); } |