2016-04-25 17:38:08 +00:00
|
|
|
//===- PDBFile.cpp - Low level interface to a PDB file ----------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
|
[pdb] Use MappedBlockStream to parse the PDB directory.
In order to efficiently write PDBs, we need to be able to make a
StreamWriter class similar to a StreamReader, which can transparently deal
with writing to discontiguous streams, and we need to use this for all
writing, similar to how we use StreamReader for all reading.
Most discontiguous streams are the typical numbered streams that appear in
a PDB file and are described by the directory, but the exception to this,
that until now has been parsed by hand, is the directory itself.
MappedBlockStream works by querying the directory to find out which blocks
a stream occupies and various other things, so naturally the same logic
could not possibly work to describe the blocks that the directory itself
resided on.
To solve this, I've introduced an abstraction IPDBStreamData, which allows
the client to query for the list of blocks occupied by the stream, as well
as the stream length. I provide two implementations of this: one which
queries the directory (for indexed streams), and one which queries the
super block (for the directory stream).
This has the side benefit of vastly simplifying the code to parse the
directory. Whereas before a mini state machine was rolled by hand, now we
simply use FixedStreamArray to read out the stream sizes, then build a
vector of FixedStreamArrays for the stream map, all in just a few lines of
code.
Reviewed By: ruiu
Differential Revision: http://reviews.llvm.org/D21046
llvm-svn: 271982
2016-06-07 05:28:55 +00:00
|
|
|
|
2016-04-25 17:38:08 +00:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
[pdb] Use MappedBlockStream to parse the PDB directory.
In order to efficiently write PDBs, we need to be able to make a
StreamWriter class similar to a StreamReader, which can transparently deal
with writing to discontiguous streams, and we need to use this for all
writing, similar to how we use StreamReader for all reading.
Most discontiguous streams are the typical numbered streams that appear in
a PDB file and are described by the directory, but the exception to this,
that until now has been parsed by hand, is the directory itself.
MappedBlockStream works by querying the directory to find out which blocks
a stream occupies and various other things, so naturally the same logic
could not possibly work to describe the blocks that the directory itself
resided on.
To solve this, I've introduced an abstraction IPDBStreamData, which allows
the client to query for the list of blocks occupied by the stream, as well
as the stream length. I provide two implementations of this: one which
queries the directory (for indexed streams), and one which queries the
super block (for the directory stream).
This has the side benefit of vastly simplifying the code to parse the
directory. Whereas before a mini state machine was rolled by hand, now we
simply use FixedStreamArray to read out the stream sizes, then build a
vector of FixedStreamArrays for the stream map, all in just a few lines of
code.
Reviewed By: ruiu
Differential Revision: http://reviews.llvm.org/D21046
llvm-svn: 271982
2016-06-07 05:28:55 +00:00
|
|
|
#include "llvm/DebugInfo/CodeView/StreamArray.h"
|
2016-06-10 05:10:19 +00:00
|
|
|
#include "llvm/DebugInfo/CodeView/StreamInterface.h"
|
[pdb] Use MappedBlockStream to parse the PDB directory.
In order to efficiently write PDBs, we need to be able to make a
StreamWriter class similar to a StreamReader, which can transparently deal
with writing to discontiguous streams, and we need to use this for all
writing, similar to how we use StreamReader for all reading.
Most discontiguous streams are the typical numbered streams that appear in
a PDB file and are described by the directory, but the exception to this,
that until now has been parsed by hand, is the directory itself.
MappedBlockStream works by querying the directory to find out which blocks
a stream occupies and various other things, so naturally the same logic
could not possibly work to describe the blocks that the directory itself
resided on.
To solve this, I've introduced an abstraction IPDBStreamData, which allows
the client to query for the list of blocks occupied by the stream, as well
as the stream length. I provide two implementations of this: one which
queries the directory (for indexed streams), and one which queries the
super block (for the directory stream).
This has the side benefit of vastly simplifying the code to parse the
directory. Whereas before a mini state machine was rolled by hand, now we
simply use FixedStreamArray to read out the stream sizes, then build a
vector of FixedStreamArrays for the stream map, all in just a few lines of
code.
Reviewed By: ruiu
Differential Revision: http://reviews.llvm.org/D21046
llvm-svn: 271982
2016-06-07 05:28:55 +00:00
|
|
|
#include "llvm/DebugInfo/CodeView/StreamReader.h"
|
2016-04-29 17:28:47 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Raw/DbiStream.h"
|
2016-06-08 17:26:39 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Raw/DirectoryStreamData.h"
|
[pdb] Use MappedBlockStream to parse the PDB directory.
In order to efficiently write PDBs, we need to be able to make a
StreamWriter class similar to a StreamReader, which can transparently deal
with writing to discontiguous streams, and we need to use this for all
writing, similar to how we use StreamReader for all reading.
Most discontiguous streams are the typical numbered streams that appear in
a PDB file and are described by the directory, but the exception to this,
that until now has been parsed by hand, is the directory itself.
MappedBlockStream works by querying the directory to find out which blocks
a stream occupies and various other things, so naturally the same logic
could not possibly work to describe the blocks that the directory itself
resided on.
To solve this, I've introduced an abstraction IPDBStreamData, which allows
the client to query for the list of blocks occupied by the stream, as well
as the stream length. I provide two implementations of this: one which
queries the directory (for indexed streams), and one which queries the
super block (for the directory stream).
This has the side benefit of vastly simplifying the code to parse the
directory. Whereas before a mini state machine was rolled by hand, now we
simply use FixedStreamArray to read out the stream sizes, then build a
vector of FixedStreamArrays for the stream map, all in just a few lines of
code.
Reviewed By: ruiu
Differential Revision: http://reviews.llvm.org/D21046
llvm-svn: 271982
2016-06-07 05:28:55 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Raw/IndexedStreamData.h"
|
2016-04-29 17:28:47 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Raw/InfoStream.h"
|
2016-06-03 05:52:57 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Raw/NameHashTable.h"
|
2016-05-13 21:21:53 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Raw/PublicsStream.h"
|
2016-05-06 20:51:57 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Raw/RawError.h"
|
2016-05-20 19:55:17 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Raw/SymbolStream.h"
|
2016-05-03 00:28:21 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Raw/TpiStream.h"
|
2016-04-25 17:38:08 +00:00
|
|
|
#include "llvm/Support/Endian.h"
|
2016-06-14 20:48:36 +00:00
|
|
|
#include "llvm/Support/FileOutputBuffer.h"
|
2016-04-25 17:38:08 +00:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
2016-06-10 05:10:19 +00:00
|
|
|
using namespace llvm::codeview;
|
2016-04-29 17:28:47 +00:00
|
|
|
using namespace llvm::pdb;
|
2016-04-25 17:38:08 +00:00
|
|
|
|
|
|
|
namespace {
|
2016-06-10 05:10:19 +00:00
|
|
|
typedef FixedStreamArray<support::ulittle32_t> ulittle_array;
|
2016-04-25 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2016-06-10 05:10:19 +00:00
|
|
|
PDBFile::PDBFile(std::unique_ptr<StreamInterface> PdbFileBuffer)
|
|
|
|
: Buffer(std::move(PdbFileBuffer)), SB(nullptr) {}
|
2016-04-25 17:38:08 +00:00
|
|
|
|
|
|
|
PDBFile::~PDBFile() {}
|
|
|
|
|
2016-06-10 05:10:19 +00:00
|
|
|
uint32_t PDBFile::getBlockSize() const { return SB->BlockSize; }
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2016-06-10 05:10:19 +00:00
|
|
|
uint32_t PDBFile::getUnknown0() const { return SB->Unknown0; }
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2016-06-10 05:10:19 +00:00
|
|
|
uint32_t PDBFile::getBlockCount() const { return SB->NumBlocks; }
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2016-06-10 05:10:19 +00:00
|
|
|
uint32_t PDBFile::getNumDirectoryBytes() const { return SB->NumDirectoryBytes; }
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2016-06-10 05:10:19 +00:00
|
|
|
uint32_t PDBFile::getBlockMapIndex() const { return SB->BlockMapAddr; }
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2016-06-10 05:10:19 +00:00
|
|
|
uint32_t PDBFile::getUnknown1() const { return SB->Unknown1; }
|
2016-04-25 17:38:08 +00:00
|
|
|
|
|
|
|
uint32_t PDBFile::getNumDirectoryBlocks() const {
|
2016-06-10 05:10:19 +00:00
|
|
|
return bytesToBlocks(SB->NumDirectoryBytes, SB->BlockSize);
|
2016-04-25 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t PDBFile::getBlockMapOffset() const {
|
2016-06-10 05:10:19 +00:00
|
|
|
return (uint64_t)SB->BlockMapAddr * SB->BlockSize;
|
2016-04-25 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2016-06-10 05:10:19 +00:00
|
|
|
uint32_t PDBFile::getNumStreams() const { return StreamSizes.size(); }
|
2016-04-25 17:38:08 +00:00
|
|
|
|
|
|
|
uint32_t PDBFile::getStreamByteSize(uint32_t StreamIndex) const {
|
2016-06-10 05:10:19 +00:00
|
|
|
return StreamSizes[StreamIndex];
|
2016-04-25 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
[pdb] Use MappedBlockStream to parse the PDB directory.
In order to efficiently write PDBs, we need to be able to make a
StreamWriter class similar to a StreamReader, which can transparently deal
with writing to discontiguous streams, and we need to use this for all
writing, similar to how we use StreamReader for all reading.
Most discontiguous streams are the typical numbered streams that appear in
a PDB file and are described by the directory, but the exception to this,
that until now has been parsed by hand, is the directory itself.
MappedBlockStream works by querying the directory to find out which blocks
a stream occupies and various other things, so naturally the same logic
could not possibly work to describe the blocks that the directory itself
resided on.
To solve this, I've introduced an abstraction IPDBStreamData, which allows
the client to query for the list of blocks occupied by the stream, as well
as the stream length. I provide two implementations of this: one which
queries the directory (for indexed streams), and one which queries the
super block (for the directory stream).
This has the side benefit of vastly simplifying the code to parse the
directory. Whereas before a mini state machine was rolled by hand, now we
simply use FixedStreamArray to read out the stream sizes, then build a
vector of FixedStreamArrays for the stream map, all in just a few lines of
code.
Reviewed By: ruiu
Differential Revision: http://reviews.llvm.org/D21046
llvm-svn: 271982
2016-06-07 05:28:55 +00:00
|
|
|
ArrayRef<support::ulittle32_t>
|
2016-04-25 17:38:08 +00:00
|
|
|
PDBFile::getStreamBlockList(uint32_t StreamIndex) const {
|
2016-06-10 05:10:19 +00:00
|
|
|
return StreamMap[StreamIndex];
|
2016-04-25 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2016-06-14 20:48:36 +00:00
|
|
|
size_t PDBFile::getFileSize() const { return Buffer->getLength(); }
|
|
|
|
|
2016-06-07 20:38:37 +00:00
|
|
|
ArrayRef<uint8_t> PDBFile::getBlockData(uint32_t BlockIndex,
|
|
|
|
uint32_t NumBytes) const {
|
2016-04-25 17:38:08 +00:00
|
|
|
uint64_t StreamBlockOffset = blockToOffset(BlockIndex, getBlockSize());
|
|
|
|
|
2016-06-10 05:10:19 +00:00
|
|
|
ArrayRef<uint8_t> Result;
|
|
|
|
if (auto EC = Buffer->readBytes(StreamBlockOffset, NumBytes, Result))
|
|
|
|
consumeError(std::move(EC));
|
|
|
|
return Result;
|
2016-04-25 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2016-06-10 05:09:12 +00:00
|
|
|
Error PDBFile::setBlockData(uint32_t BlockIndex, uint32_t Offset,
|
|
|
|
ArrayRef<uint8_t> Data) const {
|
2016-06-10 05:10:19 +00:00
|
|
|
if (Offset >= getBlockSize())
|
|
|
|
return make_error<RawError>(
|
|
|
|
raw_error_code::invalid_block_address,
|
|
|
|
"setBlockData attempted to write out of block bounds.");
|
|
|
|
if (Data.size() >= getBlockSize() - Offset)
|
|
|
|
return make_error<RawError>(
|
|
|
|
raw_error_code::invalid_block_address,
|
|
|
|
"setBlockData attempted to write out of block bounds.");
|
2016-06-10 05:09:12 +00:00
|
|
|
|
2016-06-10 05:10:19 +00:00
|
|
|
uint64_t StreamBlockOffset = blockToOffset(BlockIndex, getBlockSize());
|
|
|
|
StreamBlockOffset += Offset;
|
|
|
|
return Buffer->writeBytes(StreamBlockOffset, Data);
|
2016-06-10 05:09:12 +00:00
|
|
|
}
|
|
|
|
|
2016-05-06 20:51:57 +00:00
|
|
|
Error PDBFile::parseFileHeaders() {
|
2016-06-10 05:10:19 +00:00
|
|
|
StreamReader Reader(*Buffer);
|
2016-05-25 03:53:16 +00:00
|
|
|
|
2016-06-10 05:10:19 +00:00
|
|
|
if (auto EC = Reader.readObject(SB)) {
|
|
|
|
consumeError(std::move(EC));
|
2016-05-06 20:51:57 +00:00
|
|
|
return make_error<RawError>(raw_error_code::corrupt_file,
|
|
|
|
"Does not contain superblock");
|
2016-06-10 05:10:19 +00:00
|
|
|
}
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2016-05-06 20:51:57 +00:00
|
|
|
// Check the magic bytes.
|
2016-06-10 05:10:19 +00:00
|
|
|
if (memcmp(SB->MagicBytes, MsfMagic, sizeof(MsfMagic)) != 0)
|
2016-05-06 20:51:57 +00:00
|
|
|
return make_error<RawError>(raw_error_code::corrupt_file,
|
|
|
|
"MSF magic header doesn't match");
|
|
|
|
|
2016-05-27 15:57:38 +00:00
|
|
|
// We don't support blocksizes which aren't a multiple of four bytes.
|
|
|
|
if (SB->BlockSize % sizeof(support::ulittle32_t) != 0)
|
2016-05-06 20:51:57 +00:00
|
|
|
return make_error<RawError>(raw_error_code::corrupt_file,
|
2016-05-27 15:57:38 +00:00
|
|
|
"Block size is not multiple of 4.");
|
2016-05-06 20:51:57 +00:00
|
|
|
|
2016-04-29 18:09:19 +00:00
|
|
|
switch (SB->BlockSize) {
|
|
|
|
case 512: case 1024: case 2048: case 4096:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// An invalid block size suggests a corrupt PDB file.
|
2016-05-06 20:51:57 +00:00
|
|
|
return make_error<RawError>(raw_error_code::corrupt_file,
|
|
|
|
"Unsupported block size.");
|
2016-04-29 18:09:19 +00:00
|
|
|
}
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2016-06-10 05:10:19 +00:00
|
|
|
if (Buffer->getLength() % SB->BlockSize != 0)
|
2016-05-06 20:51:57 +00:00
|
|
|
return make_error<RawError>(raw_error_code::corrupt_file,
|
2016-05-27 15:57:38 +00:00
|
|
|
"File size is not a multiple of block size");
|
2016-04-25 17:38:08 +00:00
|
|
|
|
|
|
|
// We don't support directories whose sizes aren't a multiple of four bytes.
|
|
|
|
if (SB->NumDirectoryBytes % sizeof(support::ulittle32_t) != 0)
|
2016-05-06 20:51:57 +00:00
|
|
|
return make_error<RawError>(raw_error_code::corrupt_file,
|
|
|
|
"Directory size is not multiple of 4.");
|
2016-04-25 17:38:08 +00:00
|
|
|
|
|
|
|
// The number of blocks which comprise the directory is a simple function of
|
|
|
|
// the number of bytes it contains.
|
|
|
|
uint64_t NumDirectoryBlocks = getNumDirectoryBlocks();
|
|
|
|
|
2016-06-10 05:10:19 +00:00
|
|
|
// 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.
|
2016-04-25 17:38:08 +00:00
|
|
|
if (NumDirectoryBlocks > SB->BlockSize / sizeof(support::ulittle32_t))
|
2016-05-06 20:51:57 +00:00
|
|
|
return make_error<RawError>(raw_error_code::corrupt_file,
|
|
|
|
"Too many directory blocks.");
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2016-05-06 20:51:57 +00:00
|
|
|
return Error::success();
|
2016-04-25 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2016-05-06 20:51:57 +00:00
|
|
|
Error PDBFile::parseStreamData() {
|
2016-06-10 05:10:19 +00:00
|
|
|
assert(SB);
|
[pdb] Use MappedBlockStream to parse the PDB directory.
In order to efficiently write PDBs, we need to be able to make a
StreamWriter class similar to a StreamReader, which can transparently deal
with writing to discontiguous streams, and we need to use this for all
writing, similar to how we use StreamReader for all reading.
Most discontiguous streams are the typical numbered streams that appear in
a PDB file and are described by the directory, but the exception to this,
that until now has been parsed by hand, is the directory itself.
MappedBlockStream works by querying the directory to find out which blocks
a stream occupies and various other things, so naturally the same logic
could not possibly work to describe the blocks that the directory itself
resided on.
To solve this, I've introduced an abstraction IPDBStreamData, which allows
the client to query for the list of blocks occupied by the stream, as well
as the stream length. I provide two implementations of this: one which
queries the directory (for indexed streams), and one which queries the
super block (for the directory stream).
This has the side benefit of vastly simplifying the code to parse the
directory. Whereas before a mini state machine was rolled by hand, now we
simply use FixedStreamArray to read out the stream sizes, then build a
vector of FixedStreamArrays for the stream map, all in just a few lines of
code.
Reviewed By: ruiu
Differential Revision: http://reviews.llvm.org/D21046
llvm-svn: 271982
2016-06-07 05:28:55 +00:00
|
|
|
if (DirectoryStream)
|
|
|
|
return Error::success();
|
2016-04-25 17:38:08 +00:00
|
|
|
|
|
|
|
uint32_t NumStreams = 0;
|
|
|
|
|
[pdb] Use MappedBlockStream to parse the PDB directory.
In order to efficiently write PDBs, we need to be able to make a
StreamWriter class similar to a StreamReader, which can transparently deal
with writing to discontiguous streams, and we need to use this for all
writing, similar to how we use StreamReader for all reading.
Most discontiguous streams are the typical numbered streams that appear in
a PDB file and are described by the directory, but the exception to this,
that until now has been parsed by hand, is the directory itself.
MappedBlockStream works by querying the directory to find out which blocks
a stream occupies and various other things, so naturally the same logic
could not possibly work to describe the blocks that the directory itself
resided on.
To solve this, I've introduced an abstraction IPDBStreamData, which allows
the client to query for the list of blocks occupied by the stream, as well
as the stream length. I provide two implementations of this: one which
queries the directory (for indexed streams), and one which queries the
super block (for the directory stream).
This has the side benefit of vastly simplifying the code to parse the
directory. Whereas before a mini state machine was rolled by hand, now we
simply use FixedStreamArray to read out the stream sizes, then build a
vector of FixedStreamArrays for the stream map, all in just a few lines of
code.
Reviewed By: ruiu
Differential Revision: http://reviews.llvm.org/D21046
llvm-svn: 271982
2016-06-07 05:28:55 +00:00
|
|
|
// Normally you can't use a MappedBlockStream without having fully parsed the
|
|
|
|
// PDB file, because it accesses the directory and various other things, which
|
|
|
|
// is exactly what we are attempting to parse. By specifying a custom
|
|
|
|
// subclass of IPDBStreamData which only accesses the fields that have already
|
|
|
|
// been parsed, we can avoid this and reuse MappedBlockStream.
|
2016-06-08 17:26:39 +00:00
|
|
|
auto DS = MappedBlockStream::createDirectoryStream(*this);
|
|
|
|
if (!DS)
|
|
|
|
return DS.takeError();
|
2016-06-10 05:10:19 +00:00
|
|
|
StreamReader Reader(**DS);
|
[pdb] Use MappedBlockStream to parse the PDB directory.
In order to efficiently write PDBs, we need to be able to make a
StreamWriter class similar to a StreamReader, which can transparently deal
with writing to discontiguous streams, and we need to use this for all
writing, similar to how we use StreamReader for all reading.
Most discontiguous streams are the typical numbered streams that appear in
a PDB file and are described by the directory, but the exception to this,
that until now has been parsed by hand, is the directory itself.
MappedBlockStream works by querying the directory to find out which blocks
a stream occupies and various other things, so naturally the same logic
could not possibly work to describe the blocks that the directory itself
resided on.
To solve this, I've introduced an abstraction IPDBStreamData, which allows
the client to query for the list of blocks occupied by the stream, as well
as the stream length. I provide two implementations of this: one which
queries the directory (for indexed streams), and one which queries the
super block (for the directory stream).
This has the side benefit of vastly simplifying the code to parse the
directory. Whereas before a mini state machine was rolled by hand, now we
simply use FixedStreamArray to read out the stream sizes, then build a
vector of FixedStreamArrays for the stream map, all in just a few lines of
code.
Reviewed By: ruiu
Differential Revision: http://reviews.llvm.org/D21046
llvm-svn: 271982
2016-06-07 05:28:55 +00:00
|
|
|
if (auto EC = Reader.readInteger(NumStreams))
|
|
|
|
return EC;
|
2016-05-28 05:59:19 +00:00
|
|
|
|
2016-06-10 05:10:19 +00:00
|
|
|
if (auto EC = Reader.readArray(StreamSizes, NumStreams))
|
[pdb] Use MappedBlockStream to parse the PDB directory.
In order to efficiently write PDBs, we need to be able to make a
StreamWriter class similar to a StreamReader, which can transparently deal
with writing to discontiguous streams, and we need to use this for all
writing, similar to how we use StreamReader for all reading.
Most discontiguous streams are the typical numbered streams that appear in
a PDB file and are described by the directory, but the exception to this,
that until now has been parsed by hand, is the directory itself.
MappedBlockStream works by querying the directory to find out which blocks
a stream occupies and various other things, so naturally the same logic
could not possibly work to describe the blocks that the directory itself
resided on.
To solve this, I've introduced an abstraction IPDBStreamData, which allows
the client to query for the list of blocks occupied by the stream, as well
as the stream length. I provide two implementations of this: one which
queries the directory (for indexed streams), and one which queries the
super block (for the directory stream).
This has the side benefit of vastly simplifying the code to parse the
directory. Whereas before a mini state machine was rolled by hand, now we
simply use FixedStreamArray to read out the stream sizes, then build a
vector of FixedStreamArrays for the stream map, all in just a few lines of
code.
Reviewed By: ruiu
Differential Revision: http://reviews.llvm.org/D21046
llvm-svn: 271982
2016-06-07 05:28:55 +00:00
|
|
|
return EC;
|
|
|
|
for (uint32_t I = 0; I < NumStreams; ++I) {
|
2016-05-27 16:16:48 +00:00
|
|
|
uint64_t NumExpectedStreamBlocks =
|
[pdb] Use MappedBlockStream to parse the PDB directory.
In order to efficiently write PDBs, we need to be able to make a
StreamWriter class similar to a StreamReader, which can transparently deal
with writing to discontiguous streams, and we need to use this for all
writing, similar to how we use StreamReader for all reading.
Most discontiguous streams are the typical numbered streams that appear in
a PDB file and are described by the directory, but the exception to this,
that until now has been parsed by hand, is the directory itself.
MappedBlockStream works by querying the directory to find out which blocks
a stream occupies and various other things, so naturally the same logic
could not possibly work to describe the blocks that the directory itself
resided on.
To solve this, I've introduced an abstraction IPDBStreamData, which allows
the client to query for the list of blocks occupied by the stream, as well
as the stream length. I provide two implementations of this: one which
queries the directory (for indexed streams), and one which queries the
super block (for the directory stream).
This has the side benefit of vastly simplifying the code to parse the
directory. Whereas before a mini state machine was rolled by hand, now we
simply use FixedStreamArray to read out the stream sizes, then build a
vector of FixedStreamArrays for the stream map, all in just a few lines of
code.
Reviewed By: ruiu
Differential Revision: http://reviews.llvm.org/D21046
llvm-svn: 271982
2016-06-07 05:28:55 +00:00
|
|
|
bytesToBlocks(getStreamByteSize(I), SB->BlockSize);
|
2016-06-10 05:10:19 +00:00
|
|
|
|
|
|
|
// For convenience, we store the block array contiguously. This is because
|
|
|
|
// if someone calls setStreamMap(), it is more convenient to be able to call
|
|
|
|
// it with an ArrayRef instead of setting up a StreamRef. Since the
|
|
|
|
// DirectoryStream is cached in the class and thus lives for the life of the
|
|
|
|
// class, we can be guaranteed that readArray() will return a stable
|
|
|
|
// reference, even if it has to allocate from its internal pool.
|
|
|
|
ArrayRef<support::ulittle32_t> Blocks;
|
[pdb] Use MappedBlockStream to parse the PDB directory.
In order to efficiently write PDBs, we need to be able to make a
StreamWriter class similar to a StreamReader, which can transparently deal
with writing to discontiguous streams, and we need to use this for all
writing, similar to how we use StreamReader for all reading.
Most discontiguous streams are the typical numbered streams that appear in
a PDB file and are described by the directory, but the exception to this,
that until now has been parsed by hand, is the directory itself.
MappedBlockStream works by querying the directory to find out which blocks
a stream occupies and various other things, so naturally the same logic
could not possibly work to describe the blocks that the directory itself
resided on.
To solve this, I've introduced an abstraction IPDBStreamData, which allows
the client to query for the list of blocks occupied by the stream, as well
as the stream length. I provide two implementations of this: one which
queries the directory (for indexed streams), and one which queries the
super block (for the directory stream).
This has the side benefit of vastly simplifying the code to parse the
directory. Whereas before a mini state machine was rolled by hand, now we
simply use FixedStreamArray to read out the stream sizes, then build a
vector of FixedStreamArrays for the stream map, all in just a few lines of
code.
Reviewed By: ruiu
Differential Revision: http://reviews.llvm.org/D21046
llvm-svn: 271982
2016-06-07 05:28:55 +00:00
|
|
|
if (auto EC = Reader.readArray(Blocks, NumExpectedStreamBlocks))
|
|
|
|
return EC;
|
2016-06-10 05:10:19 +00:00
|
|
|
StreamMap.push_back(Blocks);
|
2016-05-27 16:16:48 +00:00
|
|
|
}
|
|
|
|
|
2016-04-25 17:38:08 +00:00
|
|
|
// We should have read exactly SB->NumDirectoryBytes bytes.
|
[pdb] Use MappedBlockStream to parse the PDB directory.
In order to efficiently write PDBs, we need to be able to make a
StreamWriter class similar to a StreamReader, which can transparently deal
with writing to discontiguous streams, and we need to use this for all
writing, similar to how we use StreamReader for all reading.
Most discontiguous streams are the typical numbered streams that appear in
a PDB file and are described by the directory, but the exception to this,
that until now has been parsed by hand, is the directory itself.
MappedBlockStream works by querying the directory to find out which blocks
a stream occupies and various other things, so naturally the same logic
could not possibly work to describe the blocks that the directory itself
resided on.
To solve this, I've introduced an abstraction IPDBStreamData, which allows
the client to query for the list of blocks occupied by the stream, as well
as the stream length. I provide two implementations of this: one which
queries the directory (for indexed streams), and one which queries the
super block (for the directory stream).
This has the side benefit of vastly simplifying the code to parse the
directory. Whereas before a mini state machine was rolled by hand, now we
simply use FixedStreamArray to read out the stream sizes, then build a
vector of FixedStreamArrays for the stream map, all in just a few lines of
code.
Reviewed By: ruiu
Differential Revision: http://reviews.llvm.org/D21046
llvm-svn: 271982
2016-06-07 05:28:55 +00:00
|
|
|
assert(Reader.bytesRemaining() == 0);
|
2016-06-08 17:26:39 +00:00
|
|
|
DirectoryStream = std::move(*DS);
|
2016-05-06 20:51:57 +00:00
|
|
|
return Error::success();
|
2016-04-25 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
[pdb] Use MappedBlockStream to parse the PDB directory.
In order to efficiently write PDBs, we need to be able to make a
StreamWriter class similar to a StreamReader, which can transparently deal
with writing to discontiguous streams, and we need to use this for all
writing, similar to how we use StreamReader for all reading.
Most discontiguous streams are the typical numbered streams that appear in
a PDB file and are described by the directory, but the exception to this,
that until now has been parsed by hand, is the directory itself.
MappedBlockStream works by querying the directory to find out which blocks
a stream occupies and various other things, so naturally the same logic
could not possibly work to describe the blocks that the directory itself
resided on.
To solve this, I've introduced an abstraction IPDBStreamData, which allows
the client to query for the list of blocks occupied by the stream, as well
as the stream length. I provide two implementations of this: one which
queries the directory (for indexed streams), and one which queries the
super block (for the directory stream).
This has the side benefit of vastly simplifying the code to parse the
directory. Whereas before a mini state machine was rolled by hand, now we
simply use FixedStreamArray to read out the stream sizes, then build a
vector of FixedStreamArrays for the stream map, all in just a few lines of
code.
Reviewed By: ruiu
Differential Revision: http://reviews.llvm.org/D21046
llvm-svn: 271982
2016-06-07 05:28:55 +00:00
|
|
|
llvm::ArrayRef<support::ulittle32_t> PDBFile::getDirectoryBlockArray() const {
|
2016-06-10 05:10:19 +00:00
|
|
|
StreamReader Reader(*Buffer);
|
|
|
|
Reader.setOffset(getBlockMapOffset());
|
|
|
|
llvm::ArrayRef<support::ulittle32_t> Result;
|
|
|
|
if (auto EC = Reader.readArray(Result, getNumDirectoryBlocks()))
|
|
|
|
consumeError(std::move(EC));
|
|
|
|
return Result;
|
2016-04-25 17:38:08 +00:00
|
|
|
}
|
2016-04-26 18:42:34 +00:00
|
|
|
|
2016-05-06 20:51:57 +00:00
|
|
|
Expected<InfoStream &> PDBFile::getPDBInfoStream() {
|
2016-04-29 17:28:47 +00:00
|
|
|
if (!Info) {
|
2016-06-08 17:26:39 +00:00
|
|
|
auto InfoS = MappedBlockStream::createIndexedStream(StreamPDB, *this);
|
|
|
|
if (!InfoS)
|
|
|
|
return InfoS.takeError();
|
|
|
|
auto TempInfo = llvm::make_unique<InfoStream>(std::move(*InfoS));
|
|
|
|
if (auto EC = TempInfo->reload())
|
2016-05-06 20:51:57 +00:00
|
|
|
return std::move(EC);
|
2016-06-08 17:26:39 +00:00
|
|
|
Info = std::move(TempInfo);
|
2016-04-26 18:42:34 +00:00
|
|
|
}
|
2016-04-29 17:28:47 +00:00
|
|
|
return *Info;
|
2016-04-26 18:42:34 +00:00
|
|
|
}
|
|
|
|
|
2016-05-06 20:51:57 +00:00
|
|
|
Expected<DbiStream &> PDBFile::getPDBDbiStream() {
|
2016-04-29 17:28:47 +00:00
|
|
|
if (!Dbi) {
|
2016-06-08 17:26:39 +00:00
|
|
|
auto DbiS = MappedBlockStream::createIndexedStream(StreamDBI, *this);
|
|
|
|
if (!DbiS)
|
|
|
|
return DbiS.takeError();
|
|
|
|
auto TempDbi = llvm::make_unique<DbiStream>(*this, std::move(*DbiS));
|
|
|
|
if (auto EC = TempDbi->reload())
|
2016-05-06 20:51:57 +00:00
|
|
|
return std::move(EC);
|
2016-06-08 17:26:39 +00:00
|
|
|
Dbi = std::move(TempDbi);
|
2016-04-26 18:42:34 +00:00
|
|
|
}
|
2016-04-29 17:28:47 +00:00
|
|
|
return *Dbi;
|
2016-04-26 18:42:34 +00:00
|
|
|
}
|
2016-05-03 00:28:21 +00:00
|
|
|
|
2016-05-06 20:51:57 +00:00
|
|
|
Expected<TpiStream &> PDBFile::getPDBTpiStream() {
|
2016-05-03 00:28:21 +00:00
|
|
|
if (!Tpi) {
|
2016-06-08 17:26:39 +00:00
|
|
|
auto TpiS = MappedBlockStream::createIndexedStream(StreamTPI, *this);
|
|
|
|
if (!TpiS)
|
|
|
|
return TpiS.takeError();
|
|
|
|
auto TempTpi = llvm::make_unique<TpiStream>(*this, std::move(*TpiS));
|
|
|
|
if (auto EC = TempTpi->reload())
|
2016-05-06 20:51:57 +00:00
|
|
|
return std::move(EC);
|
2016-06-08 17:26:39 +00:00
|
|
|
Tpi = std::move(TempTpi);
|
2016-05-03 00:28:21 +00:00
|
|
|
}
|
|
|
|
return *Tpi;
|
|
|
|
}
|
2016-05-13 21:21:53 +00:00
|
|
|
|
2016-05-25 04:35:22 +00:00
|
|
|
Expected<TpiStream &> PDBFile::getPDBIpiStream() {
|
|
|
|
if (!Ipi) {
|
2016-06-08 17:26:39 +00:00
|
|
|
auto IpiS = MappedBlockStream::createIndexedStream(StreamIPI, *this);
|
|
|
|
if (!IpiS)
|
|
|
|
return IpiS.takeError();
|
|
|
|
auto TempIpi = llvm::make_unique<TpiStream>(*this, std::move(*IpiS));
|
|
|
|
if (auto EC = TempIpi->reload())
|
2016-05-25 04:35:22 +00:00
|
|
|
return std::move(EC);
|
2016-06-08 17:26:39 +00:00
|
|
|
Ipi = std::move(TempIpi);
|
2016-05-25 04:35:22 +00:00
|
|
|
}
|
|
|
|
return *Ipi;
|
|
|
|
}
|
|
|
|
|
2016-05-13 21:21:53 +00:00
|
|
|
Expected<PublicsStream &> PDBFile::getPDBPublicsStream() {
|
|
|
|
if (!Publics) {
|
|
|
|
auto DbiS = getPDBDbiStream();
|
2016-06-08 17:26:39 +00:00
|
|
|
if (!DbiS)
|
|
|
|
return DbiS.takeError();
|
|
|
|
|
2016-05-13 21:21:53 +00:00
|
|
|
uint32_t PublicsStreamNum = DbiS->getPublicSymbolStreamIndex();
|
|
|
|
|
2016-06-08 17:26:39 +00:00
|
|
|
auto PublicS =
|
|
|
|
MappedBlockStream::createIndexedStream(PublicsStreamNum, *this);
|
|
|
|
if (!PublicS)
|
|
|
|
return PublicS.takeError();
|
|
|
|
auto TempPublics =
|
|
|
|
llvm::make_unique<PublicsStream>(*this, std::move(*PublicS));
|
|
|
|
if (auto EC = TempPublics->reload())
|
2016-05-13 21:21:53 +00:00
|
|
|
return std::move(EC);
|
2016-06-08 17:26:39 +00:00
|
|
|
Publics = std::move(TempPublics);
|
2016-05-13 21:21:53 +00:00
|
|
|
}
|
|
|
|
return *Publics;
|
|
|
|
}
|
2016-05-20 19:55:17 +00:00
|
|
|
|
|
|
|
Expected<SymbolStream &> PDBFile::getPDBSymbolStream() {
|
|
|
|
if (!Symbols) {
|
|
|
|
auto DbiS = getPDBDbiStream();
|
2016-06-08 17:26:39 +00:00
|
|
|
if (!DbiS)
|
|
|
|
return DbiS.takeError();
|
|
|
|
|
2016-05-20 19:55:17 +00:00
|
|
|
uint32_t SymbolStreamNum = DbiS->getSymRecordStreamIndex();
|
|
|
|
|
2016-06-08 17:26:39 +00:00
|
|
|
auto SymbolS =
|
|
|
|
MappedBlockStream::createIndexedStream(SymbolStreamNum, *this);
|
|
|
|
if (!SymbolS)
|
|
|
|
return SymbolS.takeError();
|
|
|
|
auto TempSymbols = llvm::make_unique<SymbolStream>(std::move(*SymbolS));
|
|
|
|
if (auto EC = TempSymbols->reload())
|
2016-05-20 19:55:17 +00:00
|
|
|
return std::move(EC);
|
2016-06-08 17:26:39 +00:00
|
|
|
Symbols = std::move(TempSymbols);
|
2016-05-20 19:55:17 +00:00
|
|
|
}
|
|
|
|
return *Symbols;
|
|
|
|
}
|
2016-06-03 05:52:57 +00:00
|
|
|
|
|
|
|
Expected<NameHashTable &> PDBFile::getStringTable() {
|
|
|
|
if (!StringTable || !StringTableStream) {
|
2016-06-08 17:26:39 +00:00
|
|
|
auto IS = getPDBInfoStream();
|
|
|
|
if (!IS)
|
|
|
|
return IS.takeError();
|
|
|
|
|
|
|
|
uint32_t NameStreamIndex = IS->getNamedStreamIndex("/names");
|
2016-06-03 05:52:57 +00:00
|
|
|
|
|
|
|
if (NameStreamIndex == 0)
|
|
|
|
return make_error<RawError>(raw_error_code::no_stream);
|
2016-06-08 00:25:08 +00:00
|
|
|
if (NameStreamIndex >= getNumStreams())
|
|
|
|
return make_error<RawError>(raw_error_code::no_stream);
|
|
|
|
|
2016-06-08 17:26:39 +00:00
|
|
|
auto NS = MappedBlockStream::createIndexedStream(NameStreamIndex, *this);
|
|
|
|
if (!NS)
|
|
|
|
return NS.takeError();
|
|
|
|
|
2016-06-10 05:10:19 +00:00
|
|
|
StreamReader Reader(**NS);
|
2016-06-03 05:52:57 +00:00
|
|
|
auto N = llvm::make_unique<NameHashTable>();
|
|
|
|
if (auto EC = N->load(Reader))
|
|
|
|
return std::move(EC);
|
|
|
|
StringTable = std::move(N);
|
2016-06-08 17:26:39 +00:00
|
|
|
StringTableStream = std::move(*NS);
|
2016-06-03 05:52:57 +00:00
|
|
|
}
|
|
|
|
return *StringTable;
|
|
|
|
}
|
2016-06-14 20:48:36 +00:00
|
|
|
|
|
|
|
void PDBFile::setSuperBlock(const SuperBlock *Block) { SB = Block; }
|
|
|
|
|
|
|
|
void PDBFile::setStreamSizes(ArrayRef<support::ulittle32_t> Sizes) {
|
|
|
|
StreamSizes = Sizes;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PDBFile::setStreamMap(ArrayRef<ArrayRef<support::ulittle32_t>> Blocks) {
|
|
|
|
StreamMap = Blocks;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PDBFile::commit() {}
|