Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-pdbutil/type-server-no-dbi.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

RUN: llvm-pdbutil dump -all %p/Inputs/TypeServerTest.pdb | FileCheck %s --check-prefix=NO-DBI
RUN: llvm-pdbutil pdb2yaml -all %p/Inputs/TypeServerTest.pdb > %t
RUN: llvm-pdbutil pdb2yaml -all %p/Inputs/TypeServerTest.pdb --yaml %t
RUN: FileCheck --input-file=%t %s --check-prefix=NO-DBI-YAML

NO-DBI-NOT: Native PDB Error: The specified stream could not be loaded.
Expand Down
7 changes: 5 additions & 2 deletions llvm/tools/llvm-pdbutil/YAMLOutputStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ static bool checkModuleSubsection(opts::ModuleSubsection MS) {
});
}

YAMLOutputStyle::YAMLOutputStyle(PDBFile &File)
: File(File), Out(outs()), Obj(File.getAllocator()) {
YAMLOutputStyle::YAMLOutputStyle(PDBFile &File, raw_ostream &OS)
: File(File), Out(OS), Obj(File.getAllocator()) {
Out.setWriteDefaultValues(!opts::pdb2yaml::Minimal);
}

YAMLOutputStyle::YAMLOutputStyle(PDBFile &File)
: YAMLOutputStyle::YAMLOutputStyle(File, llvm::outs()) {}

Error YAMLOutputStyle::dump() {
if (opts::pdb2yaml::StreamDirectory)
opts::pdb2yaml::StreamMetadata = true;
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-pdbutil/YAMLOutputStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace pdb {
class YAMLOutputStyle : public OutputStyle {
public:
YAMLOutputStyle(PDBFile &File);

YAMLOutputStyle(PDBFile &File, raw_ostream &Output);
Error dump() override;

private:
Expand Down
35 changes: 33 additions & 2 deletions llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,10 @@ cl::opt<bool> DumpModuleSyms("module-syms", cl::desc("dump module symbols"),
cl::list<std::string> InputFilename(cl::Positional,
cl::desc("<input PDB file>"), cl::Required,
cl::sub(PdbToYamlSubcommand));
cl::opt<std::string> PdbYamlOutputFile(
"yaml", cl::desc("the name of the yaml file to write (default stdout)"),
cl::sub(PdbToYamlSubcommand));

} // namespace pdb2yaml

namespace merge {
Expand Down Expand Up @@ -897,8 +901,35 @@ static void pdb2Yaml(StringRef Path) {
std::unique_ptr<IPDBSession> Session;
auto &File = loadPDB(Path, Session);

auto O = std::make_unique<YAMLOutputStyle>(File);

std::unique_ptr<YAMLOutputStyle> O;
std::unique_ptr<raw_fd_ostream> OutputFile;
if (!opts::pdb2yaml::PdbYamlOutputFile.empty()) {
std::error_code EC;
if (!sys::fs::exists(opts::pdb2yaml::PdbYamlOutputFile)) {
auto ParentPath =
sys::path::parent_path(opts::pdb2yaml::PdbYamlOutputFile);
if (!ParentPath.empty()) {
EC = sys::fs::create_directories(
sys::path::parent_path(opts::pdb2yaml::PdbYamlOutputFile));
if (EC) {
errs() << "Error creating directory: "
<< sys::path::parent_path(opts::pdb2yaml::PdbYamlOutputFile)
<< "\n";
exit(1);
}
}
}
OutputFile = std::make_unique<raw_fd_ostream>(
opts::pdb2yaml::PdbYamlOutputFile, EC, sys::fs::FA_Write);
if (EC || !OutputFile) {
errs() << "Error opening file for writing: "
<< opts::pdb2yaml::PdbYamlOutputFile << "\n";
exit(1);
}
O = std::make_unique<YAMLOutputStyle>(File, *OutputFile);
} else {
O = std::make_unique<YAMLOutputStyle>(File);
}
ExitOnErr(O->dump());
}

Expand Down