Skip to content

Commit 8e62ace

Browse files
authored
[lldb] Ignore trailing spaces on quit confirmation (#162263)
1 parent 466f691 commit 8e62ace

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

lldb/source/Core/IOHandler.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,16 @@ void IOHandlerConfirm::IOHandlerComplete(IOHandler &io_handler,
152152

153153
void IOHandlerConfirm::IOHandlerInputComplete(IOHandler &io_handler,
154154
std::string &line) {
155-
if (line.empty()) {
155+
const llvm::StringRef input = llvm::StringRef(line).rtrim();
156+
if (input.empty()) {
156157
// User just hit enter, set the response to the default
157158
m_user_response = m_default_response;
158159
io_handler.SetIsDone(true);
159160
return;
160161
}
161162

162-
if (line.size() == 1) {
163-
switch (line[0]) {
163+
if (input.size() == 1) {
164+
switch (input[0]) {
164165
case 'y':
165166
case 'Y':
166167
m_user_response = true;
@@ -176,10 +177,10 @@ void IOHandlerConfirm::IOHandlerInputComplete(IOHandler &io_handler,
176177
}
177178
}
178179

179-
if (line == "yes" || line == "YES" || line == "Yes") {
180+
if (input.equals_insensitive("yes")) {
180181
m_user_response = true;
181182
io_handler.SetIsDone(true);
182-
} else if (line == "no" || line == "NO" || line == "No") {
183+
} else if (input.equals_insensitive("no")) {
183184
m_user_response = false;
184185
io_handler.SetIsDone(true);
185186
}

lldb/test/API/driver/quit_speed/TestQuitWithProcess.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,28 @@ def test_run_quit(self):
3333
child.sendline("quit")
3434
print("sent quit")
3535
child.expect(pexpect.EOF, timeout=15)
36+
37+
@skipIfAsan
38+
def test_run_quit_with_prompt(self):
39+
"""Test that the lldb driver's batch mode works correctly with trailing space in confimation."""
40+
import pexpect
41+
42+
self.build()
43+
44+
exe = self.getBuildArtifact("a.out")
45+
46+
self.launch(executable=exe)
47+
child = self.child
48+
49+
# Launch the process without a TTY so we don't have to interrupt:
50+
child.sendline("process launch -n")
51+
print("launched process")
52+
child.expect(r"Process ([\d]*) launched:")
53+
print("Got launch message")
54+
child.sendline("quit")
55+
print("sent quit")
56+
57+
child.expect(r".*LLDB will kill one or more processes.*")
58+
# add trailing space to the confirmation.
59+
child.sendline("yEs ")
60+
child.expect(pexpect.EOF, timeout=15)

0 commit comments

Comments
 (0)