Skip to content

[lldb] Don't save empty expressions in the multiline editor history #3213

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
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: 3 additions & 2 deletions lldb/source/Host/common/Editline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1554,8 +1554,9 @@ bool Editline::GetLines(int first_line_number, StringList &lines,

interrupted = m_editor_status == EditorStatus::Interrupted;
if (!interrupted) {
// Save the completed entry in history before returning
if (m_input_lines.size() > 1 || !m_input_lines[0].empty())
// Save the completed entry in history before returning. Don't save empty
// input as that just clutters the command history.
if (m_input_lines.size() > 1 || !m_input_lines.front().empty())
m_history_sp->Enter(CombineLines(m_input_lines).c_str());

lines = GetInputAsStringList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,33 @@ def test_nav_arrow_down(self):
@skipIfAsan
@skipIfEditlineSupportMissing
@expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr48316')
def test_nav_arrow_up_empty_pr49845(self):
"""Tests that navigating with the up arrow doesn't crash."""
@skipIf(oslist=["linux"], archs=["arm", "aarch64"]) # Randomly fails on buildbot
def test_nav_arrow_up_empty(self):
"""
Tests that navigating with the up arrow doesn't crash and skips
empty history entries.
"""
self.launch()

# Create an empty history session by only entering a newline.
# Create a real history entry '456' and then follow up with an
# empty entry (that shouldn't be saved).
self.child.sendline("expr")
self.child.expect_exact("terminate with an empty line to evaluate")
self.child.send("456\n\n")
self.expect_prompt()

self.child.sendline("expr")
self.child.expect_exact("terminate with an empty line to evaluate")
self.child.send("\n")
self.expect_prompt()

# Send just the up arrow in the expression evaluator. This should bring up the previous empty expression.
# The up arrow should recall the actual history entry and not the
# the empty entry (as that one shouldn't have been saved).
self.child.sendline("expr")
self.child.expect_exact("terminate with an empty line to evaluate")
self.child.send(self.arrow_up)
self.child.expect_exact("1: ")
self.child.send("\n")
self.child.expect_exact("456")
self.child.send("\n\n")
self.expect_prompt()

self.quit()