From d443c3f8906345beb4dcce5065befbbd9b030153 Mon Sep 17 00:00:00 2001 From: Ebuka Ezike Date: Tue, 7 Oct 2025 12:16:02 +0100 Subject: [PATCH 1/2] [lldb] Ignore trailing spaces on quit confirmation --- lldb/source/Core/IOHandler.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp index 57819eeade6e8..e97a730287cdc 100644 --- a/lldb/source/Core/IOHandler.cpp +++ b/lldb/source/Core/IOHandler.cpp @@ -152,15 +152,16 @@ void IOHandlerConfirm::IOHandlerComplete(IOHandler &io_handler, void IOHandlerConfirm::IOHandlerInputComplete(IOHandler &io_handler, std::string &line) { - if (line.empty()) { + const llvm::StringRef input = llvm::StringRef(line).rtrim(); + if (input.empty()) { // User just hit enter, set the response to the default m_user_response = m_default_response; io_handler.SetIsDone(true); return; } - if (line.size() == 1) { - switch (line[0]) { + if (input.size() == 1) { + switch (input[0]) { case 'y': case 'Y': m_user_response = true; @@ -176,10 +177,10 @@ void IOHandlerConfirm::IOHandlerInputComplete(IOHandler &io_handler, } } - if (line == "yes" || line == "YES" || line == "Yes") { + if (input.compare_insensitive("yes")) { m_user_response = true; io_handler.SetIsDone(true); - } else if (line == "no" || line == "NO" || line == "No") { + } else if (input.compare_insensitive("no")) { m_user_response = false; io_handler.SetIsDone(true); } From 46e5f467ec7d8d3bf7c63193affe389b2ff483a9 Mon Sep 17 00:00:00 2001 From: Ebuka Ezike Date: Wed, 8 Oct 2025 13:54:39 +0100 Subject: [PATCH 2/2] [lldb][test] add test case for trailing space --- lldb/source/Core/IOHandler.cpp | 4 +-- .../driver/quit_speed/TestQuitWithProcess.py | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp index e97a730287cdc..c2530aa0d00c5 100644 --- a/lldb/source/Core/IOHandler.cpp +++ b/lldb/source/Core/IOHandler.cpp @@ -177,10 +177,10 @@ void IOHandlerConfirm::IOHandlerInputComplete(IOHandler &io_handler, } } - if (input.compare_insensitive("yes")) { + if (input.equals_insensitive("yes")) { m_user_response = true; io_handler.SetIsDone(true); - } else if (input.compare_insensitive("no")) { + } else if (input.equals_insensitive("no")) { m_user_response = false; io_handler.SetIsDone(true); } diff --git a/lldb/test/API/driver/quit_speed/TestQuitWithProcess.py b/lldb/test/API/driver/quit_speed/TestQuitWithProcess.py index 2412b295bfb59..305e3cc397cf0 100644 --- a/lldb/test/API/driver/quit_speed/TestQuitWithProcess.py +++ b/lldb/test/API/driver/quit_speed/TestQuitWithProcess.py @@ -33,3 +33,28 @@ def test_run_quit(self): child.sendline("quit") print("sent quit") child.expect(pexpect.EOF, timeout=15) + + @skipIfAsan + def test_run_quit_with_prompt(self): + """Test that the lldb driver's batch mode works correctly with trailing space in confimation.""" + import pexpect + + self.build() + + exe = self.getBuildArtifact("a.out") + + self.launch(executable=exe) + child = self.child + + # Launch the process without a TTY so we don't have to interrupt: + child.sendline("process launch -n") + print("launched process") + child.expect(r"Process ([\d]*) launched:") + print("Got launch message") + child.sendline("quit") + print("sent quit") + + child.expect(r".*LLDB will kill one or more processes.*") + # add trailing space to the confirmation. + child.sendline("yEs ") + child.expect(pexpect.EOF, timeout=15)