[lldb] Fix a crash when tab-completion an empty line in a function with only one...
authorRaphael Isemann <teemperor@gmail.com>
Fri, 14 Aug 2020 06:49:01 +0000 (08:49 +0200)
committerRaphael Isemann <teemperor@gmail.com>
Fri, 14 Aug 2020 07:06:52 +0000 (09:06 +0200)
commitbbe3c479a6adf0abfe5d111e9ba206daa5a1eb2b
tree2893521a2b1f5f4f73f088c6a2008cf714349117
parent9aa0ff77bdc762b70123192d7f0bd3e95bc83788
[lldb] Fix a crash when tab-completion an empty line in a function with only one local variable

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.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D85903
lldb/source/Host/common/Editline.cpp
lldb/test/API/commands/expression/multiline-completion/TestMultilineCompletion.py
lldb/test/API/commands/expression/multiline-completion/main.c