This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Copy log files into diagnostic directory
ClosedPublic

Authored by JDevlieghere on Oct 10 2022, 5:27 PM.

Details

Summary

This patch copies over log files to the diagnostic directory. The caveat here is that this only works for logs that are redirected to a file. The implementation piggybacks of the mapping kept by the debugger. The advantage is that it's free until you generate the diagnostics, at which point you only pay the price of copying over the file.

Diff Detail

Event Timeline

JDevlieghere created this revision.Oct 10 2022, 5:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 10 2022, 5:27 PM
JDevlieghere requested review of this revision.Oct 10 2022, 5:27 PM

seems fine to me.

lldb/test/Shell/Diagnostics/TestCopyLogs.test
4

That's cute, but I suspect windows will have a problem with that. -s %s (and putting the commands in this file) would be safer.

So either way, if someone was running with no logs enabled we would have to ask them to enable them then re-run and get a new set of diagnostics (which is fine as is , not a criticism).

Option 1 they would need to add -o "log enable gdb-remote packets -f <some arbitrary path>".
Option 2 they would need to add -o "log enable gdb-remote packets".

So a few made up file names vs a performance decrease I'd take the former (without any measurement of the latter).

Given that diagnostics are going to be written on crash is it any more "safe" to just copy a file than rely on a ring buffer in memory? I don't think it is, unless the crash itself was in logging itself and all bets are off then in any case.

Another disadvantage to the ring buffer is a size limit, so you could lose early log data from a long session before you get to the crash. However you could work around that by sending each log to a file, once you had realised that the buffer didn't go far back enough (and we're asking people to re-run the reproducer in any case).

Saving logs that are already written to a file seems logical and isn't much harder to guide people how to do, vs. the ring buffer.

Also is the buffer option the same as "circular" here?

-h <log-handler> ( --log-handler <log-handler> )
     Specify a log handler which determines where log messages are written.
     Values: default | stream | circular | os

So we could have diagnostics also save anything kept in "circular", on the off chance that writing to a file isn't possible.

JDevlieghere marked an inline comment as done.Oct 11 2022, 8:46 AM

So either way, if someone was running with no logs enabled we would have to ask them to enable them then re-run and get a new set of diagnostics (which is fine as is , not a criticism).

Yeah, the idea is that if we ask someone to enable logs (which is still very likely even with the diagnostics) we'd automatically include them in the diagnostics so they don't need to go look in multiple places.

Also is the buffer option the same as "circular" here?

-h <log-handler> ( --log-handler <log-handler> )
     Specify a log handler which determines where log messages are written.
     Values: default | stream | circular | os

Yup

So we could have diagnostics also save anything kept in "circular", on the off chance that writing to a file isn't possible.

Technically yes, but then we have two ad-hoc solutions that support half the log handlers. I think if we care about that we might as well go with the T-based log handler behind the scenes.

lldb/test/Shell/Diagnostics/TestCopyLogs.test
4

I thought about that, but I still need %t to be expanded. I guess I could put log enable lldb commands -f in a file and append %t/commands.log to it.

DavidSpickett added a comment.EditedOct 12 2022, 2:11 AM

Technically yes, but then we have two ad-hoc solutions that support half the log handlers. I think if we care about that we might as well go with the T-based log handler behind the scenes.

Sure. More wondering whether the choice between circular buffer and file is a whole lot of code, but it isn't given that we already have buffers.

Saving log files only sounds good to me.

JDevlieghere marked an inline comment as done.

Rebase

JDevlieghere retitled this revision from [lldb] Copy log files into diagnostic directory (RFC) to [lldb] Copy log files into diagnostic directory .Nov 2 2022, 5:19 PM
JDevlieghere edited the summary of this revision. (Show Details)
labath added inline comments.Nov 15 2022, 12:21 AM
lldb/source/Core/Debugger.cpp
846

A default reference capture is dangerous when the lambda is supposed to run after the enclosing function returns. I guess you really wanted to capture this (?)
Also, I would expect that means that you need to disable the callback in the Debugger destructor.

lldb/test/Shell/Diagnostics/TestCopyLogs.test
4

hm.. the %t substitution makes it tricky, but I don't think this is better than what we had before. It still has nested quotes, which is the thing that causes problems on windows. I think you could work around this by creating an alias in a command file (say command alias logcommands log enable lldb commands) and then invoking it from the command line (-o "logcommands -f %t/commands.log").

JDevlieghere marked an inline comment as done.

Remove callback in dtor

mib accepted this revision.Feb 10 2023, 5:17 PM

LGTM!

lldb/source/Core/Debugger.cpp
852

re-use log_path for more clarity

This revision is now accepted and ready to land.Feb 10 2023, 5:17 PM
This revision was landed with ongoing or failed builds.Mar 7 2023, 4:00 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 7 2023, 4:00 PM