diff options
author | Jason Molenda <jmolenda@apple.com> | 2024-03-12 09:03:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-12 09:03:28 -0700 |
commit | 87dc068280aaddc98acb7865ae3df1d248f4a170 (patch) | |
tree | 57fa7cd85fa18b4e564d2fa08ecdcc89035e76f1 /lldb/tools | |
parent | 0ebf511ad011a83022edb171e044c98d9d16b1fa (diff) | |
download | llvm-87dc068280aaddc98acb7865ae3df1d248f4a170.zip llvm-87dc068280aaddc98acb7865ae3df1d248f4a170.tar.gz llvm-87dc068280aaddc98acb7865ae3df1d248f4a170.tar.bz2 |
[lldb] [debugserver] Handle interrupted reads correctly (#84872)
The first half of this patch is a long-standing annoyance, if I attach
to debugserver with lldb while it is waiting for an lldb connection, the
syscall is interrupted and it doesn't retry, debugserver exits
immediately.
The second half is a request from another tool that is communicating
with debugserver, that we retry reads on our sockets in the same way. I
haven't dug in to the details of how they're communicating that this is
necessary, but the best I've been able to find reading the POSIX API
docs, this is fine.
rdar://117113298
Diffstat (limited to 'lldb/tools')
-rw-r--r-- | lldb/tools/debugserver/source/RNBSocket.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lldb/tools/debugserver/source/RNBSocket.cpp b/lldb/tools/debugserver/source/RNBSocket.cpp index 1282ea2..fc55dbf 100644 --- a/lldb/tools/debugserver/source/RNBSocket.cpp +++ b/lldb/tools/debugserver/source/RNBSocket.cpp @@ -120,8 +120,13 @@ rnb_err_t RNBSocket::Listen(const char *listen_host, uint16_t port, while (!accept_connection) { struct kevent event_list[4]; - int num_events = - kevent(queue_id, events.data(), events.size(), event_list, 4, NULL); + int num_events; + do { + errno = 0; + num_events = + kevent(queue_id, events.data(), events.size(), event_list, 4, NULL); + } while (num_events == -1 && + (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)); if (num_events < 0) { err.SetError(errno, DNBError::MachKernel); @@ -291,7 +296,12 @@ rnb_err_t RNBSocket::Read(std::string &p) { // DNBLogThreadedIf(LOG_RNB_COMM, "%8u RNBSocket::%s calling read()", // (uint32_t)m_timer.ElapsedMicroSeconds(true), __FUNCTION__); DNBError err; - ssize_t bytesread = read(m_fd, buf, sizeof(buf)); + ssize_t bytesread; + do { + errno = 0; + bytesread = read(m_fd, buf, sizeof(buf)); + } while (bytesread == -1 && + (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)); if (bytesread <= 0) err.SetError(errno, DNBError::POSIX); else |