[Lldb-commits] [lldb] r201896 - We have to call waitpid on the lldb side for Mac OS X (even though we've successfully called it

Jim Ingham jingham at apple.com
Fri Feb 21 14:35:29 PST 2014


Author: jingham
Date: Fri Feb 21 16:35:29 2014
New Revision: 201896

URL: http://llvm.org/viewvc/llvm-project?rev=201896&view=rev
Log:
We have to call waitpid on the lldb side for Mac OS X (even though we've successfully called it
on the debugserver side) when we kill a process or it leaves a zombie around.

Modified:
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=201896&r1=201895&r2=201896&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Fri Feb 21 16:35:29 2014
@@ -2022,6 +2022,24 @@ ProcessGDBRemote::DoDestroy ()
 
                 if (packet_cmd == 'W' || packet_cmd == 'X')
                 {
+#if 0 && defined(__APPLE__)
+                    // For Native processes on Mac OS X, we launch through the Host Platform, then hand the process off
+                    // to debugserver, which becomes the parent process through "PT_ATTACH".  Then when we go to kill
+                    // the process on Mac OS X we call ptrace(PT_KILL) to kill it, then we call waitpid which returns
+                    // with no error and the correct status.  But amusingly enough that doesn't seem to actually reap
+                    // the process, but instead it is left around as a Zombie.  Probably the kernel is in the process of
+                    // switching ownership back to lldb which was the original parent, and gets confused in the handoff.
+                    // Anyway, so call waitpid here to finally reap it.
+                    PlatformSP platform_sp(GetTarget().GetPlatform());
+                    if (platform_sp && platform_sp->IsHost())
+                    {
+                        int status;
+                        ::pid_t reap_pid;
+                        reap_pid = waitpid (GetID(), &status, WNOHANG);
+                        if (log)
+                            log->Printf ("Reaped pid: %d, status: %d.\n", reap_pid, status);
+                    }
+#endif
                     SetLastStopPacket (response);
                     ClearThreadIDList ();
                     exit_status = response.GetHexU8();





More information about the lldb-commits mailing list