const char *getExecutable() const { return Executable; }
const llvm::opt::ArgStringList &getArguments() const { return Arguments; }
+
+ /// Print a command argument, and optionally quote it.
+ static void printArg(llvm::raw_ostream &OS, const char *Arg, bool Quote);
};
/// Like Command, but with a fallback which is executed in case
return C;
}
+static void printArgList(raw_ostream &OS, const llvm::opt::ArgList &Args) {
+ llvm::opt::ArgStringList ASL;
+ for (const auto *A : Args)
+ A->render(Args, ASL);
+
+ for (auto I = ASL.begin(), E = ASL.end(); I != E; ++I) {
+ if (I != ASL.begin())
+ OS << ' ';
+ Command::printArg(OS, *I, true);
+ }
+ OS << '\n';
+}
+
// When clang crashes, produce diagnostic information including the fully
// preprocessed source file(s). Request that the developer attach the
// diagnostic information to a bug report.
<< "Error generating run script: " + Script + " " + EC.message();
} else {
ScriptOS << "# Crash reproducer for " << getClangFullVersion() << "\n"
- << "# Original command: ";
+ << "# Driver args: ";
+ printArgList(ScriptOS, C.getInputArgs());
+ ScriptOS << "# Original command: ";
Cmd.Print(ScriptOS, "\n", /*Quote=*/true);
Cmd.Print(ScriptOS, "\n", /*Quote=*/true, &CrashInfo);
Diag(clang::diag::note_drv_command_failed_diag_msg) << Script;
return 0;
}
-static void PrintArg(raw_ostream &OS, const char *Arg, bool Quote) {
+void Command::printArg(raw_ostream &OS, const char *Arg, bool Quote) {
const bool Escape = std::strpbrk(Arg, "\"\\$");
if (!Quote && !Escape) {
CrashReportInfo *CrashInfo) const {
// Always quote the exe.
OS << ' ';
- PrintArg(OS, Executable, /*Quote=*/true);
+ printArg(OS, Executable, /*Quote=*/true);
llvm::ArrayRef<const char *> Args = Arguments;
llvm::SmallVector<const char *, 128> ArgsRespFile;
// Replace the input file name with the crashinfo's file name.
OS << ' ';
StringRef ShortName = llvm::sys::path::filename(CrashInfo->Filename);
- PrintArg(OS, ShortName.str().c_str(), Quote);
+ printArg(OS, ShortName.str().c_str(), Quote);
continue;
}
}
OS << ' ';
- PrintArg(OS, Arg, Quote);
+ printArg(OS, Arg, Quote);
}
if (CrashInfo && HaveCrashVFS) {
OS << ' ';
- PrintArg(OS, "-ivfsoverlay", Quote);
+ printArg(OS, "-ivfsoverlay", Quote);
OS << ' ';
- PrintArg(OS, CrashInfo->VFSPath.str().c_str(), Quote);
+ printArg(OS, CrashInfo->VFSPath.str().c_str(), Quote);
}
if (ResponseFile != nullptr) {
// CHECKSRC: const int x = 10;
// CHECKSH: # Crash reproducer
+// CHECKSH-NEXT: # Driver args: "-fsyntax-only"
+// CHECKSH-SAME: "-D" "FOO=BAR"
// CHECKSH-NEXT: # Original command: {{.*$}}
// CHECKSH-NEXT: "-cc1"
// CHECKSH: "-isysroot" "/tmp/"
// RUN: -iprefix /the/prefix -iwithprefix /tmp -iwithprefixbefore /tmp/ \
// RUN: -Xclang -internal-isystem -Xclang /tmp/ \
// RUN: -Xclang -internal-externc-isystem -Xclang /tmp/ \
-// RUN: -DFOO=BAR 2>&1 | FileCheck %s
+// RUN: -DFOO=BAR -DBAR="BAZ QUX" 2>&1 | FileCheck %s
// RUN: cat %t/crash-report-*.c | FileCheck --check-prefix=CHECKSRC %s
// RUN: cat %t/crash-report-*.sh | FileCheck --check-prefix=CHECKSH %s
// REQUIRES: crash-recovery
FOO
// CHECKSRC: FOO
// CHECKSH: # Crash reproducer
+// CHECKSH-NEXT: # Driver args: "-fsyntax-only"
+// CHECKSH-SAME: "-D" "FOO=BAR"
+// CHECKSH-SAME: "-D" "BAR=BAZ QUX"
// CHECKSH-NEXT: # Original command: {{.*$}}
// CHECKSH-NEXT: "-cc1"
// CHECKSH: "-main-file-name" "crash-report.c"
// CHECKSH: "-D" "FOO=BAR"
+// CHECKSH: "-D" "BAR=BAZ QUX"
// CHECKSH-NOT: "-F/tmp/"
// CHECKSH-NOT: "-I" "/tmp/"
// CHECKSH-NOT: "-idirafter" "/tmp/"