Escape command line arguments in backtraces
authorLuke Drummond <luke.drummond@codeplay.com>
Wed, 4 Nov 2020 12:10:25 +0000 (12:10 +0000)
committerLuke Drummond <luke.drummond@codeplay.com>
Tue, 17 Nov 2020 12:16:13 +0000 (12:16 +0000)
commit537cbd90c43dd9b166fa8f03347b1397505140e5
tree135880f2679513bb4bfe8ba18efdb735fbee1fc0
parentfcca6fe93f04f50c302f9ce2d1bad8f5f3fa369a
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
llvm/lib/Support/PrettyStackTrace.cpp