Fixed SBTarget attach calls to properly deal with being connected to a remotely
connected process connection.

Also added support for more kinds of continue packet when multiple threads
need to continue where some want to continue with signals.



git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@133785 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/API/SBTarget.cpp b/source/API/SBTarget.cpp
index 8ed525e..c1278e0 100644
--- a/source/API/SBTarget.cpp
+++ b/source/API/SBTarget.cpp
@@ -282,11 +282,43 @@
     if (m_opaque_sp)
     {
         Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
-        if (listener.IsValid())
-            sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
+
+        StateType state = eStateInvalid;
+        sb_process.SetProcess (m_opaque_sp->GetProcessSP());
+        if (sb_process.IsValid())
+        {
+            state = sb_process->GetState();
+            
+            if (sb_process->IsAlive() && state != eStateConnected)
+            {       
+                if (state == eStateAttaching)
+                    error.SetErrorString ("process attach is in progress");
+                else
+                    error.SetErrorString ("a process is already being debugged");
+                sb_process.Clear();
+                return sb_process;
+            }            
+        }
+
+        if (state == eStateConnected)
+        {
+            // If we are already connected, then we have already specified the
+            // listener, so if a valid listener is supplied, we need to error out
+            // to let the client know.
+            if (listener.IsValid())
+            {
+                error.SetErrorString ("process is connected and already has a listener, pass empty listener");
+                sb_process.Clear();
+                return sb_process;
+            }
+        }
         else
-            sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
-        
+        {
+            if (listener.IsValid())
+                sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
+            else
+                sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
+        }
 
         if (sb_process.IsValid())
         {
@@ -323,10 +355,42 @@
     {
         Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
 
-        if (listener.IsValid())
-            sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
+        StateType state = eStateInvalid;
+        sb_process.SetProcess (m_opaque_sp->GetProcessSP());
+        if (sb_process.IsValid())
+        {
+            state = sb_process->GetState();
+            
+            if (sb_process->IsAlive() && state != eStateConnected)
+            {       
+                if (state == eStateAttaching)
+                    error.SetErrorString ("process attach is in progress");
+                else
+                    error.SetErrorString ("a process is already being debugged");
+                sb_process.Clear();
+                return sb_process;
+            }            
+        }
+        
+        if (state == eStateConnected)
+        {
+            // If we are already connected, then we have already specified the
+            // listener, so if a valid listener is supplied, we need to error out
+            // to let the client know.
+            if (listener.IsValid())
+            {
+                error.SetErrorString ("process is connected and already has a listener, pass empty listener");
+                sb_process.Clear();
+                return sb_process;
+            }
+        }
         else
-            sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
+        {
+            if (listener.IsValid())
+                sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
+            else
+                sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
+        }
 
         if (sb_process.IsValid())
         {