From ff26163768b5421f089e670bb66ee20445030fd9 Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Thu, 20 Feb 2014 00:52:37 +0000 Subject: [PATCH] Don't have both lldb and debugserver call waitpid on the target process. This sets up a race condition, and if lldb wins, then debugserver won't get the correct error status to lldb. llvm-svn: 201744 --- lldb/include/lldb/Target/Process.h | 7 +++++++ lldb/include/lldb/lldb-enumerations.h | 4 +++- lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index f52b54da52cf..b74347d37e68 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -815,9 +815,16 @@ public: return m_monitor_callback_baton; } + // If the LaunchInfo has a monitor callback, then arrange to monitor the process. + // Return true if the LaunchInfo has taken care of monitoring the process, and false if the + // caller might want to monitor the process themselves. + bool MonitorProcess () const { + if (GetFlags().Test(lldb::eLaunchFlagsDontMonitorProcess)) + return true; + if (m_monitor_callback && ProcessIDIsValid()) { Host::StartMonitoringChildProcess (m_monitor_callback, diff --git a/lldb/include/lldb/lldb-enumerations.h b/lldb/include/lldb/lldb-enumerations.h index c8294960a7b2..347e20f21df6 100644 --- a/lldb/include/lldb/lldb-enumerations.h +++ b/lldb/include/lldb/lldb-enumerations.h @@ -46,7 +46,9 @@ namespace lldb { eLaunchFlagDisableSTDIO = (1u << 4), ///< Disable stdio for inferior process (e.g. for a GUI app) 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 + 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. } LaunchFlags; //---------------------------------------------------------------------- diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 79e3236bac97..3ff620da8408 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -763,6 +763,10 @@ PlatformDarwin::DebugProcess (ProcessLaunchInfo &launch_info, 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); process_sp = Platform::DebugProcess (launch_info, debugger, target, listener, error); } else