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.

llvm-svn: 214924
This commit is contained in:
Reid Kleckner 2014-08-05 20:49:12 +00:00
parent 42a6936c78
commit 822434da9f
2 changed files with 4 additions and 1 deletions

View File

@ -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()) {

View File

@ -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];