Skip to content

Commit 14bd14f

Browse files
committed
[lldb] Fix ^C handling in IOHandlerProcessSTDIO
D120762 accidentally moved the interrupt check into the block which was reading stdio. This meant that a ^C only took effect after a regular character has been pressed. This patch fixes that and adds a (pexpect) test. Differential Revision: https://reviews.llvm.org/D121912
1 parent 53e9ee3 commit 14bd14f

File tree

4 files changed

+66
-11
lines changed

4 files changed

+66
-11
lines changed

lldb/source/Target/Process.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4361,18 +4361,18 @@ class IOHandlerProcessSTDIO : public IOHandler {
43614361
break;
43624362
} else
43634363
break;
4364+
}
43644365

4365-
if (select_helper.FDIsSetRead(pipe_read_fd)) {
4366-
size_t bytes_read;
4367-
// Consume the interrupt byte
4368-
Status error = m_pipe.Read(&ch, 1, bytes_read);
4369-
if (error.Success()) {
4370-
if (ch == 'q')
4371-
break;
4372-
if (ch == 'i')
4373-
if (StateIsRunningState(m_process->GetState()))
4374-
m_process->SendAsyncInterrupt();
4375-
}
4366+
if (select_helper.FDIsSetRead(pipe_read_fd)) {
4367+
size_t bytes_read;
4368+
// Consume the interrupt byte
4369+
Status error = m_pipe.Read(&ch, 1, bytes_read);
4370+
if (error.Success()) {
4371+
if (ch == 'q')
4372+
break;
4373+
if (ch == 'i')
4374+
if (StateIsRunningState(m_process->GetState()))
4375+
m_process->SendAsyncInterrupt();
43764376
}
43774377
}
43784378
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include Makefile.rules
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Test sending SIGINT Process IOHandler
3+
"""
4+
5+
import os
6+
7+
import lldb
8+
from lldbsuite.test.decorators import *
9+
from lldbsuite.test.lldbtest import *
10+
from lldbsuite.test.lldbpexpect import PExpectTest
11+
12+
class TestCase(PExpectTest):
13+
14+
mydir = TestBase.compute_mydir(__file__)
15+
16+
def test(self):
17+
self.build(dictionary={"CXX_SOURCES":"cat.cpp"})
18+
self.launch(executable=self.getBuildArtifact(), timeout=5)
19+
20+
self.child.sendline("process launch")
21+
self.child.expect("Process .* launched")
22+
23+
self.child.sendline("Hello cat")
24+
self.child.expect_exact("read: Hello cat")
25+
26+
self.child.sendintr()
27+
self.child.expect("Process .* stopped")
28+
self.expect_prompt()
29+
30+
self.expect("bt", substrs=["input_copy_loop"])
31+
32+
self.child.sendline("continue")
33+
self.child.expect("Process .* resuming")
34+
35+
self.child.sendline("Goodbye cat")
36+
self.child.expect_exact("read: Goodbye cat")
37+
38+
self.child.sendeof()
39+
self.child.expect("Process .* exited")
40+
self.expect_prompt()
41+
42+
self.quit()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <iostream>
2+
3+
void input_copy_loop() {
4+
std::string str;
5+
while (std::getline(std::cin, str))
6+
std::cout << "read: " << str << std::endl;
7+
}
8+
9+
int main() {
10+
input_copy_loop();
11+
return 0;
12+
}

0 commit comments

Comments
 (0)