From 31cad06755bc57a8d4e8cece2169e3bf49721638 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Tue, 5 Aug 2014 20:49:12 +0000 Subject: [PATCH] Make crash diagnostics on Windows the tiniest bit more useful This escapes any backslashes in the executable path and fixes an issue with a trailing quote when the main file name had to be quoted during printing. It's impossible to test this without putting backslashes or quotes into the executable path, so I didn't add automated tests. The crash diagnostics are still only useful if you're using bash on Windows, though. This should probably be writing a batch file instead. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214924 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Driver.cpp | 2 ++ lib/Driver/Job.cpp | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 3cdeec14d1..c5e7050972 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -548,6 +548,8 @@ void Driver::generateCompilationDiagnostics(Compilation &C, StringRef NewFilename = llvm::sys::path::filename(*it); 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()) { diff --git a/lib/Driver/Job.cpp b/lib/Driver/Job.cpp index 42cc1bc290..fdf730d881 100644 --- a/lib/Driver/Job.cpp +++ b/lib/Driver/Job.cpp @@ -95,7 +95,8 @@ static void PrintArg(raw_ostream &OS, const char *Arg, bool Quote) { void Command::Print(raw_ostream &OS, const char *Terminator, bool Quote, bool CrashReport) const { - OS << " \"" << Executable << '"'; + // Always quote the exe. + PrintArg(OS, Executable, /*Quote=*/true); for (size_t i = 0, e = Arguments.size(); i < e; ++i) { const char *const Arg = Arguments[i]; -- 2.40.0