Skip to content

Commit 6b68342

Browse files
labathJDevlieghere
authored andcommitted
[lldb] Fix TestProcessIOHandlerInterrupt.py for macos
On darwin, we don't completely suppress the signal used to interrupt the inferior. The underlying read syscall returns EINTR, which causes premature termination of the input loop. Work around that by hand-rolling an EINTR-resistant version of getline. (cherry picked from commit a4d6de2)
1 parent 60ff1e4 commit 6b68342

File tree

1 file changed

+19
-3
lines changed
  • lldb/test/API/iohandler/sigint

1 file changed

+19
-3
lines changed

lldb/test/API/iohandler/sigint/cat.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1-
#include <iostream>
1+
#include <cstdio>
2+
#include <string>
3+
#include <unistd.h>
4+
5+
std::string getline() {
6+
std::string result;
7+
while (true) {
8+
int r;
9+
char c;
10+
do
11+
r = read(fileno(stdin), &c, 1);
12+
while (r == -1 && errno == EINTR);
13+
if (r <= 0 || c == '\n')
14+
return result;
15+
result += c;
16+
}
17+
}
218

319
void input_copy_loop() {
420
std::string str;
5-
while (std::getline(std::cin, str))
6-
std::cout << "read: " << str << std::endl;
21+
while (str = getline(), !str.empty())
22+
printf("read: %s\n", str.c_str());
723
}
824

925
int main() {

0 commit comments

Comments
 (0)