-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[llvm-pdbutil] Add output file option for pdb2yaml #82300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@llvm/pr-subscribers-debuginfo Author: None (nikitalita) ChangesAdds Full diff: https://github.com/llvm/llvm-project/pull/82300.diff 3 Files Affected:
diff --git a/llvm/tools/llvm-pdbutil/YAMLOutputStyle.cpp b/llvm/tools/llvm-pdbutil/YAMLOutputStyle.cpp
index 80b76657facc7c..10700aadfabc56 100644
--- a/llvm/tools/llvm-pdbutil/YAMLOutputStyle.cpp
+++ b/llvm/tools/llvm-pdbutil/YAMLOutputStyle.cpp
@@ -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;
diff --git a/llvm/tools/llvm-pdbutil/YAMLOutputStyle.h b/llvm/tools/llvm-pdbutil/YAMLOutputStyle.h
index 5d53e0b65d03c9..b8badecfca405a 100644
--- a/llvm/tools/llvm-pdbutil/YAMLOutputStyle.h
+++ b/llvm/tools/llvm-pdbutil/YAMLOutputStyle.h
@@ -21,7 +21,7 @@ namespace pdb {
class YAMLOutputStyle : public OutputStyle {
public:
YAMLOutputStyle(PDBFile &File);
-
+ YAMLOutputStyle(PDBFile &File, raw_ostream &Output);
Error dump() override;
private:
diff --git a/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp b/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
index fa870666fe61a3..e1336501103dfc 100644
--- a/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
+++ b/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
@@ -716,6 +716,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 {
@@ -893,8 +897,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());
}
|
|
|
|
We need tests for this as well. |
|
|
|
The CI seems to be hanging on Windows "Waiting for Agent"; not sure how to fix that. |
|
It passes the tests now. |
|
@tru this one too, please? |
84b3927 to
f01feaa
Compare
Adds
--yaml=<filename>option topdb2yaml. This is added primarily because we can't always count on having a utf-8 shell to redirect our output from, and if the shell is UTF-16 (like certain Windows shells), we'll output garbage.