Skip to content

Commit 80e9558

Browse files
committed
[debugserver] Add one additional sleep before attaching after waiting
It's possible for debugserver to attach to a process during the handoff between /usr/lib/dyld and the dyld in the shared cache. When that happens, we may end up in a state where there is no dyld in the process and our debugging session is doomed. To make that scenario a lot less likely, we can insert a sleep right before attaching after waiting to find the right pid. rdar://105513180 Differential Revision: https://reviews.llvm.org/D144311 (cherry picked from commit 97b579d)
1 parent bd79e28 commit 80e9558

File tree

1 file changed

+8
-0
lines changed
  • lldb/tools/debugserver/source

1 file changed

+8
-0
lines changed

lldb/tools/debugserver/source/DNB.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,14 @@ DNBProcessAttachWait(RNBContext *ctx, const char *waitfor_process_name,
793793
if (waitfor_pid != INVALID_NUB_PROCESS) {
794794
DNBLogThreadedIf(LOG_PROCESS, "Attaching to %s with pid %i...\n",
795795
waitfor_process_name, waitfor_pid);
796+
// In some cases, we attempt to attach during the transition from
797+
// /usr/lib/dyld to the dyld in the shared cache. If that happens, we may
798+
// end up in a state where there is no dyld in the process and from there
799+
// the debugging session is doomed.
800+
// In an attempt to make this scenario much less likely, we sleep
801+
// for an additional `waitfor_interval` number of microseconds before
802+
// attaching.
803+
::usleep(waitfor_interval);
796804
waitfor_pid = DNBProcessAttach(waitfor_pid, timeout_abstime,
797805
ctx->GetIgnoredExceptions(), err_str,
798806
err_len);

0 commit comments

Comments
 (0)