<rdar://problem/11007934> 

On darwin, if child process of process being debugged dies due to mach exception, the debugged process will die.

debugserver now only handles the mach exceptions for the task being debugged.

llvm-svn: 152291
diff --git a/lldb/tools/debugserver/source/MacOSX/MachException.cpp b/lldb/tools/debugserver/source/MacOSX/MachException.cpp
index 7492e9a..ead512e 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachException.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/MachException.cpp
@@ -165,12 +165,16 @@
                         (uint64_t)(exc_data_count > 1 ? exc_data[1] : 0xBADDBADD));
     }
 
-    g_message->task_port = task_port;
-    g_message->thread_port = thread_port;
-    g_message->exc_type = exc_type;
-    g_message->exc_data.resize(exc_data_count);
-    ::memcpy (&g_message->exc_data[0], exc_data, g_message->exc_data.size() * sizeof (mach_exception_data_type_t));
-    return KERN_SUCCESS;
+    if (task_port == g_message->task_port)
+    {
+        g_message->task_port = task_port;
+        g_message->thread_port = thread_port;
+        g_message->exc_type = exc_type;
+        g_message->exc_data.resize(exc_data_count);
+        ::memcpy (&g_message->exc_data[0], exc_data, g_message->exc_data.size() * sizeof (mach_exception_data_type_t));
+        return KERN_SUCCESS;
+    }
+    return KERN_FAILURE;
 }
 
 
@@ -318,12 +322,13 @@
 }
 
 bool
-MachException::Message::CatchExceptionRaise()
+MachException::Message::CatchExceptionRaise(task_t task)
 {
     bool success = false;
     // locker will keep a mutex locked until it goes out of scope
 //    PThreadMutex::Locker locker(&g_message_mutex);
     //    DNBLogThreaded("calling  mach_exc_server");
+    state.task_port = task;
     g_message = &state;
     // The exc_server function is the MIG generated server handling function
     // to handle messages from the kernel relating to the occurrence of an
diff --git a/lldb/tools/debugserver/source/MacOSX/MachException.h b/lldb/tools/debugserver/source/MacOSX/MachException.h
index 330978b..08d22cd 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachException.h
+++ b/lldb/tools/debugserver/source/MacOSX/MachException.h
@@ -101,7 +101,7 @@
             memset(&exc_msg,   0, sizeof(exc_msg));
             memset(&reply_msg, 0, sizeof(reply_msg));
         }
-        bool CatchExceptionRaise();
+        bool CatchExceptionRaise(task_t task);
         void Dump() const;
         kern_return_t Reply (MachProcess *process, int signal);
         kern_return_t Receive( mach_port_t receive_port,
diff --git a/lldb/tools/debugserver/source/MacOSX/MachTask.cpp b/lldb/tools/debugserver/source/MacOSX/MachTask.cpp
index 869384c..14a8fca 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachTask.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/MachTask.cpp
@@ -592,7 +592,7 @@
         }
         else
         {
-            if (exception_message.CatchExceptionRaise())
+            if (exception_message.CatchExceptionRaise(task))
             {
                 ++num_exceptions_received;
                 mach_proc->ExceptionMessageReceived(exception_message);