[Lldb-commits] [lldb] r201744 - Don't have both lldb and debugserver call waitpid on the target process. This sets up a race condition,

Jim Ingham jingham at apple.com
Wed Feb 19 16:52:37 PST 2014


Author: jingham
Date: Wed Feb 19 18:52:37 2014
New Revision: 201744

URL: http://llvm.org/viewvc/llvm-project?rev=201744&view=rev
Log:
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.

<rdar://problem/16030008>

Modified:
    lldb/trunk/include/lldb/Target/Process.h
    lldb/trunk/include/lldb/lldb-enumerations.h
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp

Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=201744&r1=201743&r2=201744&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Wed Feb 19 18:52:37 2014
@@ -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,

Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=201744&r1=201743&r2=201744&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Wed Feb 19 18:52:37 2014
@@ -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;
         
     //----------------------------------------------------------------------

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=201744&r1=201743&r2=201744&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Wed Feb 19 18:52:37 2014
@@ -763,6 +763,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);
         process_sp = Platform::DebugProcess (launch_info, debugger, target, listener, error);
     }
     else





More information about the lldb-commits mailing list