This is an archive of the discontinued LLVM Phabricator instance.

Tools emit the bug report URL on crash
ClosedPublic

Authored by gbreynoo on Feb 10 2020, 6:42 AM.

Details

Summary

When Clang crashes a useful message is output:

"PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script."

A similar message could be output for all tools.

I am unfamiliar with this area of LLVM. Any suggestions would be appreciated, particularly regarding the testing of this change.

Diff Detail

Event Timeline

gbreynoo created this revision.Feb 10 2020, 6:42 AM

As this code is currently untested already, and testing it would require exploiting an existing crash (there should be none - any crashes that currently occur should be fixed), or deliberately introducing one, I think it is sufficient if you test it manually. As such, please post an example of the output you would get for a crash from LLD or another tool such as llvm-readobj. Finally, can clang be changed to make use of the same code? It seems silly to repeat the exact same string in the LLVM code base in two different places.

gbreynoo updated this revision to Diff 249627.Mar 11 2020, 8:06 AM

Removed Clangs use of the same message.

Hi James,

After forcing a crash in llvm-readobj here is the output:

PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace
Stack dump:
0.      Program arguments: F:\llvm-git\build\Debug\bin\llvm-readobj.exe
#0 0x00007ff60572b6d4 (F:\llvm-git\build\Debug\bin\llvm-readobj.exe+0x114b6d4)
#1 0x00007ff60572b874 (F:\llvm-git\build\Debug\bin\llvm-readobj.exe+0x114b874)
#2 0x00007ff604905623 (F:\llvm-git\build\Debug\bin\llvm-readobj.exe+0x325623)
#3 0x00007ff60572bd04 (F:\llvm-git\build\Debug\bin\llvm-readobj.exe+0x114bd04)
#4 0x00007ff60572bbee (F:\llvm-git\build\Debug\bin\llvm-readobj.exe+0x114bbee)
#5 0x00007ff60572baae (F:\llvm-git\build\Debug\bin\llvm-readobj.exe+0x114baae)
#6 0x00007ff60572bd99 (F:\llvm-git\build\Debug\bin\llvm-readobj.exe+0x114bd99)
#7 0x00007ffd61a47974 (C:\WINDOWS\System32\KERNEL32.DLL+0x17974)
#8 0x00007ffd61cba261 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x6a261)

After looking into Clang I saw that both messages would be output:

PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace
Stack dump:
0.      Program arguments: F:\llvm-git\build\Debug\bin\clang.exe -target i386-apple-darwin10 -flto -S -g F:\llvm-git\llvm-project\clang\test\CodeGen\2009-10-20-GlobalDebug.c
 #0 0x00007ff7a5698894 (F:\llvm-git\build\Debug\bin\clang.exe+0xb128894)
 #1 0x00007ff7a5698a34 (F:\llvm-git\build\Debug\bin\clang.exe+0xb128a34)
 #2 0x00007ff79a9fd29a (F:\llvm-git\build\Debug\bin\clang.exe+0x48d29a)
 #3 0x00007ff7a0086e56 (F:\llvm-git\build\Debug\bin\clang.exe+0x5b16e56)
 #4 0x00007ff7a0086158 (F:\llvm-git\build\Debug\bin\clang.exe+0x5b16158)
 #5 0x00007ff79ee69fee (F:\llvm-git\build\Debug\bin\clang.exe+0x48f9fee)
 #6 0x00007ff79ee695ff (F:\llvm-git\build\Debug\bin\clang.exe+0x48f95ff)
 #7 0x00007ff7a0082c3a (F:\llvm-git\build\Debug\bin\clang.exe+0x5b12c3a)
 #8 0x00007ff79ffbb1fd (F:\llvm-git\build\Debug\bin\clang.exe+0x5a4b1fd)
 #9 0x00007ff79ffbb439 (F:\llvm-git\build\Debug\bin\clang.exe+0x5a4b439)
#10 0x00007ff79ff55259 (F:\llvm-git\build\Debug\bin\clang.exe+0x59e5259)
#11 0x00007ff79a9fe6c3 (F:\llvm-git\build\Debug\bin\clang.exe+0x48e6c3)
#12 0x00007ff7a56998a4 (F:\llvm-git\build\Debug\bin\clang.exe+0xb1298a4)
#13 0x00007ff7a569974e (F:\llvm-git\build\Debug\bin\clang.exe+0xb12974e)
#14 0x00007ff7a569960e (F:\llvm-git\build\Debug\bin\clang.exe+0xb12960e)
#15 0x00007ff7a5699939 (F:\llvm-git\build\Debug\bin\clang.exe+0xb129939)
#16 0x00007ffd61a47974 (C:\WINDOWS\System32\KERNEL32.DLL+0x17974)
#17 0x00007ffd61cba261 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x6a261)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 11.0.0 (https://github.com/llvm/llvm-project.git 7202d9cde9d23ba94c7f09fd6b5eafc437136542)
Target: i386-apple-darwin10
Thread model: posix
InstalledDir: F:\llvm-git\build\Debug\bin
clang: note: diagnostic msg: PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
clang: note: diagnostic msg: Error generating preprocessed source(s).

