Skip to content

Commit 2b65f5e

Browse files
authored
Merge pull request #3213 from Teemperor/cherry/4f7fb13f87e10bd2cd89ccf2be70b026032237a7
[lldb] Don't save empty expressions in the multiline editor history
2 parents c6a6439 + fc545f5 commit 2b65f5e

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

lldb/source/Host/common/Editline.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,8 +1554,9 @@ bool Editline::GetLines(int first_line_number, StringList &lines,
15541554

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

15611562
lines = GetInputAsStringList();

lldb/test/API/commands/expression/multiline-navigation/TestMultilineNavigation.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,33 @@ def test_nav_arrow_down(self):
7373
@skipIfAsan
7474
@skipIfEditlineSupportMissing
7575
@expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr48316')
76-
def test_nav_arrow_up_empty_pr49845(self):
77-
"""Tests that navigating with the up arrow doesn't crash."""
76+
@skipIf(oslist=["linux"], archs=["arm", "aarch64"]) # Randomly fails on buildbot
77+
def test_nav_arrow_up_empty(self):
78+
"""
79+
Tests that navigating with the up arrow doesn't crash and skips
80+
empty history entries.
81+
"""
7882
self.launch()
7983

80-
# Create an empty history session by only entering a newline.
84+
# Create a real history entry '456' and then follow up with an
85+
# empty entry (that shouldn't be saved).
86+
self.child.sendline("expr")
87+
self.child.expect_exact("terminate with an empty line to evaluate")
88+
self.child.send("456\n\n")
89+
self.expect_prompt()
90+
8191
self.child.sendline("expr")
8292
self.child.expect_exact("terminate with an empty line to evaluate")
8393
self.child.send("\n")
8494
self.expect_prompt()
8595

86-
# Send just the up arrow in the expression evaluator. This should bring up the previous empty expression.
96+
# The up arrow should recall the actual history entry and not the
97+
# the empty entry (as that one shouldn't have been saved).
8798
self.child.sendline("expr")
8899
self.child.expect_exact("terminate with an empty line to evaluate")
89100
self.child.send(self.arrow_up)
90-
self.child.expect_exact("1: ")
91-
self.child.send("\n")
101+
self.child.expect_exact("456")
102+
self.child.send("\n\n")
92103
self.expect_prompt()
93104

94105
self.quit()

0 commit comments

Comments
 (0)