Author: jingham Date: Tue Jun 24 16:51:42 2014 New Revision: 211636 URL: http://llvm.org/viewvc/llvm-project?rev=211636&view=rev Log: Rework fix in r201744. You really DO need to waitpid twice to get the process fully reaped. The race & bad behavior was because we were letting the reaping thread in LLDB to also set the Process exit status, so debugserver would sometimes be shut down before it got a chance to report the exit status, and then we got confused.
<rdar://problem/16555850> Modified: lldb/trunk/include/lldb/Target/Process.h lldb/trunk/include/lldb/lldb-enumerations.h lldb/trunk/source/Host/macosx/Host.mm lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp lldb/trunk/tools/debugserver/source/DNB.cpp Modified: lldb/trunk/include/lldb/Target/Process.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=211636&r1=211635&r2=211636&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Process.h (original) +++ lldb/trunk/include/lldb/Target/Process.h Tue Jun 24 16:51:42 2014 @@ -824,9 +824,6 @@ public: bool MonitorProcess () const { - if (GetFlags().Test(lldb::eLaunchFlagsDontMonitorProcess)) - return true; - if (m_monitor_callback && ProcessIDIsValid()) { Host::StartMonitoringChildProcess (m_monitor_callback, Modified: lldb/trunk/include/lldb/lldb-enumerations.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=211636&r1=211635&r2=211636&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-enumerations.h (original) +++ lldb/trunk/include/lldb/lldb-enumerations.h Tue Jun 24 16:51:42 2014 @@ -47,8 +47,8 @@ namespace lldb { eLaunchFlagLaunchInTTY = (1u << 5), ///< Launch the process in a new TTY if supported by the host eLaunchFlagLaunchInShell= (1u << 6), ///< Launch the process inside a shell to get shell expansion eLaunchFlagLaunchInSeparateProcessGroup = (1u << 7), ///< Launch the process in a separate process group - eLaunchFlagsDontMonitorProcess = (1u << 8) ///< If you are going to hand the process off (e.g. to debugserver) - ///< set this flag so lldb & the handee don't race to reap it. + eLaunchFlagsDontSetExitStatus = (1u << 8) ///< If you are going to hand the process off (e.g. to debugserver) + ///< set this flag so lldb & the handee don't race to set its exit status. } LaunchFlags; //---------------------------------------------------------------------- Modified: lldb/trunk/source/Host/macosx/Host.mm URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Host.mm?rev=211636&r1=211635&r2=211636&view=diff ============================================================================== --- lldb/trunk/source/Host/macosx/Host.mm (original) +++ lldb/trunk/source/Host/macosx/Host.mm Tue Jun 24 16:51:42 2014 @@ -1667,7 +1667,12 @@ Host::LaunchProcess (ProcessLaunchInfo & if (!launch_info.MonitorProcess()) { const bool monitor_signals = false; - StartMonitoringChildProcess (Process::SetProcessExitStatus, + Host::MonitorChildProcessCallback callback = nullptr; + + if (!launch_info.GetFlags().Test(lldb::eLaunchFlagsDontSetExitStatus)) + callback = Process::SetProcessExitStatus; + + StartMonitoringChildProcess (callback, NULL, pid, monitor_signals); Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp?rev=211636&r1=211635&r2=211636&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original) +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Tue Jun 24 16:51:42 2014 @@ -785,10 +785,10 @@ PlatformDarwin::DebugProcess (ProcessLau if (IsHost()) { - // We are going to hand this process off to debugserver which will monitor the process itself. - // So don't also monitor it from lldb or we set up a race between debugserver & us for who will find out - // about the debugged process's death. - launch_info.GetFlags().Set(eLaunchFlagsDontMonitorProcess); + // We are going to hand this process off to debugserver which will be in charge of setting the exit status. + // We still need to reap it from lldb but if we let the monitor thread also set the exit status, we set up a + // race between debugserver & us for who will find out about the debugged process's death. + launch_info.GetFlags().Set(eLaunchFlagsDontSetExitStatus); process_sp = Platform::DebugProcess (launch_info, debugger, target, listener, error); } else Modified: lldb/trunk/tools/debugserver/source/DNB.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/DNB.cpp?rev=211636&r1=211635&r2=211636&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/DNB.cpp (original) +++ lldb/trunk/tools/debugserver/source/DNB.cpp Tue Jun 24 16:51:42 2014 @@ -239,7 +239,7 @@ spawn_kqueue_thread (pid_t pid) struct kevent reg_event; - EV_SET(®_event, pid, EVFILT_PROC, EV_ADD, NOTE_EXIT|NOTE_EXIT_DETAIL, 0, NULL); + EV_SET(®_event, pid, EVFILT_PROC, EV_ADD, NOTE_EXIT|NOTE_EXITSTATUS|NOTE_EXIT_DETAIL, 0, NULL); // Register the event: int result = kevent (kq_id, ®_event, 1, NULL, 0, NULL); if (result != 0) _______________________________________________ lldb-commits mailing list lldb-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits