This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add a "diagnostics dump" command
ClosedPublic

Authored by JDevlieghere on Oct 10 2022, 3:05 PM.

Details

Summary

Add a "diagnostics dump" command to, as the name implies, dump the diagnostics to disk. The goal of this command is to let the user generate the diagnostics in case of an issue that doesn't cause the debugger to crash. This is also useful for testing.

Diff Detail

Event Timeline

JDevlieghere created this revision.Oct 10 2022, 3:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 10 2022, 3:05 PM
JDevlieghere requested review of this revision.Oct 10 2022, 3:05 PM
DavidSpickett added inline comments.Oct 11 2022, 5:56 AM
lldb/source/Commands/CommandObjectDiagnostics.cpp
85

AppendError sets the status for you now.

107

Is "log" correct here?

lldb/source/Commands/Options.td
348

Worth clarifying whether the path can be absolute or relative to the current working dir?

I'd guess either works.

lldb/source/Utility/Diagnostics.cpp
62

You std::move'd some errors above does that apply here?

(I'm not sure exactly what requires it and what doesn't)

70

Silly question, is it intentional that we write out files after saying they have been written?

Of course it makes sense to print something up front, otherwise the error here would come out of the blue, but perhaps "LLDB diagnostics will be written to..." instead?

(this is probably better changed in that earlier patch not sure if that went in yet)

lldb/test/Shell/Diagnostics/TestDump.test
1

"correct directory and creates a new one if needed." ?

clayborg added inline comments.Oct 11 2022, 11:42 AM
lldb/source/Commands/CommandObjectDiagnostics.cpp
84

Do we want to just create a temp directory if the user didn't specify one here and them emit the path to where things were saved instead of erroring out?

lldb/source/Utility/Diagnostics.cpp
58

How are we dumping these to the directory the user specifies the directory in "diagnostic dump"? Below we create a unique directory. Seems like this API should take a "Optional<FileSpec> directory" parameter and if it doesn't have a value, then create a unique directory?

JDevlieghere marked 8 inline comments as done.

Address code review feedback

lldb/source/Commands/CommandObjectDiagnostics.cpp
84

Yes, that's exactly what we do. If we get here we were unable to create either of them.

lldb/source/Commands/Options.td
348

Given that either works I think we don't need to be explicit about it.

lldb/source/Utility/Diagnostics.cpp
62

toString takes ownership of the error, so it needs to be moved here. Errors cannot be copied, so they always need to be moved, except when RVO kicks in.

70

Yes, that was @labath's suggestion because when we call this from the signal handler, we might crash again in the process and wouldn't print anything at all.

DavidSpickett added inline comments.Oct 25 2022, 2:54 AM
lldb/source/Utility/Diagnostics.cpp
70

Maybe I can be clearer:

LLDB diagnostics written to <...>
Please include the directory content when filing a bug report
<we crash during writing the files>

So the files haven't been written, or at least they are in an undefined state, but the output looks like we finished writing them. So will be written is more accurate. If I see this in a test log file I'm going to wonder did it crash writing them or did it already write them, which means I'd have to reproduce locally. With the sequence of events clearer, I can at least check obvious things like a full disk before needing to do that.

Small thing but it's a few words might save some annoyance down the road.

(printing up front I agree with, that part is good)

JDevlieghere marked an inline comment as done.

Update wording

lldb/source/Utility/Diagnostics.cpp
70

Makes sense!

This revision is now accepted and ready to land.Oct 25 2022, 8:47 AM
clayborg accepted this revision.Oct 25 2022, 4:49 PM
This revision was landed with ongoing or failed builds.Oct 31 2022, 2:40 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptOct 31 2022, 2:40 PM