From f6b93824677a9aaab59989f7f402010fda6bd63c Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Mon, 11 Jul 2016 21:45:09 +0000 Subject: [PATCH] [pdb] Add a pdb2yaml option to not dump file headers. This will be useful once we start adding the ability to dump type records and symbol records, since it will allow us to generate mergeable information instead of information that specifies an entire file. llvm-svn: 275109 --- llvm/test/DebugInfo/PDB/pdbdump-yaml.test | 7 ++++++ llvm/tools/llvm-pdbdump/PdbYaml.h | 2 +- llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp | 26 ++++++++++++--------- llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp | 21 ++++++++++++----- llvm/tools/llvm-pdbdump/llvm-pdbdump.h | 1 + 5 files changed, 39 insertions(+), 18 deletions(-) diff --git a/llvm/test/DebugInfo/PDB/pdbdump-yaml.test b/llvm/test/DebugInfo/PDB/pdbdump-yaml.test index 2d48489e3902..3ccc6c25be1b 100644 --- a/llvm/test/DebugInfo/PDB/pdbdump-yaml.test +++ b/llvm/test/DebugInfo/PDB/pdbdump-yaml.test @@ -1,5 +1,7 @@ ; RUN: llvm-pdbdump pdb2yaml -stream-metadata -stream-directory -pdb-stream %p/Inputs/empty.pdb \ ; RUN: | FileCheck -check-prefix=YAML %s +; RUN: llvm-pdbdump pdb2yaml -no-file-headers -stream-metadata -stream-directory -pdb-stream \ +; RUN: %p/Inputs/empty.pdb | FileCheck -check-prefix=NO-HEADERS %s ; YAML: --- ; YAML-NEXT: MSF: @@ -74,3 +76,8 @@ ; YAML-NEXT: Signature: 1424295906 ; YAML-NEXT: Version: 20000404 ; YAML-NEXT: ... + +; NO-HEADERS: --- +; NO-HEADERS-NOT: MSF: +; NO-HEADERS-NOT: SuperBlock: +; NO-HEADERS: ... \ No newline at end of file diff --git a/llvm/tools/llvm-pdbdump/PdbYaml.h b/llvm/tools/llvm-pdbdump/PdbYaml.h index 96b7d7c8db2e..d243f9b12b1a 100644 --- a/llvm/tools/llvm-pdbdump/PdbYaml.h +++ b/llvm/tools/llvm-pdbdump/PdbYaml.h @@ -46,7 +46,7 @@ struct PdbInfoStream { }; struct PdbObject { - MsfHeaders Headers; + Optional Headers; Optional> StreamSizes; Optional> StreamMap; Optional PdbStream; diff --git a/llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp b/llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp index 32f19414dd9e..f3c730fc6b39 100644 --- a/llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp +++ b/llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp @@ -42,20 +42,24 @@ Error YAMLOutputStyle::dump() { } Error YAMLOutputStyle::dumpFileHeaders() { + if (opts::pdb2yaml::NoFileHeaders) + return Error::success(); + yaml::MsfHeaders Headers; - Obj.Headers.SuperBlock.NumBlocks = File.getBlockCount(); - Obj.Headers.SuperBlock.BlockMapAddr = File.getBlockMapIndex(); - Obj.Headers.BlockMapOffset = File.getBlockMapOffset(); - Obj.Headers.SuperBlock.BlockSize = File.getBlockSize(); + Obj.Headers.emplace(); + Obj.Headers->SuperBlock.NumBlocks = File.getBlockCount(); + Obj.Headers->SuperBlock.BlockMapAddr = File.getBlockMapIndex(); + Obj.Headers->BlockMapOffset = File.getBlockMapOffset(); + Obj.Headers->SuperBlock.BlockSize = File.getBlockSize(); auto Blocks = File.getDirectoryBlockArray(); - Obj.Headers.DirectoryBlocks.assign(Blocks.begin(), Blocks.end()); - Obj.Headers.NumDirectoryBlocks = File.getNumDirectoryBlocks(); - Obj.Headers.SuperBlock.NumDirectoryBytes = File.getNumDirectoryBytes(); - Obj.Headers.NumStreams = + Obj.Headers->DirectoryBlocks.assign(Blocks.begin(), Blocks.end()); + Obj.Headers->NumDirectoryBlocks = File.getNumDirectoryBlocks(); + Obj.Headers->SuperBlock.NumDirectoryBytes = File.getNumDirectoryBytes(); + Obj.Headers->NumStreams = opts::pdb2yaml::StreamMetadata ? File.getNumStreams() : 0; - Obj.Headers.SuperBlock.Unknown0 = File.getUnknown0(); - Obj.Headers.SuperBlock.Unknown1 = File.getUnknown1(); - Obj.Headers.FileSize = File.getFileSize(); + Obj.Headers->SuperBlock.Unknown0 = File.getUnknown0(); + Obj.Headers->SuperBlock.Unknown1 = File.getUnknown1(); + Obj.Headers->FileSize = File.getFileSize(); return Error::success(); } diff --git a/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp b/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp index 1b72a1927ca1..ffb71ba04107 100644 --- a/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp +++ b/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp @@ -261,18 +261,24 @@ cl::list InputFilename(cl::Positional, } namespace pdb2yaml { +cl::opt + NoFileHeaders("no-file-headers", + cl::desc("Do not dump MSF file headers (you will not be able " + "to generate a fresh PDB from the resulting YAML)"), + cl::sub(PdbToYamlSubcommand), cl::init(false)); + cl::opt StreamMetadata( "stream-metadata", cl::desc("Dump the number of streams and each stream's size"), - cl::sub(PdbToYamlSubcommand)); + cl::sub(PdbToYamlSubcommand), cl::init(false)); cl::opt StreamDirectory( "stream-directory", cl::desc("Dump each stream's block map (implies -stream-metadata)"), - cl::sub(PdbToYamlSubcommand)); + cl::sub(PdbToYamlSubcommand), cl::init(false)); cl::opt PdbStream( "pdb-stream", cl::desc("Dump the PDB Stream (Stream 1) (implies -stream-metadata)"), - cl::sub(PdbToYamlSubcommand)); + cl::sub(PdbToYamlSubcommand), cl::init(false)); cl::list InputFilename(cl::Positional, cl::desc(""), cl::Required, @@ -296,9 +302,12 @@ static void yamlToPdb(StringRef Path) { llvm::yaml::Input In(Buffer->getBuffer()); pdb::yaml::PdbObject YamlObj; In >> YamlObj; + if (!YamlObj.Headers.hasValue()) + ExitOnErr(make_error(generic_error_code::unspecified, + "Yaml does not contain MSF headers")); auto OutFileOrError = FileOutputBuffer::create( - opts::yaml2pdb::YamlPdbOutputFile, YamlObj.Headers.FileSize); + opts::yaml2pdb::YamlPdbOutputFile, YamlObj.Headers->FileSize); if (OutFileOrError.getError()) ExitOnErr(make_error(generic_error_code::invalid_path, opts::yaml2pdb::YamlPdbOutputFile)); @@ -306,11 +315,11 @@ static void yamlToPdb(StringRef Path) { auto FileByteStream = llvm::make_unique(std::move(*OutFileOrError)); PDBFile Pdb(std::move(FileByteStream)); - ExitOnErr(Pdb.setSuperBlock(&YamlObj.Headers.SuperBlock)); + ExitOnErr(Pdb.setSuperBlock(&YamlObj.Headers->SuperBlock)); if (YamlObj.StreamSizes.hasValue()) { Pdb.setStreamSizes(YamlObj.StreamSizes.getValue()); } - Pdb.setDirectoryBlocks(YamlObj.Headers.DirectoryBlocks); + Pdb.setDirectoryBlocks(YamlObj.Headers->DirectoryBlocks); if (YamlObj.StreamMap.hasValue()) { std::vector> StreamMap; diff --git a/llvm/tools/llvm-pdbdump/llvm-pdbdump.h b/llvm/tools/llvm-pdbdump/llvm-pdbdump.h index 412edaaec968..7ccf4d5c2b4f 100644 --- a/llvm/tools/llvm-pdbdump/llvm-pdbdump.h +++ b/llvm/tools/llvm-pdbdump/llvm-pdbdump.h @@ -57,6 +57,7 @@ extern llvm::cl::opt DumpFpo; } namespace pdb2yaml { +extern llvm::cl::opt NoFileHeaders; extern llvm::cl::opt StreamMetadata; extern llvm::cl::opt StreamDirectory; extern llvm::cl::opt PdbStream;