Skip to content

Conversation

da-viper
Copy link
Contributor

@da-viper da-viper commented Oct 7, 2025

No description provided.

@da-viper da-viper requested a review from JDevlieghere as a code owner October 7, 2025 11:34
@da-viper da-viper requested a review from Michael137 October 7, 2025 14:06
Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good but this should come with a (PExpect) test.

@llvmbot llvmbot added the lldb label Oct 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 8, 2025

@llvm/pr-subscribers-lldb

Author: Ebuka Ezike (da-viper)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/162263.diff

2 Files Affected:

  • (modified) lldb/source/Core/IOHandler.cpp (+6-5)
  • (modified) lldb/test/API/driver/quit_speed/TestQuitWithProcess.py (+25)
diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp
index 57819eeade6e8..c2530aa0d00c5 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.equals_insensitive("yes")) {
     m_user_response = true;
     io_handler.SetIsDone(true);
-  } else if (line == "no" || line == "NO" || line == "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)

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@da-viper da-viper merged commit 8e62ace into llvm:main Oct 8, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants