diff options
author | Zachary Turner <zturner@google.com> | 2016-06-08 17:26:39 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-06-08 17:26:39 +0000 |
commit | a1657a9e64c1e8df34e32ca69fac918a7d28c60a (patch) | |
tree | 74993d26964f0f2f28bed1a30e85b19401a2f34e /llvm/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp | |
parent | ced0853b468dadcf50ad5dae68017e3cd9c86bda (diff) | |
download | bcm5719-llvm-a1657a9e64c1e8df34e32ca69fac918a7d28c60a.tar.gz bcm5719-llvm-a1657a9e64c1e8df34e32ca69fac918a7d28c60a.zip |
[pdb] Handle stream index errors better.
Reviewed By: ruiu
Differential Revision: http://reviews.llvm.org/D21128
llvm-svn: 272172
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp index 3428ff83471..cae33768af6 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp @@ -8,13 +8,27 @@ //===----------------------------------------------------------------------===// #include "llvm/DebugInfo/PDB/Raw/MappedBlockStream.h" +#include "llvm/DebugInfo/PDB/Raw/DirectoryStreamData.h" #include "llvm/DebugInfo/PDB/Raw/IPDBStreamData.h" +#include "llvm/DebugInfo/PDB/Raw/IndexedStreamData.h" #include "llvm/DebugInfo/PDB/Raw/PDBFile.h" #include "llvm/DebugInfo/PDB/Raw/RawError.h" using namespace llvm; using namespace llvm::pdb; +namespace { +// This exists so that we can use make_unique while still keeping the +// constructor of MappedBlockStream private, forcing users to go through +// the `create` interface. +class MappedBlockStreamImpl : public MappedBlockStream { +public: + MappedBlockStreamImpl(std::unique_ptr<IPDBStreamData> Data, + const IPDBFile &File) + : MappedBlockStream(std::move(Data), File) {} +}; +} + MappedBlockStream::MappedBlockStream(std::unique_ptr<IPDBStreamData> Data, const IPDBFile &Pdb) : Pdb(Pdb), Data(std::move(Data)) {} @@ -122,3 +136,19 @@ Error MappedBlockStream::readBytes(uint32_t Offset, uint32_t MappedBlockStream::getNumBytesCopied() const { return static_cast<uint32_t>(Pool.getBytesAllocated()); } + +Expected<std::unique_ptr<MappedBlockStream>> +MappedBlockStream::createIndexedStream(uint32_t StreamIdx, + const IPDBFile &File) { + if (StreamIdx >= File.getNumStreams()) + return make_error<RawError>(raw_error_code::no_stream); + + auto Data = llvm::make_unique<IndexedStreamData>(StreamIdx, File); + return llvm::make_unique<MappedBlockStreamImpl>(std::move(Data), File); +} + +Expected<std::unique_ptr<MappedBlockStream>> +MappedBlockStream::createDirectoryStream(const PDBFile &File) { + auto Data = llvm::make_unique<DirectoryStreamData>(File); + return llvm::make_unique<MappedBlockStreamImpl>(std::move(Data), File); +} |