From: Rui Ueyama Date: Fri, 30 Sep 2016 20:34:44 +0000 (+0000) Subject: Pass a filename instead of a msf::WritableStream to PDBFileBuilder::commit. X-Git-Tag: llvmorg-4.0.0-rc1~8421 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fc22cef98ed96ac3aa471b66315ebc54e3421762;p=platform%2Fupstream%2Fllvm.git Pass a filename instead of a msf::WritableStream to PDBFileBuilder::commit. WritableStream needs the exact file size to open a file, but until we fix the final layout of a PDB file, we don't know the size of the file. This patch changes the parameter type of PDBFileBuilder::commit to solve that chiecken-and-egg problem. Now the function opens a file after fixing the layout, so it can create a file with the exact size. Differential Revision: https://reviews.llvm.org/D25107 llvm-svn: 282940 --- diff --git a/llvm/include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h b/llvm/include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h index 52170a4..843ea97 100644 --- a/llvm/include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h +++ b/llvm/include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h @@ -47,7 +47,7 @@ public: Expected> build(std::unique_ptr PdbFileBuffer); - Error commit(const msf::WritableStream &Buffer); + Error commit(StringRef Filename); private: Expected finalizeMsfLayout() const; diff --git a/llvm/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp b/llvm/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp index 165b03c..5b9f946 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp @@ -14,6 +14,7 @@ #include "llvm/DebugInfo/MSF/MSFBuilder.h" #include "llvm/DebugInfo/MSF/StreamInterface.h" #include "llvm/DebugInfo/MSF/StreamWriter.h" +#include "llvm/DebugInfo/PDB/GenericError.h" #include "llvm/DebugInfo/PDB/Raw/DbiStream.h" #include "llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h" #include "llvm/DebugInfo/PDB/Raw/InfoStream.h" @@ -138,13 +139,20 @@ PDBFileBuilder::build(std::unique_ptr PdbFileBuffer) { return std::move(File); } -Error PDBFileBuilder::commit(const msf::WritableStream &Buffer) { - StreamWriter Writer(Buffer); +Error PDBFileBuilder::commit(StringRef Filename) { auto ExpectedLayout = finalizeMsfLayout(); if (!ExpectedLayout) return ExpectedLayout.takeError(); auto &Layout = *ExpectedLayout; + uint64_t Filesize = Layout.SB->BlockSize * Layout.SB->NumBlocks; + auto OutFileOrError = FileOutputBuffer::create(Filename, Filesize); + if (OutFileOrError.getError()) + return llvm::make_error(generic_error_code::invalid_path, + Filename); + FileBufferByteStream Buffer(std::move(*OutFileOrError)); + StreamWriter Writer(Buffer); + if (auto EC = Writer.writeObject(*Layout.SB)) return EC; uint32_t BlockMapOffset = @@ -189,4 +197,4 @@ Error PDBFileBuilder::commit(const msf::WritableStream &Buffer) { } return Buffer.commit(); -} \ No newline at end of file +} diff --git a/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp b/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp index ca46660..bfd9058 100644 --- a/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp +++ b/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp @@ -321,14 +321,6 @@ static void yamlToPdb(StringRef Path) { ExitOnErr(make_error(generic_error_code::unspecified, "Yaml does not contain MSF headers")); - auto OutFileOrError = FileOutputBuffer::create( - opts::yaml2pdb::YamlPdbOutputFile, YamlObj.Headers->FileSize); - if (OutFileOrError.getError()) - ExitOnErr(make_error(generic_error_code::invalid_path, - opts::yaml2pdb::YamlPdbOutputFile)); - - auto FileByteStream = - llvm::make_unique(std::move(*OutFileOrError)); PDBFileBuilder Builder(Allocator); ExitOnErr(Builder.initialize(YamlObj.Headers->SuperBlock)); @@ -382,7 +374,7 @@ static void yamlToPdb(StringRef Path) { IpiBuilder.addTypeRecord(R.Record); } - ExitOnErr(Builder.commit(*FileByteStream)); + ExitOnErr(Builder.commit(opts::yaml2pdb::YamlPdbOutputFile)); } static void pdb2Yaml(StringRef Path) {