This is an archive of the discontinued LLVM Phabricator instance.

[lldb/crashlog] Make interactive mode the new default
AcceptedPublic

Authored by mib on Jan 12 2023, 11:03 PM.

Details

Summary

This patch makes interactive mode as the default when using the crashlog
command. It replaces the existing -i|--interactive flag with a new
-m|--mode option, that can either be interactive or batch.

By default, when the option is not explicitely set by the user, the
interactive mode is selected, however, lldb will fallback to batch
mode if the command interpreter is not interactive or if stdout is not
a tty.

This also adds some railguards to prevent users from using interactive
only options with the batch mode and updates the tests accordingly.

rdar://97801509

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>

Diff Detail

Event Timeline

mib created this revision.Jan 12 2023, 11:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2023, 11:03 PM
mib requested review of this revision.Jan 12 2023, 11:03 PM
mib retitled this revision from [lldb/crashlog] Make interactive mode a default & report progress on image loading to [lldb/crashlog] Default interactive mode & report progress on image loading.Jan 12 2023, 11:04 PM
mib removed a project: Restricted Project.
Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2023, 11:04 PM

Switching the default over seems fine. The symbol lookup stuff seems orthogonal to that and maybe should be its own patch?

lldb/examples/python/crashlog.py
452–457

It's not obvious why this is necessary (and we can't rely on open/the OS to do this for us) so let's add a comment.

1111–1113

Background lookup is lazy: it's only going to start looking for symbols after we've determined they might be of interest. Right now that means after seeing an imagine in the backtrace. Without anything else, the first backtrace is still going be unsymbolicated (unless we had the symbols already available on the host).

It seems like you're doing the symbol loading explicitly in the C++ implementation of the scripted process, so what's depending on this?

mib updated this revision to Diff 489042.Jan 13 2023, 9:44 AM
mib marked 2 inline comments as done.
mib retitled this revision from [lldb/crashlog] Default interactive mode & report progress on image loading to [lldb/crashlog] Make interactive mode the new default.
mib edited the summary of this revision. (Show Details)

Address @JDevlieghere comments:

  • Move module loading logic to separate patch D141702
  • Remove use of background symbol lookup

Another nice addition here would be checking if stdout is a tty (sys.stdout.isatty()) and continuing to use the textual format if it isn't. A quick experiment seems to show this does the right thing from inside LLDB:

$ echo -e "script\nimport sys\nsys.stdout.isatty()" | lldb -b
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> >>> True
now exiting InteractiveConsole...
$ echo -e "script\nimport sys\nsys.stdout.isatty()" | lldb -b | tail
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.

now exiting InteractiveConsole...
(lldb) script
>>> >>> False
lldb/examples/python/crashlog.py
1306

Spurious print? It doesn't look like we're printing a double newline elsewhere.

mib added inline comments.Jan 13 2023, 10:04 AM
lldb/examples/python/crashlog.py
452–457

From my experience, open

1306

I wanted to leave space between the actual error message and the help

mib updated this revision to Diff 489151.Jan 13 2023, 4:24 PM
mib marked an inline comment as not done.

Address @JDevlieghere comment:

  • Check is stdout is a tty to run in interactive mode
  • Remove extra return line
JDevlieghere accepted this revision.Jan 13 2023, 4:27 PM

LGTM. You can remove one of the -b in the test to check the TTY stuff (it should be false when piping into FileCheck).

lldb/examples/python/crashlog.py
1306

I like this

This revision is now accepted and ready to land.Jan 13 2023, 4:27 PM
mib updated this revision to Diff 493456.Jan 30 2023, 5:13 PM
mib edited the summary of this revision. (Show Details)

Fix test failures:

  • Change -b|--batch flag to -m|--mode options that expects an enum value.
mib marked 2 inline comments as done.Jan 30 2023, 5:13 PM
mib added inline comments.
lldb/examples/python/crashlog.py
452–457

I started replying to your message but I ended up adding a comment of the file directly.

mib requested review of this revision.EditedJan 30 2023, 5:15 PM

I changed the implementation to be able to fix the tests. Could you guys please take another look ?

bulbazord accepted this revision.Jan 31 2023, 11:31 AM

I like this. I have no opinion on having -i/-b versus --mode/-m to indicate which mode crashlog.py should use, though I think that using an enum makes it easier to add new modes down the line so I'm okay with this implementation (note: I can't think of any other kinds of modes I would add later).

LGTM, @JDevlieghere any objections?

lldb/examples/python/crashlog.py
47

nit: no need to remove this line.

This revision is now accepted and ready to land.Jan 31 2023, 11:31 AM
JDevlieghere added inline comments.Feb 6 2023, 11:21 AM
lldb/examples/python/crashlog.py
1148

This can be interpreted as the textual crashlogs going away which isn't the case or the goal. I think this should say "textual" (although that might be confusing with the JSON/text input) or maybe "batch".

mib updated this revision to Diff 495938.Feb 8 2023, 1:27 PM
mib marked an inline comment as done.

Address @JDevlieghere feedback: rename legacy loading mode into batch.

mib updated this revision to Diff 495939.Feb 8 2023, 1:28 PM
mib edited the summary of this revision. (Show Details)