The new diff includes the removal of the second message, and I have added reviewers who have made changes in the area.

probinson added inline comments.
clang/lib/Driver/Driver.cpp
1273

No, for clang crashes we want the message to say all these things. The driver makes an effort to produce preprocessed source and a run script; it's hard to diagnose a crash without them.

gbreynoo updated this revision to Diff 251392.Mar 19 2020, 8:34 AM
gbreynoo marked an inline comment as done.

After Paul's comment, a custom message can now be used to replace the generic one.

Thanks Paul.

Output is now as below:

General output:

PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace
Stack dump:
0.      Program arguments: F:\llvm-git\build\Debug\bin\llvm-readobj.exe
#0 0x00007ff6d55259c4 (F:\llvm-git\build\Debug\bin\llvm-readobj.exe+0x11559c4)
#1 0x00007ff6d5525b64 (F:\llvm-git\build\Debug\bin\llvm-readobj.exe+0x1155b64)
#2 0x00007ff6d46f83f3 (F:\llvm-git\build\Debug\bin\llvm-readobj.exe+0x3283f3)
#3 0x00007ff6d5525ff4 (F:\llvm-git\build\Debug\bin\llvm-readobj.exe+0x1155ff4)
#4 0x00007ff6d5525ede (F:\llvm-git\build\Debug\bin\llvm-readobj.exe+0x1155ede)
#5 0x00007ff6d5525d9e (F:\llvm-git\build\Debug\bin\llvm-readobj.exe+0x1155d9e)
#6 0x00007ff6d5526089 (F:\llvm-git\build\Debug\bin\llvm-readobj.exe+0x1156089)
#7 0x00007ffe44fb7974 (C:\WINDOWS\System32\KERNEL32.DLL+0x17974)
#8 0x00007ffe470fa261 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x6a261)

Clang specific:

PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: F:\llvm-git\build\Debug\bin\clang.exe -target i386-apple-darwin10 -flto -S -g F:\llvm-git\llvm-project\clang\test\CodeGen\2009-10-20-GlobalDebug.c
 #0 0x00007ff76a655274 (F:\llvm-git\build\Debug\bin\clang.exe+0xb305274)
 #1 0x00007ff76a655414 (F:\llvm-git\build\Debug\bin\clang.exe+0xb305414)
 #2 0x00007ff75f804234 (F:\llvm-git\build\Debug\bin\clang.exe+0x4b4234)
 #3 0x00007ff75f7ebf45 (F:\llvm-git\build\Debug\bin\clang.exe+0x49bf45)
 #4 0x00007ff764f1ef36 (F:\llvm-git\build\Debug\bin\clang.exe+0x5bcef36)
 #5 0x00007ff764f1e238 (F:\llvm-git\build\Debug\bin\clang.exe+0x5bce238)
 #6 0x00007ff763cdea2e (F:\llvm-git\build\Debug\bin\clang.exe+0x498ea2e)
 #7 0x00007ff763cde03f (F:\llvm-git\build\Debug\bin\clang.exe+0x498e03f)
 #8 0x00007ff764f1ad1a (F:\llvm-git\build\Debug\bin\clang.exe+0x5bcad1a)
 #9 0x00007ff764e5303d (F:\llvm-git\build\Debug\bin\clang.exe+0x5b0303d)
#10 0x00007ff764e53279 (F:\llvm-git\build\Debug\bin\clang.exe+0x5b03279)
#11 0x00007ff764ded0d9 (F:\llvm-git\build\Debug\bin\clang.exe+0x5a9d0d9)
#12 0x00007ff75f7ed1b7 (F:\llvm-git\build\Debug\bin\clang.exe+0x49d1b7)
#13 0x00007ff76a656034 (F:\llvm-git\build\Debug\bin\clang.exe+0xb306034)
#14 0x00007ff76a655ede (F:\llvm-git\build\Debug\bin\clang.exe+0xb305ede)
#15 0x00007ff76a655d9e (F:\llvm-git\build\Debug\bin\clang.exe+0xb305d9e)
#16 0x00007ff76a6560c9 (F:\llvm-git\build\Debug\bin\clang.exe+0xb3060c9)
#17 0x00007ffe44fb7974 (C:\WINDOWS\System32\KERNEL32.DLL+0x17974)
#18 0x00007ffe470fa261 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x6a261)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 11.0.0 (https://github.com/llvm/llvm-project.git fc2a5ef9c8754fe3fbdf96483901ca3f13406b35)
Target: i386-apple-darwin10
Thread model: posix
InstalledDir: F:\llvm-git\build\Debug\bin
clang: note: diagnostic msg: Error generating preprocessed source(s).
jhenderson added inline comments.Mar 23 2020, 2:18 AM
clang/lib/Driver/Driver.cpp
1273

