Index: tools/llvm-pdbdump/CMakeLists.txt =================================================================== --- tools/llvm-pdbdump/CMakeLists.txt +++ tools/llvm-pdbdump/CMakeLists.txt @@ -15,9 +15,11 @@ FunctionDumper.cpp LinePrinter.cpp LLVMOutputStyle.cpp + PdbYaml.cpp TypeDumper.cpp TypedefDumper.cpp VariableDumper.cpp + YAMLOutputStyle.cpp ) if(LLVM_USE_SANITIZE_COVERAGE) Index: tools/llvm-pdbdump/LLVMOutputStyle.h =================================================================== --- tools/llvm-pdbdump/LLVMOutputStyle.h +++ tools/llvm-pdbdump/LLVMOutputStyle.h @@ -34,6 +34,8 @@ Error dumpPublicsStream() override; Error dumpSectionHeaders() override; + void flush() override; + private: PDBFile &File; codeview::CVTypeDumper TD; Index: tools/llvm-pdbdump/LLVMOutputStyle.cpp =================================================================== --- tools/llvm-pdbdump/LLVMOutputStyle.cpp +++ tools/llvm-pdbdump/LLVMOutputStyle.cpp @@ -650,3 +650,5 @@ } return Error::success(); } + +void LLVMOutputStyle::flush() { P.flush(); } Index: tools/llvm-pdbdump/OutputStyle.h =================================================================== --- tools/llvm-pdbdump/OutputStyle.h +++ tools/llvm-pdbdump/OutputStyle.h @@ -31,6 +31,8 @@ virtual Error dumpSectionMap() = 0; virtual Error dumpPublicsStream() = 0; virtual Error dumpSectionHeaders() = 0; + + virtual void flush() = 0; }; } } Index: tools/llvm-pdbdump/PdbYaml.h =================================================================== --- /dev/null +++ tools/llvm-pdbdump/PdbYaml.h @@ -0,0 +1,57 @@ +//===- PdbYAML.h ---------------------------------------------- *- C++ --*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TOOLS_LLVMPDBDUMP_PDBYAML_H +#define LLVM_TOOLS_LLVMPDBDUMP_PDBYAML_H + +#include "OutputStyle.h" + +#include "llvm/ADT/Optional.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/YAMLTraits.h" + +#include + +namespace llvm { +namespace pdb { +class PDBFile; + +namespace yaml { +struct MsfHeaders { + uint32_t BlockSize; + uint32_t Unknown0; + uint32_t BlockCount; + uint32_t NumDirectoryBytes; + uint32_t Unknown1; + uint32_t BlockMapIndex; + uint32_t NumDirectoryBlocks; + uint32_t BlockMapOffset; + std::vector DirectoryBlocks; + uint32_t NumStreams; +}; + +struct PdbObject { + Optional Headers; +}; +} +} + +namespace yaml { +template <> struct MappingTraits { + static void mapping(IO &IO, pdb::yaml::MsfHeaders &Obj); +}; +template <> struct MappingTraits { + static void mapping(IO &IO, pdb::yaml::PdbObject &Obj); +}; +} +} + +LLVM_YAML_IS_SEQUENCE_VECTOR(uint32_t) + +#endif // LLVM_TOOLS_LLVMPDBDUMP_PDBYAML_H Index: tools/llvm-pdbdump/PdbYaml.cpp =================================================================== --- /dev/null +++ tools/llvm-pdbdump/PdbYaml.cpp @@ -0,0 +1,35 @@ +//===- PdbYAML.cpp -------------------------------------------- *- C++ --*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "PdbYaml.h" + +#include "llvm/DebugInfo/PDB/Raw/PDBFile.h" + +using namespace llvm; +using namespace llvm::pdb; +using namespace llvm::pdb::yaml; + +void llvm::yaml::MappingTraits::mapping( + IO &IO, pdb::yaml::MsfHeaders &Obj) { + IO.mapRequired("BlockSize", Obj.BlockSize); + IO.mapRequired("Unknown0", Obj.Unknown0); + IO.mapRequired("NumBlocks", Obj.BlockCount); + IO.mapRequired("NumDirectoryBytes", Obj.NumDirectoryBytes); + IO.mapRequired("Unknown1", Obj.Unknown1); + IO.mapRequired("BlockMapAddr", Obj.BlockMapIndex); + IO.mapRequired("NumDirectoryBlocks", Obj.NumDirectoryBlocks); + IO.mapRequired("BlockMapOffset", Obj.BlockMapOffset); + IO.mapRequired("DirectoryBlocks", Obj.DirectoryBlocks); + IO.mapRequired("NumStreams", Obj.NumStreams); +} + +void llvm::yaml::MappingTraits::mapping( + IO &IO, pdb::yaml::PdbObject &Obj) { + IO.mapOptional("MSF", Obj.Headers); +} Index: tools/llvm-pdbdump/YAMLOutputStyle.h =================================================================== --- /dev/null +++ tools/llvm-pdbdump/YAMLOutputStyle.h @@ -0,0 +1,50 @@ +//===- YAMLOutputStyle.h -------------------------------------- *- C++ --*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TOOLS_LLVMPDBDUMP_YAMLOUTPUTSTYLE_H +#define LLVM_TOOLS_LLVMPDBDUMP_YAMLOUTPUTSTYLE_H + +#include "OutputStyle.h" +#include "PdbYaml.h" + +#include "llvm/DebugInfo/CodeView/TypeDumper.h" +#include "llvm/Support/ScopedPrinter.h" +#include "llvm/Support/YAMLTraits.h" + +namespace llvm { +namespace pdb { +class YAMLOutputStyle : public OutputStyle { +public: + YAMLOutputStyle(PDBFile &File); + + Error dumpFileHeaders() override; + Error dumpStreamSummary() override; + Error dumpStreamBlocks() override; + Error dumpStreamData() override; + Error dumpInfoStream() override; + Error dumpNamedStream() override; + Error dumpTpiStream(uint32_t StreamIdx) override; + Error dumpDbiStream() override; + Error dumpSectionContribs() override; + Error dumpSectionMap() override; + Error dumpPublicsStream() override; + Error dumpSectionHeaders() override; + + void flush() override; + +private: + PDBFile &File; + llvm::yaml::Output Out; + + yaml::PdbObject Obj; +}; +} // namespace pdb +} // namespace llvm + +#endif // LLVM_TOOLS_LLVMPDBDUMP_YAMLOUTPUTSTYLE_H Index: tools/llvm-pdbdump/YAMLOutputStyle.cpp =================================================================== --- /dev/null +++ tools/llvm-pdbdump/YAMLOutputStyle.cpp @@ -0,0 +1,119 @@ +//===- YAMLOutputStyle.cpp ------------------------------------ *- C++ --*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "YAMLOutputStyle.h" + +#include "PdbYaml.h" +#include "llvm-pdbdump.h" + +#include "llvm/DebugInfo/PDB/Raw/PDBFile.h" + +using namespace llvm; +using namespace llvm::pdb; + +YAMLOutputStyle::YAMLOutputStyle(PDBFile &File) : Out(outs()), File(File) {} + +Error YAMLOutputStyle::dumpFileHeaders() { + if (!opts::DumpHeaders) + return Error::success(); + + yaml::MsfHeaders Headers; + Headers.BlockCount = File.getBlockCount(); + Headers.BlockMapIndex = File.getBlockMapIndex(); + Headers.BlockMapOffset = File.getBlockMapOffset(); + Headers.BlockSize = File.getBlockSize(); + auto Blocks = File.getDirectoryBlockArray(); + Headers.DirectoryBlocks.assign(Blocks.begin(), Blocks.end()); + Headers.NumDirectoryBlocks = File.getNumDirectoryBlocks(); + Headers.NumDirectoryBytes = File.getNumDirectoryBytes(); + Headers.NumStreams = File.getNumStreams(); + Headers.Unknown0 = File.getUnknown0(); + Headers.Unknown1 = File.getUnknown1(); + + Obj.Headers.emplace(Headers); + + return Error::success(); +} + +Error YAMLOutputStyle::dumpStreamSummary() { + if (!opts::DumpStreamSummary) + return Error::success(); + + return Error::success(); +} + +Error YAMLOutputStyle::dumpStreamBlocks() { + if (!opts::DumpStreamBlocks) + return Error::success(); + + return Error::success(); +} + +Error YAMLOutputStyle::dumpStreamData() { + uint32_t StreamCount = File.getNumStreams(); + StringRef DumpStreamStr = opts::DumpStreamDataIdx; + uint32_t DumpStreamNum; + if (DumpStreamStr.getAsInteger(/*Radix=*/0U, DumpStreamNum) || + DumpStreamNum >= StreamCount) + return Error::success(); + + return Error::success(); +} + +Error YAMLOutputStyle::dumpInfoStream() { + if (!opts::DumpHeaders) + return Error::success(); + return Error::success(); +} + +Error YAMLOutputStyle::dumpNamedStream() { + if (opts::DumpStreamDataName.empty()) + return Error::success(); + + return Error::success(); +} + +Error YAMLOutputStyle::dumpTpiStream(uint32_t StreamIdx) { + return Error::success(); +} + +Error YAMLOutputStyle::dumpDbiStream() { return Error::success(); } + +Error YAMLOutputStyle::dumpSectionContribs() { + if (!opts::DumpSectionContribs) + return Error::success(); + + return Error::success(); +} + +Error YAMLOutputStyle::dumpSectionMap() { + if (!opts::DumpSectionMap) + return Error::success(); + + return Error::success(); +} + +Error YAMLOutputStyle::dumpPublicsStream() { + if (!opts::DumpPublics) + return Error::success(); + + return Error::success(); +} + +Error YAMLOutputStyle::dumpSectionHeaders() { + if (!opts::DumpSectionHeaders) + return Error::success(); + + return Error::success(); +} + +void YAMLOutputStyle::flush() { + Out << Obj; + outs().flush(); +} Index: tools/llvm-pdbdump/llvm-pdbdump.cpp =================================================================== --- tools/llvm-pdbdump/llvm-pdbdump.cpp +++ tools/llvm-pdbdump/llvm-pdbdump.cpp @@ -22,6 +22,7 @@ #include "OutputStyle.h" #include "TypeDumper.h" #include "VariableDumper.h" +#include "YAMLOutputStyle.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/BitVector.h" @@ -206,6 +207,8 @@ std::unique_ptr O; if (opts::RawOutputStyle == opts::OutputStyleTy::LLVM) O = llvm::make_unique(File); + else if (opts::RawOutputStyle == opts::OutputStyleTy::YAML) + O = llvm::make_unique(File); else return make_error(raw_error_code::feature_unsupported, "Requested output style unsupported"); @@ -248,6 +251,8 @@ if (auto EC = O->dumpSectionHeaders()) return EC; + + O->flush(); return Error::success(); }