This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Fix a crash when tab-completion an empty line in a function with only one local variable
ClosedPublic

Authored by teemperor on Aug 13 2020, 6:05 AM.

Details

Summary

When LLDB sees only one possible completion for an input, it will add a trailing space to
the completion to signal that to the user. If the current argument is quoted, that also means
LLDB needs to add the trailing quote to finish the current argument first.

In case the user is in a function with only one local variable and is currently editing an
empty line in the multiline expression editor, then we are in the unique situation where
we can have a unique completion for an empty input line. (In a normal LLDB session this
would never occur as empty input would just list all the possible commands).

In this special situation our check if the current argument needs to receive a trailing quote
will crash LLDB as there is no current argument and the completion code just unconditionally
tries to access the current argument. This just adds the missing check if we even have
a current argument before we check if we need to add a terminating quote character.

Diff Detail

Event Timeline

teemperor requested review of this revision.Aug 13 2020, 6:05 AM
teemperor created this revision.
labath accepted this revision.Aug 13 2020, 6:20 AM

Haha, cute bug.

lldb/test/API/commands/expression/multiline-completion/TestMultilineCompletion.py
17

I don't think this variable is useful if it's used only once.

24–25

This description is not correct. The first \n will finish the existing line, and the second \n will create an new empty line (which will exit the editor).

And this assumes that the initial line will already contain some data. Otherwise the first \n will exit the editor, and the second \n will re-execute the previous command, reentering the expression editor:P

Might be best to send a single space before the newlines to ensure the desired interpretation.

This revision is now accepted and ready to land.Aug 13 2020, 6:20 AM
teemperor updated this revision to Diff 285359.Aug 13 2020, 6:51 AM
  • Remove variable.
  • Add a leading space before the two newlines and update description (Thanks Pavel!)
Herald added a project: Restricted Project. · View Herald TranscriptAug 14 2020, 12:07 AM