This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add support for specifying a log handler
ClosedPublic

Authored by JDevlieghere on Jun 21 2022, 10:59 PM.

Details

Summary

This patch adds a new flag to log enable allowing the user to specify a log handler. This makes it possible to enable logging to a circular buffer (D127937) or with OSLog (D128321) as well as the default stream handler. As is the patch is more of an RFC/POC. It needs some cleaning up as well as a test case, which I'll add if everyone is happy with the direction.

Diff Detail

Event Timeline

JDevlieghere created this revision.Jun 21 2022, 10:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2022, 10:59 PM
clayborg added inline comments.Jun 22 2022, 9:54 AM
lldb/include/lldb/lldb-private-enumerations.h
229

Maybe "eLogHandlerCircular"?

230

remove #if. See inlined comments in https://reviews.llvm.org/D128321

lldb/source/Commands/CommandObjectLog.cpp
37
41
170

Do we want to define a "eLogHandlerDefault" which points to "eLogHandlerStream"?

lldb/source/Commands/Options.td
438–439

Maybe "--type" or "--kind" would be better? Handler seems like an internal name. Maybe also mention what it will default to if not specified? Can the user see a list of the valid values or do we need to supply these in the description?

lldb/source/Core/Debugger.cpp
1418
mib added inline comments.Jun 22 2022, 11:21 AM
lldb/source/Core/Debugger.cpp
1409–1411

Many (or most) arguments passed to this function might not be used depending on the kind of LogHandler you're instantiating. This is fine for now but if we add other handlers in the future that take different argument, it might become very confusing on which one to use.

May be we could use a parameter pack with some template specialization to make this more robust ?

1440

I find it confusing to negate should_close but to initialize it to true.

Since it’s not modified anywhere else, IMO it might be better to inline the value with a comment (/*should_close=*/), instead of using the variable.

1462

Ditto

mib added inline comments.Jun 22 2022, 11:23 AM
lldb/source/Commands/CommandObjectLog.cpp
170

I was hoping we could use a type alias for this, that marks eLogHandlerStream as eLogHandlerDefault but I couldn't find of a nice C++ way to do it :/

JDevlieghere marked 11 inline comments as done.Jun 22 2022, 3:03 PM
JDevlieghere added inline comments.
lldb/source/Commands/Options.td
438–439

I think the concept of a "log handler" is sufficiently well known that it should be easy for a a (power) user to understand. I'm concerned that "type" and "kind" are a tad too high level, and therefore could easily be confused with the log category and channel. For example, when someone asks to enable the "gdb packet log", is that a category, channel, type or kind?

lldb/source/Core/Debugger.cpp
1409–1411

What did you have in mind? We don't know a-priori what the type will be. You could template the function in the enum value, but you still wouldn't know which arguments to pass before dispatching to the right function.

JDevlieghere marked 2 inline comments as done.
clayborg added inline comments.Jun 23 2022, 3:55 PM
lldb/source/Commands/CommandObjectLog.cpp
26

Question: how does one see these values and their descriptions? Do the descriptions get displayed anywhere? If they do, then my comments below make sense, if the don't, then ignore below comments and maybe roll all that documentation into the main description for this command.

30

It doesn't seem very clear to the user what "stream" means here. Is says it will use one, but what is a stream? Maybe expand on this will output the log to the debugger stderr or to a file if used with the -f option? Maybe "default" is a better user facing term here?

34–35

circular makes more sense to use as the name IMHO. Not sure what rotating means for a log handler. Maybe expand on if this is enabled, you can see the cached log lines by using "log dump" and it will keep X amount of messages? Or does the user need to specify a size of a buffer somewhere?

40

Just saying that we will use the system log handler doesn't really explain what is going on here. Maybe "Log messages to the OS's default system log."

140–142

Can we also add the valid values that users can choose from in this error message? If the user types "log enable -h wrong", how does the user know what the valid values to use are?

lldb/source/Commands/Options.td
438–439

How can the user see the available options? I always have to type an incorrect value in for enums and then I see a correction saying "you can only specify 'a', 'b', or 'c'"

440–441

Should this be moved to the enum description?

JDevlieghere marked 6 inline comments as done.Jun 23 2022, 5:30 PM
JDevlieghere added a subscriber: jingham.
JDevlieghere added inline comments.
lldb/source/Commands/CommandObjectLog.cpp
26

The values are printed in the help output:

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

The usage/description is not. As far as I can tell, it isn't printed anywhere. I talked it over with @jingham and it should get printed in the help <log-hander> output but currently that's not the case.

(lldb) help <log-handler>
  <log-handler> -- The log handle that will be used to write out log messages.

To make that work we need to tie the actual enum to the ArgumentTableEntry in in CommandObject.cpp. I think that's something we should do, but that's outside the scope of this patch.

lldb/source/Commands/Options.td
438–439

This is part of the help output.

JDevlieghere marked 2 inline comments as done.
labath accepted this revision.Jun 24 2022, 6:43 AM
labath added inline comments.
lldb/source/Commands/CommandObjectLog.cpp
170

Were you maybe looking for something like:

enum {
 foo_1,
 foo_2,
 ...,
  foo_default = foo_47
};
This revision is now accepted and ready to land.Jun 24 2022, 6:43 AM

Add eLogHandlerDefault = eLogHandlerStream.

Improve help and error message

mib added inline comments.Jun 24 2022, 1:53 PM
lldb/source/Commands/CommandObjectLog.cpp
170

That could do :) ! I was thinking of doing :

enum {
foo_1,
foo_2,
...
};

using foo_default = foo_1;

But I don't think this works.

clayborg accepted this revision.Jun 24 2022, 2:20 PM
This revision was landed with ongoing or failed builds.Jun 24 2022, 6:24 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2022, 6:24 PM