diff options
author | Justin Bogner <mail@justinbogner.com> | 2014-10-21 17:24:44 +0000 |
---|---|---|
committer | Justin Bogner <mail@justinbogner.com> | 2014-10-21 17:24:44 +0000 |
commit | 256451561c9d9f71328c213295cae8ce9fded3f9 (patch) | |
tree | d73ae7c20673a379b5be61cf37f7a613eea95440 /clang/lib/Driver/Driver.cpp | |
parent | e306a32325ad3e9b73191941fef2d3643fb58ebe (diff) | |
download | bcm5719-llvm-256451561c9d9f71328c213295cae8ce9fded3f9.tar.gz bcm5719-llvm-256451561c9d9f71328c213295cae8ce9fded3f9.zip |
Driver: Move crash report command mangling into Command::Print
This pushes the logic for generating a crash reproduction script
entirely into Command::Print, instead of Command doing half of the
work and then relying on textual substitution for the rest. This makes
this logic much easier to read and will simplify fixing a couple of
issues in this area.
llvm-svn: 220305
Diffstat (limited to 'clang/lib/Driver/Driver.cpp')
-rw-r--r-- | clang/lib/Driver/Driver.cpp | 31 |
1 files changed, 4 insertions, 27 deletions
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 2e9fcfe0ef5..baf154fbc58 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -424,10 +424,7 @@ void Driver::generateCompilationDiagnostics(Compilation &C, CCGenDiagnostics = true; // Save the original job command(s). - std::string Cmd; - llvm::raw_string_ostream OS(Cmd); - FailingCommand.Print(OS, "\n", /*Quote*/ false, /*CrashReport*/ true); - OS.flush(); + Command Cmd = FailingCommand; // Keep track of whether we produce any errors while trying to produce // preprocessed sources. @@ -541,36 +538,16 @@ void Driver::generateCompilationDiagnostics(Compilation &C, } // Assume associated files are based off of the first temporary file. - const char *MainFile = TempFiles[0]; + CrashReportInfo CrashInfo(TempFiles[0], VFS); - std::string Script = StringRef(MainFile).rsplit('.').first.str() + ".sh"; + std::string Script = CrashInfo.Filename.rsplit('.').first.str() + ".sh"; std::error_code EC; llvm::raw_fd_ostream ScriptOS(Script, EC, llvm::sys::fs::F_Excl); if (EC) { Diag(clang::diag::note_drv_command_failed_diag_msg) << "Error generating run script: " + Script + " " + EC.message(); } else { - // Replace the original filename with the preprocessed one. - size_t I, E; - I = Cmd.find("-main-file-name "); - assert(I != std::string::npos && "Expected to find -main-file-name"); - I += 16; - E = Cmd.find(" ", I); - assert(E != std::string::npos && "-main-file-name missing argument?"); - StringRef OldFilename = StringRef(Cmd).slice(I, E); - StringRef NewFilename = llvm::sys::path::filename(MainFile); - I = StringRef(Cmd).rfind(OldFilename); - E = I + OldFilename.size(); - if (E + 1 < Cmd.size() && Cmd[E] == '"') - ++E; // Replace a trailing quote if present. - I = Cmd.rfind(" ", I) + 1; - Cmd.replace(I, E - I, NewFilename.data(), NewFilename.size()); - if (!VFS.empty()) { - // Add the VFS overlay to the reproduction script. - I += NewFilename.size(); - Cmd.insert(I, std::string(" -ivfsoverlay ") + VFS.c_str()); - } - ScriptOS << Cmd; + Cmd.Print(ScriptOS, "\n", /*Quote=*/false, &CrashInfo); Diag(clang::diag::note_drv_command_failed_diag_msg) << Script; } Diag(clang::diag::note_drv_command_failed_diag_msg) |