[Lldb-commits] [lldb] a4d6de2 - [lldb] Fix TestProcessIOHandlerInterrupt.py for macos

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Fri Mar 18 03:52:05 PDT 2022


Author: Pavel Labath
Date: 2022-03-18T11:51:55+01:00
New Revision: a4d6de2031ad2f92d399fc8d1b1301229ed8255b

URL: https://github.com/llvm/llvm-project/commit/a4d6de2031ad2f92d399fc8d1b1301229ed8255b
DIFF: https://github.com/llvm/llvm-project/commit/a4d6de2031ad2f92d399fc8d1b1301229ed8255b.diff

LOG: [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.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lldb/test/API/iohandler/sigint/cat.cpp b/lldb/test/API/iohandler/sigint/cat.cpp
index 5a3d9380e3826..7e12cf7df7e58 100644
--- a/lldb/test/API/iohandler/sigint/cat.cpp
+++ b/lldb/test/API/iohandler/sigint/cat.cpp
@@ -1,9 +1,25 @@
-#include <iostream>
+#include <cstdio>
+#include <string>
+#include <unistd.h>
+
+std::string getline() {
+  std::string result;
+  while (true) {
+    int r;
+    char c;
+    do
+      r = read(fileno(stdin), &c, 1);
+    while (r == -1 && errno == EINTR);
+    if (r <= 0 || c == '\n')
+      return result;
+    result += c;
+  }
+}
 
 void input_copy_loop() {
   std::string str;
-  while (std::getline(std::cin, str))
-    std::cout << "read: " << str << std::endl;
+  while (str = getline(), !str.empty())
+    printf("read: %s\n", str.c_str());
 }
 
 int main() {


        


More information about the lldb-commits mailing list