Skip to content

[LLDB] Fix completion of space-only lines in the REPL on Linux #83203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lldb/source/Host/common/Editline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,11 @@ unsigned char Editline::TabCommand(int ch) {
case CompletionMode::Normal: {
std::string to_add = completion.GetCompletion();
// Terminate the current argument with a quote if it started with a quote.
if (!request.GetParsedLine().empty() && request.GetParsedArg().IsQuoted())
Args &parsedLine = request.GetParsedLine();
if (!parsedLine.empty() && request.GetCursorIndex() < parsedLine.size() &&
request.GetParsedArg().IsQuoted()) {
to_add.push_back(request.GetParsedArg().GetQuoteChar());
}
to_add.push_back(' ');
el_deletestr(m_editline, request.GetCursorArgumentPrefix().size());
el_insertstr(m_editline, to_add.c_str());
Expand Down
32 changes: 23 additions & 9 deletions lldb/test/API/repl/clang/TestClangREPL.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test.lldbpexpect import PExpectTest
from lldbsuite.test.lldbtest import *


class TestCase(PExpectTest):
Expand All @@ -17,13 +16,7 @@ def expect_repl(self, expr, substrs=[]):
self.current_repl_line_number += 1
self.child.expect_exact(str(self.current_repl_line_number) + ">")

# PExpect uses many timeouts internally and doesn't play well
# under ASAN on a loaded machine..
@skipIfAsan
@skipIf(oslist=["linux"], archs=["arm", "aarch64"]) # Randomly fails on buildbot
@skipIfEditlineSupportMissing
def test_basic_completion(self):
"""Test that we can complete a simple multiline expression"""
def start_repl(self):
self.build()
self.current_repl_line_number = 1

Expand All @@ -41,6 +34,14 @@ def test_basic_completion(self):
self.child.send("expression --repl -l c --\n")
self.child.expect_exact("1>")

# PExpect uses many timeouts internally and doesn't play well
# under ASAN on a loaded machine..
@skipIfAsan
@skipIf(oslist=["linux"], archs=["arm", "aarch64"]) # Randomly fails on buildbot
@skipIfEditlineSupportMissing
def test_basic_completion(self):
"""Test that we can complete a simple multiline expression"""
self.start_repl()
# Try evaluating a simple expression.
self.expect_repl("3 + 3", substrs=["(int) $0 = 6"])

Expand All @@ -54,3 +55,16 @@ def test_basic_completion(self):
self.expect_repl("$persistent + 10", substrs=["(long) $2 = 17"])

self.quit()

# PExpect uses many timeouts internally and doesn't play well
# under ASAN on a loaded machine..
@skipIfAsan
@skipIf(oslist=["linux"], archs=["arm", "aarch64"]) # Randomly fails on buildbot
@skipIfEditlineSupportMissing
def test_completion_with_space_only_line(self):
"""Test that we don't crash when completing lines with spaces only"""
self.start_repl()

self.child.send(" ")
self.child.send("\t")
self.expect_repl("3 + 3", substrs=["(int) $0 = 6"])