This is an archive of the discontinued LLVM Phabricator instance.

[Driver] When forcing a crash print the bug report message
ClosedPublic

Authored by john.brawn on Jun 11 2020, 10:23 AM.

Details

Summary

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.

Diff Detail

Event Timeline

john.brawn created this revision.Jun 11 2020, 10:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 11 2020, 10:23 AM

This seems sensible to me, but I have zero experience with the CrashRecoveryContext class. It might be best to get someone who has more knowledge of it to look at it.

Added a couple of reviewers that have recently worked on CrashRecoveryContext.

aganea added inline comments.Jun 16 2020, 2:00 PM
clang/tools/driver/driver.cpp
518

The only concern I have is that a unrelated call stack will be printed.
Could you possibly add (and use here) a function along the lines of emitBugReportMsg() { errs() << BugReportMsg; }?

john.brawn marked an inline comment as done.Jun 18 2020, 9:49 AM
john.brawn added inline comments.
clang/tools/driver/driver.cpp
518

I had a go at doing that, but then realised that currently the bug report message only exists, and is only printed, when llvm is built with LLVM_ENABLE_BACKTRACES=ON which I don't think is what we want. I've instead adjusted things so that the bug report message is printed in CrashRecoveryContext instead of in the backtrace handler, which also means we can get the message without the backtrace here.

john.brawn edited the summary of this revision. (Show Details)

Moved BugReportMsg printing into CrashRecoveryContext, and stopped printing of backtrace when forcing a crash.

Herald added a project: Restricted Project. · View Herald TranscriptJun 18 2020, 9:53 AM
aganea added a comment.EditedJun 18 2020, 10:44 AM

But that won't work when compiling & crashing with -fno-integrated-cc1, would it? (or if building with cmake ... -DCLANG_SPAWN_CC1=1). In that case, normal crashes (not -gen-reproducer) won't go through the CrashRecoveryContext.
Try running:

$ CCC_OVERRIDE_OPTIONS=+-fno-integrated-cc1
$ py your_build_folder/bin/llvm-lit.py -vv -a clang/test/Driver/crash-report.c

See if the commands issued by the test display the "PLEASE submit a bug report" message.

But that won't work when compiling & crashing with -fno-integrated-cc1, would it? (or if building with cmake ... -DCLANG_SPAWN_CC1=1). In that case, normal crashes (not -gen-reproducer) won't go through the CrashRecoveryContext.
Try running:

$ CCC_OVERRIDE_OPTIONS=+-fno-integrated-cc1
$ py your_build_folder/bin/llvm-lit.py -vv -a clang/test/Driver/crash-report.c

See if the commands issued by the test display the "PLEASE submit a bug report" message.

If I'm following it correctly (I could easily not be), the latest version of the patch will also no longer print the bug report submission message for crashes in other parts of LLVM, not just clang, which was rather the motivation of @gbreynoo's recent changes.

john.brawn retitled this revision from [Driver] When forcing a crash call abort to get the correct diagnostic to [Driver] When forcing a crash print the bug report message.
john.brawn edited the summary of this revision. (Show Details)

Print the bug report message when forcing a crash, but also have the message available even with LLVM_ENABLE_BACKTRACES=OFF.

MaskRay added inline comments.
llvm/lib/Support/PrettyStackTrace.cpp
36

This variable is mutable. Please use const char BugReportMsg[]

jhenderson accepted this revision.Jun 23 2020, 12:01 AM

LGTM, but wait for others too, please.

This revision is now accepted and ready to land.Jun 23 2020, 12:01 AM
john.brawn marked an inline comment as done.Jun 23 2020, 5:54 AM
john.brawn added inline comments.
llvm/lib/Support/PrettyStackTrace.cpp
36

It needs to be mutable because it is set by llvm::setBugReportMsg.

MaskRay added inline comments.Jun 23 2020, 10:59 AM
clang/tools/driver/driver.cpp
515

Why llvm::dbgs() << llvm::getBugReportMsg(); when -gen-reproducer is specified? The user requests to generate a reproduce file, but this does not suggest that clang has a bug. Dumping an URL is not very appropriate.

john.brawn marked an inline comment as done.Jun 25 2020, 12:10 PM
john.brawn added inline comments.
clang/tools/driver/driver.cpp
515

Emitting the bug report message is primarily for when FORCE_CLANG_DIAGNOSTICS_CRASH is set (because we can get here either due to that or -gen-reproducer). I could adjust this to only emit the message when that is set if you'd like? Though either way we get the "PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:" message.

MaskRay added inline comments.Jun 25 2020, 12:35 PM
clang/tools/driver/driver.cpp
515

When FORCE_CLANG_DIAGNOSTICS_CRASH is set or -gen-reproducer is specified, I feel that a URL or "PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT" is not very appropriate because this is not a real crash......

john.brawn marked an inline comment as done.Jun 26 2020, 12:30 PM
john.brawn added inline comments.
clang/tools/driver/driver.cpp
515

FORCE_CLANG_DIAGNOSTICS_CRASH exists exactly to test the diagnostics (at least according to 681e4b8d962ed848d2bd443642e53909af53a6cd which added it) so we should be emitting it them. I'll adjust it to not do so when using -gen-reproducer.

john.brawn edited the summary of this revision. (Show Details)

Don't print the diagnostic with -gen-reproducer.

MaskRay accepted this revision.Jun 26 2020, 4:32 PM

Thanks!

jhenderson accepted this revision.Jun 29 2020, 12:27 AM

Latest version LGTM too.

This revision was automatically updated to reflect the committed changes.