@@ -718,6 +718,10 @@ cl::opt<bool> DumpModuleSyms("module-syms", cl::desc("dump module symbols"),
718718cl::list<std::string> InputFilename (cl::Positional,
719719 cl::desc (" <input PDB file>" ), cl::Required,
720720 cl::sub(PdbToYamlSubcommand));
721+ cl::opt<std::string> PdbYamlOutputFile (
722+ " yaml" , cl::desc(" the name of the yaml file to write (default stdout)" ),
723+ cl::sub(PdbToYamlSubcommand));
724+
721725} // namespace pdb2yaml
722726
723727namespace merge {
@@ -897,8 +901,35 @@ static void pdb2Yaml(StringRef Path) {
897901 std::unique_ptr<IPDBSession> Session;
898902 auto &File = loadPDB (Path, Session);
899903
900- auto O = std::make_unique<YAMLOutputStyle>(File);
901-
904+ std::unique_ptr<YAMLOutputStyle> O;
905+ std::unique_ptr<raw_fd_ostream> OutputFile;
906+ if (!opts::pdb2yaml::PdbYamlOutputFile.empty ()) {
907+ std::error_code EC;
908+ if (!sys::fs::exists (opts::pdb2yaml::PdbYamlOutputFile)) {
909+ auto ParentPath =
910+ sys::path::parent_path (opts::pdb2yaml::PdbYamlOutputFile);
911+ if (!ParentPath.empty ()) {
912+ EC = sys::fs::create_directories (
913+ sys::path::parent_path (opts::pdb2yaml::PdbYamlOutputFile));
914+ if (EC) {
915+ errs () << " Error creating directory: "
916+ << sys::path::parent_path (opts::pdb2yaml::PdbYamlOutputFile)
917+ << " \n " ;
918+ exit (1 );
919+ }
920+ }
921+ }
922+ OutputFile = std::make_unique<raw_fd_ostream>(
923+ opts::pdb2yaml::PdbYamlOutputFile, EC, sys::fs::FA_Write);
924+ if (EC || !OutputFile) {
925+ errs () << " Error opening file for writing: "
926+ << opts::pdb2yaml::PdbYamlOutputFile << " \n " ;
927+ exit (1 );
928+ }
929+ O = std::make_unique<YAMLOutputStyle>(File, *OutputFile);
930+ } else {
931+ O = std::make_unique<YAMLOutputStyle>(File);
932+ }
902933 ExitOnErr (O->dump ());
903934}
904935
0 commit comments