@probinson - what are your thoughts on the latest version? Note that the output style is slightly different from before, but the message is now the same.

llvm/include/llvm/Support/PrettyStackTrace.h
42

msg -> Msg
SetCustomBugReportMsg -> setBugReportMsg

llvm/lib/Support/PrettyStackTrace.cpp
145

static const char *BugReportMsg;

Why not just have this set to the default in the first place, and overwrite it if somebody needs to? That'll remove the need for the new if in the CrashHandler function.

147

No need for the explicit llvm:: - you are inside a using namespace llvm file.

Also msg -> Msg.

Messaging looks fine now. Final ok left to James.

llvm/lib/Support/PrettyStackTrace.cpp
158

This wants a trailing fullstop.

gbreynoo marked 5 inline comments as done.Mar 23 2020, 11:32 AM
gbreynoo updated this revision to Diff 252109.Mar 23 2020, 11:43 AM

Changes made in response to James' comments

  • Corrected casing of Msg
  • Renamed setBugReportMsg
  • Set default string
gbreynoo marked an inline comment as done.Mar 23 2020, 11:58 AM
gbreynoo added inline comments.
llvm/lib/Support/PrettyStackTrace.cpp
147

I've found it is required, it's also consistent the other global functions in this file.

jhenderson added inline comments.Mar 25 2020, 1:45 AM
llvm/include/llvm/Support/PrettyStackTrace.h
42

The second half of this hasn't been properly addressed. Function names should start with a lower-case letter (see the LLVM coding standards). The other functions use an older style, and in general I think we should avoid adding more with the wrong style.

llvm/lib/Support/PrettyStackTrace.cpp
145

Again, this hasn't been properly addresssed. This should use an upper-case letter for the first letter of variable names. Please see the coding standards.

gbreynoo marked 2 inline comments as done.Mar 25 2020, 2:48 AM
gbreynoo updated this revision to Diff 252539.Mar 25 2020, 4:24 AM

Apologies James, this fixes the case issues.

This revision is now accepted and ready to land.Mar 25 2020, 5:18 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 26 2020, 3:45 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
MaskRay added inline comments.
llvm/lib/Support/PrettyStackTrace.cpp
145

static const char BugReportMsg[] = ...

static const char *BugReportMsg defines a writable variable.

In IR, the former does not have the unnamed_addr attribute while the latter has. The latter can lower to .rodata.str1.1 (SHF_MERGE | SHF_STRINGS) which can be optimized by the linker. This is nuance and the optimization probably weighs nothing (it is hardly to think there will be another thing having the same byte sequence.) The former just seems more correct.

MaskRay added inline comments.Mar 26 2020, 10:21 AM
llvm/lib/Support/PrettyStackTrace.cpp
145

Nevermind. I did not see setBugReportMsg

Hi. This patch seems to cause the undefined symbol error we're seeing when linking clang:

