1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

Escape command line arguments in backtraces

A common routine is to have the compiler crash, and attempt to rerun the
cc1 command-line by copying and pasting the arguments printed by
`llvm::Support::PrettyStackProgram::print`. However, these arguments are
not quoted or escaped which means they must be manually edited before
working correctly. This patch ensures that shell-unfriendly characters
are C-escaped, and arguments with spaces are double-quoted reducing the
frustration of running cc1 inside a debugger.

As the quoting is C, this is "best effort for most shells", but should
be fine for at least bash, zsh, csh, and cmd.exe.

Reviewed by: jhenderson

Differential Revision: https://reviews.llvm.org/D90759
This commit is contained in:
Luke Drummond 2020-11-04 12:10:25 +00:00
parent 1bd32a39f9
commit 95dd3dbc4f

View File

@ -25,6 +25,7 @@
#include <cassert>
#include <cstdarg>
#include <cstdio>
#include <cstring>
#include <tuple>
#ifdef HAVE_CRASHREPORTERCLIENT_H
@ -253,8 +254,16 @@ void PrettyStackTraceFormat::print(raw_ostream &OS) const { OS << Str << "\n"; }
void PrettyStackTraceProgram::print(raw_ostream &OS) const {
OS << "Program arguments: ";
// Print the argument list.
for (unsigned i = 0, e = ArgC; i != e; ++i)
OS << ArgV[i] << ' ';
for (int I = 0; I < ArgC; ++I) {
const bool HaveSpace = ::strchr(ArgV[I], ' ');
if (I)
OS << ' ';
if (HaveSpace)
OS << '"';
OS.write_escaped(ArgV[I]);
if (HaveSpace)
OS << '"';
}
OS << '\n';
}