This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Output currently processing check and nodes on crash
AbandonedPublic

Authored by njames93 on Jan 28 2022, 5:32 PM.

Details

Summary

Create a PrettyStackTraceEvent that will dump the current check as well as the bound nodes if a ClangTidyCheck::check call results in a segfault.
This should help massively in debugging random crashes users may be experiencing where the check causing the crash is unknown as well as the source location of the crash.

Diff Detail

Event Timeline

njames93 created this revision.Jan 28 2022, 5:32 PM
njames93 requested review of this revision.Jan 28 2022, 5:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 28 2022, 5:32 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
155

Insert a blank line after the last closing namespace, please.

347

blank line between translation unit decls

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
180

blank line before onResultEntry

LGTM with a few whitespace nits.

This revision is now accepted and ready to land.Jan 28 2022, 5:54 PM
Eugene.Zelenko added inline comments.
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
190

Please separate with newline.

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
23–28

Please sort alphabetically.

njames93 updated this revision to Diff 404350.Jan 30 2022, 2:39 AM
njames93 marked 5 inline comments as done.

Refactored implementation to not store state in ClangTidyContext. This will let external consumers of clang-tidy opt into the behaviour. As well as integrate the reporting to any signal handlers they may be using.

njames93 requested review of this revision.Jan 30 2022, 2:40 AM

@Eugene.Zelenko Do you think I should update release notes for this?

Sure, this is important improvement.

Still LGTM and my comments are just thought experiments,
not must haves before pushing.

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
165

Does the LLVM style guide say anything about preferring member initializers over initializing constant expressions?

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
235

We repeat this if (CurrentlyProcessing) fragment 3 times...
Maybe initializing to a Null Object would be better?

This revision is now accepted and ready to land.Jan 31 2022, 10:30 AM
njames93 updated this revision to Diff 405111.Feb 1 2022, 3:10 PM

Added release notes.
Remove AST dump of bound nodes, typically isn't very helpful

njames93 added inline comments.Feb 2 2022, 2:52 AM
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
235

I don't think thats an improvement, as if we aren't in a context where the stack trace would be emitted, we don't want to be storing the state on each match.

njames93 updated this revision to Diff 405581.Feb 3 2022, 4:41 AM

Add testing infrastructure to verify stack trace output

njames93 added inline comments.Feb 3 2022, 4:51 AM
clang-tools-extra/test/CMakeLists.txt
100

Fairly certain llvm_add_library isnt the correct function to use as that will put the test module in the build/lib directory. However thats what the other plugin module is using so I've copied that for now.

njames93 edited the summary of this revision. (Show Details)Feb 3 2022, 6:16 AM
njames93 updated this revision to Diff 405636.Feb 3 2022, 7:29 AM
njames93 edited the summary of this revision. (Show Details)

Ignore the CTCrashTestTrace implementation file in the lit tests, Fixes 'Test has no 'RUN'' error.

njames93 added a subscriber: thakis.Feb 4 2022, 6:40 AM

@thakis I tried to test this on the gn build and got no issues, however I'm aware that the CTCrashTestTrace plugin isn't even compiled on the gn build. Not sure its worth the effort fixing that. The lit test should be disabled anyway.

aaron.ballman accepted this revision.Feb 9 2022, 6:37 AM

LGTM

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
165

I know we document that we prefer sticking with the local style used around the change. I don't know if we say anything about initializers, but for new code I've been suggesting folks use member initializers when possible.

349–352

This function does a whole lot of things that shouldn't be used in signal handlers: http://eel.is/c++draft/support.signal#3

Unless you know of a problem from the assert, I'd say go ahead and use it.

njames93 abandoned this revision.Feb 19 2022, 4:32 AM

I have decided to move this behaviour into the ast matcher directly, I feel in the long term, that should be a better home for this functionality.