[llvm] ce1fa20 - [Driver] When forcing a crash print the bug report message
John Brawn via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 29 05:15:18 PDT 2020
Author: John Brawn
Date: 2020-06-29T13:13:12+01:00
New Revision: ce1fa201af77e60d31b48571ffa1f85b919f6245
URL: https://github.com/llvm/llvm-project/commit/ce1fa201af77e60d31b48571ffa1f85b919f6245
DIFF: https://github.com/llvm/llvm-project/commit/ce1fa201af77e60d31b48571ffa1f85b919f6245.diff
LOG: [Driver] When forcing a crash print the bug report message
Commit a945037e8fd0c30e250a62211469eea6765a36ae moved the printing of the
"PLEASE submit a bug report" message to the crash handler, but that means we
don't print it when forcing a crash using FORCE_CLANG_DIAGNOSTICS_CRASH. Fix
this by adding a function to get the bug report message and printing it when
forcing a crash.
Differential Revision: https://reviews.llvm.org/D81672
Added:
Modified:
clang/test/Driver/crash-report-crashfile.m
clang/test/Driver/crash-report-modules.m
clang/test/Driver/crash-report-null.test
clang/tools/driver/driver.cpp
llvm/include/llvm/Support/PrettyStackTrace.h
llvm/lib/Support/PrettyStackTrace.cpp
Removed:
################################################################################
diff --git a/clang/test/Driver/crash-report-crashfile.m b/clang/test/Driver/crash-report-crashfile.m
index 980b1acd9fed..fd26246073fa 100644
--- a/clang/test/Driver/crash-report-crashfile.m
+++ b/clang/test/Driver/crash-report-crashfile.m
@@ -18,6 +18,7 @@
const int x = MODULE_MACRO;
// CRASH_ENV: failing because environment variable 'FORCE_CLANG_DIAGNOSTICS_CRASH' is set
+// CRASH_ENV: PLEASE submit a bug report to {{.*}} and include the crash backtrace, preprocessed source, and associated run script.
// CRASH_ENV: Preprocessed source(s) and associated run script(s) are located at:
// CRASH_ENV-NEXT: note: diagnostic msg: {{.*}}.m
// CRASH_ENV-NEXT: note: diagnostic msg: {{.*}}.cache
diff --git a/clang/test/Driver/crash-report-modules.m b/clang/test/Driver/crash-report-modules.m
index ded31b4ed4fe..e6d033533791 100644
--- a/clang/test/Driver/crash-report-modules.m
+++ b/clang/test/Driver/crash-report-modules.m
@@ -19,6 +19,7 @@
@import simple;
const int x = MODULE_MACRO;
+// CHECK: PLEASE submit a bug report to {{.*}} and include the crash backtrace, preprocessed source, and associated run script.
// CHECK: Preprocessed source(s) and associated run script(s) are located at:
// CHECK-NEXT: note: diagnostic msg: {{.*}}.m
// CHECK-NEXT: note: diagnostic msg: {{.*}}.cache
diff --git a/clang/test/Driver/crash-report-null.test b/clang/test/Driver/crash-report-null.test
index 7281f5309eb3..05309bf63f27 100644
--- a/clang/test/Driver/crash-report-null.test
+++ b/clang/test/Driver/crash-report-null.test
@@ -3,5 +3,6 @@
// FIXME: Investigating. "fatal error: file 'nul' modified since it was first processed"
// XFAIL: windows-gnu
+// CHECK: PLEASE submit a bug report to {{.*}} and include the crash backtrace, preprocessed source, and associated run script.
// CHECK: Preprocessed source(s) and associated run script(s) are located at:
// CHECK-NEXT: note: diagnostic msg: {{.*}}null-{{.*}}.c
diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 5e92fc32e6f6..f24fd61e61a5 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -511,6 +511,11 @@ int main(int argc_, const char **argv_) {
for (const auto &J : C->getJobs())
if (const Command *C = dyn_cast<Command>(&J))
FailingCommands.push_back(std::make_pair(-1, C));
+
+ // Print the bug report message that would be printed if we did actually
+ // crash, but only if we're crashing due to FORCE_CLANG_DIAGNOSTICS_CRASH.
+ if (::getenv("FORCE_CLANG_DIAGNOSTICS_CRASH"))
+ llvm::dbgs() << llvm::getBugReportMsg();
}
for (const auto &P : FailingCommands) {
diff --git a/llvm/include/llvm/Support/PrettyStackTrace.h b/llvm/include/llvm/Support/PrettyStackTrace.h
index 32975f3c5a35..ac25cffde051 100644
--- a/llvm/include/llvm/Support/PrettyStackTrace.h
+++ b/llvm/include/llvm/Support/PrettyStackTrace.h
@@ -41,6 +41,9 @@ namespace llvm {
/// a crash.
void setBugReportMsg(const char *Msg);
+ /// Get the bug report message that will be output upon a crash.
+ const char *getBugReportMsg();
+
/// PrettyStackTraceEntry - This class is used to represent a frame of the
/// "pretty" stack trace that is dumped when a program crashes. You can define
/// subclasses of this and declare them on the program stack: when they are
diff --git a/llvm/lib/Support/PrettyStackTrace.cpp b/llvm/lib/Support/PrettyStackTrace.cpp
index 3d310ed8916e..9072f9d2d2ee 100644
--- a/llvm/lib/Support/PrettyStackTrace.cpp
+++ b/llvm/lib/Support/PrettyStackTrace.cpp
@@ -33,6 +33,10 @@
using namespace llvm;
+static const char *BugReportMsg =
+ "PLEASE submit a bug report to " BUG_REPORT_URL
+ " and include the crash backtrace.\n";
+
// If backtrace support is not enabled, compile out support for pretty stack
// traces. This has the secondary effect of not requiring thread local storage
// when backtrace support is disabled.
@@ -142,10 +146,6 @@ using CrashHandlerStringStorage =
static CrashHandlerStringStorage crashHandlerStringStorage;
#endif
-static const char *BugReportMsg =
- "PLEASE submit a bug report to " BUG_REPORT_URL
- " and include the crash backtrace.\n";
-
/// This callback is run if a fatal signal is delivered to the process, it
/// prints the pretty stack trace.
static void CrashHandler(void *) {
@@ -203,9 +203,11 @@ static void printForSigInfoIfNeeded() {
#endif // ENABLE_BACKTRACES
void llvm::setBugReportMsg(const char *Msg) {
-#if ENABLE_BACKTRACES
BugReportMsg = Msg;
-#endif
+}
+
+const char *llvm::getBugReportMsg() {
+ return BugReportMsg;
}
PrettyStackTraceEntry::PrettyStackTraceEntry() {
More information about the llvm-commits
mailing list