mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-03-04 02:18:46 +00:00
[pdb] Have builders share a single BumpPtrAllocator.
This makes it easier to have the writable and readable PDB interfaces share code since the read/write and write-only interfaces now share a single allocator, you don't have to worry about a builder building a read only interface and then having the read-only interface's data become corrupt when the builder goes out of scope. Now the allocator is specified explicitly to all constructors, so all interfaces can share a single allocator that is scoped appropriately. llvm-svn: 276459
This commit is contained in:
parent
de0ff2102f
commit
5565f30e4c
@ -42,7 +42,8 @@ class PDBFile : public msf::IMsfFile {
|
||||
friend PDBFileBuilder;
|
||||
|
||||
public:
|
||||
explicit PDBFile(std::unique_ptr<msf::StreamInterface> PdbFileBuffer);
|
||||
PDBFile(std::unique_ptr<msf::StreamInterface> PdbFileBuffer,
|
||||
BumpPtrAllocator &Allocator);
|
||||
~PDBFile() override;
|
||||
|
||||
uint32_t getFreeBlockMapBlock() const;
|
||||
@ -89,7 +90,7 @@ public:
|
||||
private:
|
||||
Error setSuperBlock(const msf::SuperBlock *Block);
|
||||
|
||||
BumpPtrAllocator Allocator;
|
||||
BumpPtrAllocator &Allocator;
|
||||
|
||||
std::unique_ptr<msf::StreamInterface> Buffer;
|
||||
const msf::SuperBlock *SB;
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "llvm/ADT/BitVector.h"
|
||||
#include "llvm/ADT/Optional.h"
|
||||
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
|
||||
#include "llvm/Support/Allocator.h"
|
||||
#include "llvm/Support/Endian.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
|
||||
@ -28,11 +29,10 @@ class StreamInterface;
|
||||
namespace pdb {
|
||||
class DbiStreamBuilder;
|
||||
class InfoStreamBuilder;
|
||||
class PDBFile;
|
||||
|
||||
class PDBFileBuilder {
|
||||
public:
|
||||
explicit PDBFileBuilder(std::unique_ptr<msf::StreamInterface> FileBuffer);
|
||||
explicit PDBFileBuilder(BumpPtrAllocator &Allocator);
|
||||
PDBFileBuilder(const PDBFileBuilder &) = delete;
|
||||
PDBFileBuilder &operator=(const PDBFileBuilder &) = delete;
|
||||
|
||||
@ -42,14 +42,15 @@ public:
|
||||
InfoStreamBuilder &getInfoBuilder();
|
||||
DbiStreamBuilder &getDbiBuilder();
|
||||
|
||||
Expected<std::unique_ptr<PDBFile>> build();
|
||||
Expected<std::unique_ptr<PDBFile>>
|
||||
build(std::unique_ptr<msf::StreamInterface> PdbFileBuffer);
|
||||
|
||||
private:
|
||||
BumpPtrAllocator &Allocator;
|
||||
|
||||
std::unique_ptr<msf::MsfBuilder> Msf;
|
||||
std::unique_ptr<InfoStreamBuilder> Info;
|
||||
std::unique_ptr<DbiStreamBuilder> Dbi;
|
||||
|
||||
std::unique_ptr<PDBFile> File;
|
||||
std::unique_ptr<msf::MsfBuilder> Msf;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/DebugInfo/PDB/IPDBSession.h"
|
||||
#include "llvm/Support/Allocator.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
|
||||
namespace llvm {
|
||||
@ -20,7 +21,8 @@ class PDBFile;
|
||||
|
||||
class RawSession : public IPDBSession {
|
||||
public:
|
||||
explicit RawSession(std::unique_ptr<PDBFile> PdbFile);
|
||||
RawSession(std::unique_ptr<PDBFile> PdbFile,
|
||||
std::unique_ptr<BumpPtrAllocator> Allocator);
|
||||
~RawSession() override;
|
||||
|
||||
static Error createFromPdb(StringRef Path,
|
||||
@ -68,6 +70,7 @@ public:
|
||||
|
||||
private:
|
||||
std::unique_ptr<PDBFile> Pdb;
|
||||
std::unique_ptr<BumpPtrAllocator> Allocator;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -36,8 +36,9 @@ namespace {
|
||||
typedef FixedStreamArray<support::ulittle32_t> ulittle_array;
|
||||
}
|
||||
|
||||
PDBFile::PDBFile(std::unique_ptr<StreamInterface> PdbFileBuffer)
|
||||
: Buffer(std::move(PdbFileBuffer)), SB(nullptr) {}
|
||||
PDBFile::PDBFile(std::unique_ptr<StreamInterface> PdbFileBuffer,
|
||||
BumpPtrAllocator &Allocator)
|
||||
: Allocator(Allocator), Buffer(std::move(PdbFileBuffer)), SB(nullptr) {}
|
||||
|
||||
PDBFile::~PDBFile() {}
|
||||
|
||||
|
@ -26,12 +26,12 @@ using namespace llvm::msf;
|
||||
using namespace llvm::pdb;
|
||||
using namespace llvm::support;
|
||||
|
||||
PDBFileBuilder::PDBFileBuilder(std::unique_ptr<msf::StreamInterface> FileBuffer)
|
||||
: File(llvm::make_unique<PDBFile>(std::move(FileBuffer))) {}
|
||||
PDBFileBuilder::PDBFileBuilder(BumpPtrAllocator &Allocator)
|
||||
: Allocator(Allocator) {}
|
||||
|
||||
Error PDBFileBuilder::initialize(const msf::SuperBlock &Super) {
|
||||
auto ExpectedMsf =
|
||||
MsfBuilder::create(File->Allocator, Super.BlockSize, Super.NumBlocks);
|
||||
MsfBuilder::create(Allocator, Super.BlockSize, Super.NumBlocks);
|
||||
if (!ExpectedMsf)
|
||||
return ExpectedMsf.takeError();
|
||||
|
||||
@ -54,11 +54,12 @@ InfoStreamBuilder &PDBFileBuilder::getInfoBuilder() {
|
||||
|
||||
DbiStreamBuilder &PDBFileBuilder::getDbiBuilder() {
|
||||
if (!Dbi)
|
||||
Dbi = llvm::make_unique<DbiStreamBuilder>(File->Allocator);
|
||||
Dbi = llvm::make_unique<DbiStreamBuilder>(Allocator);
|
||||
return *Dbi;
|
||||
}
|
||||
|
||||
Expected<std::unique_ptr<PDBFile>> PDBFileBuilder::build() {
|
||||
Expected<std::unique_ptr<PDBFile>>
|
||||
PDBFileBuilder::build(std::unique_ptr<msf::StreamInterface> PdbFileBuffer) {
|
||||
if (Info) {
|
||||
uint32_t Length = Info->calculateSerializedLength();
|
||||
if (auto EC = Msf->setStreamSize(StreamPDB, Length))
|
||||
@ -74,6 +75,7 @@ Expected<std::unique_ptr<PDBFile>> PDBFileBuilder::build() {
|
||||
if (!ExpectedLayout)
|
||||
return ExpectedLayout.takeError();
|
||||
|
||||
auto File = llvm::make_unique<PDBFile>(std::move(PdbFileBuffer), Allocator);
|
||||
const msf::Layout &L = *ExpectedLayout;
|
||||
File->StreamMap = L.StreamMap;
|
||||
File->StreamSizes = L.StreamSizes;
|
||||
|
@ -41,8 +41,9 @@ public:
|
||||
};
|
||||
}
|
||||
|
||||
RawSession::RawSession(std::unique_ptr<PDBFile> PdbFile)
|
||||
: Pdb(std::move(PdbFile)) {}
|
||||
RawSession::RawSession(std::unique_ptr<PDBFile> PdbFile,
|
||||
std::unique_ptr<BumpPtrAllocator> Allocator)
|
||||
: Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)) {}
|
||||
|
||||
RawSession::~RawSession() {}
|
||||
|
||||
@ -58,13 +59,15 @@ Error RawSession::createFromPdb(StringRef Path,
|
||||
std::unique_ptr<MemoryBuffer> Buffer = std::move(*ErrorOrBuffer);
|
||||
auto Stream = llvm::make_unique<InputByteStream>(std::move(Buffer));
|
||||
|
||||
std::unique_ptr<PDBFile> File(new PDBFile(std::move(Stream)));
|
||||
auto Allocator = llvm::make_unique<BumpPtrAllocator>();
|
||||
auto File = llvm::make_unique<PDBFile>(std::move(Stream), *Allocator);
|
||||
if (auto EC = File->parseFileHeaders())
|
||||
return EC;
|
||||
if (auto EC = File->parseStreamData())
|
||||
return EC;
|
||||
|
||||
Session.reset(new RawSession(std::move(File)));
|
||||
Session =
|
||||
llvm::make_unique<RawSession>(std::move(File), std::move(Allocator));
|
||||
|
||||
return Error::success();
|
||||
}
|
||||
|
@ -307,6 +307,7 @@ cl::list<std::string> InputFilename(cl::Positional,
|
||||
static ExitOnError ExitOnErr;
|
||||
|
||||
static void yamlToPdb(StringRef Path) {
|
||||
BumpPtrAllocator Allocator;
|
||||
ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
|
||||
MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
|
||||
/*RequiresNullTerminator=*/false);
|
||||
@ -332,7 +333,7 @@ static void yamlToPdb(StringRef Path) {
|
||||
|
||||
auto FileByteStream =
|
||||
llvm::make_unique<FileBufferByteStream>(std::move(*OutFileOrError));
|
||||
PDBFileBuilder Builder(std::move(FileByteStream));
|
||||
PDBFileBuilder Builder(Allocator);
|
||||
|
||||
ExitOnErr(Builder.initialize(YamlObj.Headers->SuperBlock));
|
||||
ExitOnErr(Builder.getMsfBuilder().setDirectoryBlocksHint(
|
||||
@ -394,7 +395,7 @@ static void yamlToPdb(StringRef Path) {
|
||||
}
|
||||
}
|
||||
|
||||
auto Pdb = Builder.build();
|
||||
auto Pdb = Builder.build(std::move(FileByteStream));
|
||||
ExitOnErr(Pdb.takeError());
|
||||
|
||||
auto &PdbFile = *Pdb;
|
||||
|
Loading…
x
Reference in New Issue
Block a user