Added a completion action class to the Process events so that we can make things like Attach and later Launch start their job, and then return to the event loop while waiting for the work to be done.


git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@124520 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Commands/CommandObjectProcess.cpp b/source/Commands/CommandObjectProcess.cpp
index 5239b7b..42bc4af 100644
--- a/source/Commands/CommandObjectProcess.cpp
+++ b/source/Commands/CommandObjectProcess.cpp
@@ -536,7 +536,8 @@
              CommandReturnObject &result)
     {
         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
-
+        bool synchronous_execution = m_interpreter.GetSynchronous ();
+        
         Process *process = m_interpreter.GetDebugger().GetExecutionContext().process;
         if (process)
         {
@@ -636,6 +637,24 @@
                         result.SetStatus (eReturnStatusFailed);
                         return false;                
                     }
+                    // If we're synchronous, wait for the stopped event and report that.
+                    // Otherwise just return.  
+                    // FIXME: in the async case it will now be possible to get to the command
+                    // interpreter with a state eStateAttaching.  Make sure we handle that correctly.
+                    if (synchronous_execution)
+                    {
+                        StateType state = process->WaitForProcessToStop (NULL);
+
+                        result.SetDidChangeProcessState (true);
+                        result.AppendMessageWithFormat ("Process %i %s\n", process->GetID(), StateAsCString (state));
+                        result.SetStatus (eReturnStatusSuccessFinishNoResult);
+                    }
+                    else
+                    {
+                        result.SetDidChangeProcessState (true);
+                        result.AppendMessageWithFormat ("Starting to attach to process.");
+                        result.SetStatus (eReturnStatusSuccessFinishNoResult);
+                    }
                 }
                 else
                 {
@@ -681,6 +700,21 @@
                                                          error.AsCString());
                             result.SetStatus (eReturnStatusFailed);
                         }
+                        // See comment for synchronous_execution above.
+                        if (synchronous_execution)
+                        {
+                            StateType state = process->WaitForProcessToStop (NULL);
+
+                            result.SetDidChangeProcessState (true);
+                            result.AppendMessageWithFormat ("Process %i %s\n", process->GetID(), StateAsCString (state));
+                            result.SetStatus (eReturnStatusSuccessFinishNoResult);
+                        }
+                        else
+                        {
+                            result.SetDidChangeProcessState (true);
+                            result.AppendMessageWithFormat ("Starting to attach to process.");
+                            result.SetStatus (eReturnStatusSuccessFinishNoResult);
+                        }
                     }
                     else
                     {