[Lldb-commits] [PATCH] D42206: If kevent() is interrupted by signal (or is being debugged) and we get EINTR, retry

Jason Molenda via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Jan 17 15:30:15 PST 2018


jasonmolenda created this revision.
jasonmolenda added a reviewer: davide.
jasonmolenda added a project: LLDB.
Herald added subscribers: llvm-commits, JDevlieghere.

I hit this while trying to debug lldb-server.  When lldb-server is waiting for connections, it will be in MainLoop::RunImpl::Poll(), in the kevent() call.  On darwin systems, attaching to the process (or interrupting it to add a breakpoint or detach) will interrupt the system call it is sitting in.  We will get back an error return value (-1) and errno will be set to EINTR.

Currently we flag this as an error and lldb-server exits with

error: IO object is not valid.

which makes it a bit difficult to debug.

This section of code is only used on the *BSD systems and Darwin (it's #ifdef'ed HAVE_SYS_EVENT_H).  I tested it on Darwin and on Linux (before noticing that linux doesn't have sys/event.h) but don't have access to a *BSD system.  I don't expect any problems handling the interrupted kevent() call on those systems as I'm doing here.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D42206

Files:
  source/Host/common/MainLoop.cpp


Index: source/Host/common/MainLoop.cpp
===================================================================
--- source/Host/common/MainLoop.cpp
+++ source/Host/common/MainLoop.cpp
@@ -105,8 +105,11 @@
   for (auto &fd : loop.m_read_fds)
     EV_SET(&in_events[i++], fd.first, EVFILT_READ, EV_ADD, 0, 0, 0);
 
-  num_events = kevent(loop.m_kqueue, in_events.data(), in_events.size(),
-                      out_events, llvm::array_lengthof(out_events), nullptr);
+  do {
+    errno = 0;
+    num_events = kevent(loop.m_kqueue, in_events.data(), in_events.size(),
+                        out_events, llvm::array_lengthof(out_events), nullptr);
+  } while (num_events == -1 && errno == EINTR);
 
   if (num_events < 0)
     return Status("kevent() failed with error %d\n", num_events);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42206.130292.patch
Type: text/x-patch
Size: 783 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180117/d0418e10/attachment-0001.bin>


More information about the lldb-commits mailing list