This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add the ability to silently import scripted commands
ClosedPublic

Authored by JDevlieghere on Jul 1 2021, 6:12 PM.

Details

Summary

Add the ability to silence command script import. The motivation for this change is being able to add command script import -s lldb.macosx.crashlog to your ~/.lldbinit without it printing

"malloc_info", "ptr_refs", "cstr_refs", "find_variable", and "objc_refs" commands have been installed, use the "--help" options on these commands for detailed help.

at the beginning of every debug session.

In addition to forwarding the silent option to LoadScriptingModule, this also changes ScriptInterpreterPythonImpl::ExecuteOneLineWithReturn and ScriptInterpreterPythonImpl::ExecuteMultipleLines to honor the enable IO option in ExecuteScriptOptions, which until now was ignored. Note that IO is only enabled (or disabled) at the start of a session, and for this particular use case, that's done when taking the Python lock in LoadScriptingModule, which means that the changes to these two functions are not strictly necessary, but (IMO) desirable nonetheless.

Diff Detail

Event Timeline

JDevlieghere created this revision.Jul 1 2021, 6:12 PM
JDevlieghere requested review of this revision.Jul 1 2021, 6:12 PM
JDevlieghere edited the summary of this revision. (Show Details)Jul 2 2021, 11:34 AM
shafik added a subscriber: shafik.Jul 6 2021, 9:31 PM
shafik added inline comments.
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
1082

/*result=*/nullptr

1208

/*result=*/nullptr

2779

/*result=*/nullptr

2795–2797

Not sure how I feel about using 0 as kind of a noop for an enum rather then explicitly name it as such.

2799

&directory so we are explicit about what we are capturing.

2892–2893

This is super confusing to read with the outer parens, it looks like the whole expression is being passed to a function.

It looks similar to an if statement further down.

teemperor accepted this revision.Jul 7 2021, 3:50 AM

LGTM, thanks!

lldb/include/lldb/Interpreter/ScriptInterpreter.h
534

I think this case where we have two bools next to each other is a good place to actually use the bugprone-arg-comment's /*silent=*/ comments to have a way to actually check that those don't get mixed up. (Or we could make it a dedicated enum which I know you're a big fan of)

lldb/source/Commands/Options.td
749

don't print any script output because we would still print LLDB errors and what not.

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
1212

no curly braces around if

This revision is now accepted and ready to land.Jul 7 2021, 3:50 AM
JDevlieghere updated this revision to Diff 357037.EditedJul 7 2021, 12:07 PM
JDevlieghere marked 3 inline comments as done.
  • Rebase
  • Address code review feedback
  • Use LoadScriptOptions
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
2795–2797

FWIW this is all copied from other uses of the locker.

2799

I can't find it in the LLVM coding standards, but I believe it's common in LLVM to capture everything, or at least I've gotten that feedback in past code reviews.

We also have the notion of a IOHandler being interactive or not:

bool IOHandler::GetIsInteractive();

Maybe we can use this to set the "silent" option in the LoadScriptOptions object correctly in more cases than just when the user specifies the option?

lldb/source/Core/Module.cpp
1531

Do we want to default to silent here?

lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
94

Do we not want to default to silent here?

I think the only time we should not be silent is when the user types "command script import" from an interactive terminal. If this command comes in from the equivalent of "command source ...", sourcing init files then that IOHandler isn't interactive and we can easily suppress this.

Scripts can actually do work when they get imported (not just register commands) and you might for instance command script import a module that's going to do some work & present output in a breakpoint command or stop hook. But breakpoint commands and stop hooks are not interactive. So I'm a little hesitant about ganging "suppress output" and "interactive".

Jim

JDevlieghere marked an inline comment as done.Jul 9 2021, 9:55 AM

I kept the existing behavior everywhere except when --silent is passed. I also don't think "being interactive" is a good enough discriminator, I can imagine some people might want to see the work done by the script. Happy to revisit all of that in a separate patch though.

This revision was landed with ongoing or failed builds.Jul 9 2021, 10:05 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 9 2021, 10:05 AM