FAILED: bin/clang-11 
: && /b/s/w/ir/k/cipd/bin/clang++ --sysroot=/b/s/w/ir/k/cipd/linux-amd64  -I/b/s/w/ir/k/recipe_cleanup/clangzmv99P/zlib_install/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wno-comment -Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections -ffile-prefix-map=/b/s/w/ir/k/recipe_cleanup/clangzmv99P/llvm_build_dir=../recipe_cleanup/clangzmv99P/llvm_build_dir -ffile-prefix-map=/b/s/w/ir/k/llvm-project/= -no-canonical-prefixes -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3  -static-libstdc++ -fuse-ld=lld -Wl,--color-diagnostics -Wl,-allow-shlib-undefined    -Wl,-O3 -Wl,--gc-sections tools/clang/tools/driver/CMakeFiles/clang.dir/driver.cpp.o tools/clang/tools/driver/CMakeFiles/clang.dir/cc1_main.cpp.o tools/clang/tools/driver/CMakeFiles/clang.dir/cc1as_main.cpp.o tools/clang/tools/driver/CMakeFiles/clang.dir/cc1gen_reproducer_main.cpp.o  -o bin/clang-11  -Wl,-rpath,"\$ORIGIN/../lib" lib/libLLVMX86CodeGen.a lib/libLLVMX86AsmParser.a lib/libLLVMX86Desc.a lib/libLLVMX86Disassembler.a lib/libLLVMX86Info.a lib/libLLVMX86Utils.a lib/libLLVMARMCodeGen.a lib/libLLVMARMAsmParser.a lib/libLLVMARMDesc.a lib/libLLVMARMDisassembler.a lib/libLLVMARMInfo.a lib/libLLVMARMUtils.a lib/libLLVMAArch64CodeGen.a lib/libLLVMAArch64AsmParser.a lib/libLLVMAArch64Desc.a lib/libLLVMAArch64Disassembler.a lib/libLLVMAArch64Info.a lib/libLLVMAArch64Utils.a lib/libLLVMRISCVCodeGen.a lib/libLLVMRISCVAsmParser.a lib/libLLVMRISCVDesc.a lib/libLLVMRISCVDisassembler.a lib/libLLVMRISCVInfo.a lib/libLLVMRISCVUtils.a lib/libLLVMAnalysis.a lib/libLLVMCodeGen.a lib/libLLVMCore.a lib/libLLVMipo.a lib/libLLVMAggressiveInstCombine.a lib/libLLVMInstCombine.a lib/libLLVMInstrumentation.a lib/libLLVMMC.a lib/libLLVMMCParser.a lib/libLLVMObjCARCOpts.a lib/libLLVMOption.a lib/libLLVMScalarOpts.a lib/libLLVMSupport.a lib/libLLVMTransformUtils.a lib/libLLVMVectorize.a -lpthread lib/libclangBasic.a lib/libclangCodeGen.a lib/libclangDriver.a lib/libclangFrontend.a lib/libclangFrontendTool.a lib/libclangSerialization.a lib/libLLVMARMDesc.a lib/libLLVMARMInfo.a lib/libLLVMARMUtils.a lib/libLLVMCFGuard.a lib/libLLVMAArch64Desc.a lib/libLLVMAArch64Info.a lib/libLLVMAArch64Utils.a lib/libLLVMAsmPrinter.a lib/libLLVMDebugInfoDWARF.a lib/libLLVMGlobalISel.a lib/libLLVMSelectionDAG.a lib/libLLVMMCDisassembler.a lib/libclangCodeGen.a lib/libLLVMCoverage.a lib/libLLVMLTO.a lib/libLLVMObjCARCOpts.a lib/libLLVMPasses.a lib/libLLVMCodeGen.a lib/libLLVMTarget.a lib/libLLVMCoroutines.a lib/libLLVMipo.a lib/libLLVMInstrumentation.a lib/libLLVMVectorize.a lib/libLLVMBitWriter.a lib/libLLVMIRReader.a lib/libLLVMAsmParser.a lib/libLLVMLinker.a lib/libLLVMScalarOpts.a lib/libLLVMAggressiveInstCombine.a lib/libLLVMInstCombine.a lib/libclangRewriteFrontend.a lib/libclangStaticAnalyzerFrontend.a lib/libclangStaticAnalyzerCheckers.a lib/libclangStaticAnalyzerCore.a lib/libclangCrossTU.a lib/libclangIndex.a lib/libclangFrontend.a lib/libclangDriver.a lib/libLLVMOption.a lib/libclangParse.a lib/libclangSerialization.a lib/libclangSema.a lib/libclangAnalysis.a lib/libclangASTMatchers.a lib/libclangEdit.a lib/libclangFormat.a lib/libclangToolingInclusions.a lib/libclangToolingCore.a lib/libclangAST.a lib/libLLVMFrontendOpenMP.a lib/libLLVMTransformUtils.a lib/libLLVMAnalysis.a lib/libLLVMProfileData.a lib/libLLVMObject.a lib/libLLVMMCParser.a lib/libLLVMBitReader.a lib/libLLVMTextAPI.a lib/libclangRewrite.a lib/libclangLex.a lib/libclangBasic.a lib/libLLVMCore.a lib/libLLVMRemarks.a lib/libLLVMBitstreamReader.a lib/libLLVMMC.a lib/libLLVMBinaryFormat.a lib/libLLVMDebugInfoCodeView.a lib/libLLVMDebugInfoMSF.a lib/libLLVMSupport.a -lrt -ldl -lpthread -lm lib/libLLVMDemangle.a && :
ld.lld: error: undefined symbol: llvm::setBugReportMsg(char const*)
>>> referenced by driver.cpp
>>>               tools/clang/tools/driver/CMakeFiles/clang.dir/driver.cpp.o:(main)

Would you mind taking a look? Thanks.

Builder: https://luci-milo.appspot.com/p/fuchsia/builders/ci/clang-linux-x64/b8884769398556395840

Hi @leonardchan
Owen is on UK time so I took a look. I think Owen inadvertently put the new API in a place that is guarded by #if ENABLE_BACKTRACES and I'm guessing that your build has that turned off.
I've posted D76893 because something has gone wrong with my git environment and I can't commit it myself right now.
I didn't actually try a build with backtraces off, because I figured you'd rather have the likely fix sooner. Hope I did fix it and sorry for the breakage.