Fixed CommandReturnObject::SetImmediateErrorFile() to set the correct stream.

Modifed lldb_private::Process to be able to handle connecting to a remote 
target that isn't running a process. This leaves lldb_private::Process in the
eStateConnected state from which we can then do an attach or launch.

Modified ProcessGDBRemote to be able to set stdin, stdout, stderr, working
dir, disable ASLR and a few other settings down by using new GDB remote 
packets. This allows us to keep all of our current launch flags and settings
intact and still be able to communicate them over to the remote GDB server.
Previously these were being sent as arguments to the debugserver binary that
we were spawning. Also modified ProcessGDBRemote to handle losing connection
to the remote GDB server and always exit immediately. We do this by watching
the lldb_private::Communication event bit for the read thread exiting in the
ProcessGDBRemote async thread.

Added support for many of the new 'Q' packets for setting stdin, stdout,
stderr, working dir and disable ASLR to the GDBRemoteCommunication class for
easy accesss.

Modified debugserver for all of the new 'Q' packets and also made it so that
debugserver always exists if it loses connection with the remote debugger.

llvm-svn: 126444
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 7a0de0b..6d2861d 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -1512,6 +1512,9 @@
         exe_module->GetFileSpec().GetPath(exec_file_path, sizeof(exec_file_path));
         if (exe_module->GetFileSpec().Exists())
         {
+            if (PrivateStateThreadIsValid ())
+                PausePrivateStateThread ();
+    
             error = WillLaunch (exe_module);
             if (error.Success())
             {
@@ -1579,7 +1582,11 @@
                         // This delays passing the stopped event to listeners till DidLaunch gets
                         // a chance to complete...
                         HandlePrivateEvent (event_sp);
-                        StartPrivateStateThread ();
+
+                        if (PrivateStateThreadIsValid ())
+                            ResumePrivateStateThread ();
+                        else
+                            StartPrivateStateThread ();
                     }
                     else if (state == eStateExited)
                     {
@@ -1605,6 +1612,7 @@
     switch (state) 
     {
         case eStateRunning:
+        case eStateConnected:
             return eEventActionRetry;
         
         case eStateStopped:
@@ -1776,31 +1784,13 @@
     Error error (DoConnectRemote (remote_url));
     if (error.Success())
     {
-        SetNextEventAction(new Process::AttachCompletionHandler(this));
-        StartPrivateStateThread();
-//        TimeValue timeout;
-//        timeout = TimeValue::Now();
-//        timeout.OffsetWithMicroSeconds(000);
-//        EventSP event_sp;
-//        StateType state = WaitForProcessStopPrivate(NULL, event_sp);
-//        
-//        if (state == eStateStopped || state == eStateCrashed)
-//        {
-//            DidLaunch ();
-//            
-//            // This delays passing the stopped event to listeners till DidLaunch gets
-//            // a chance to complete...
-//            HandlePrivateEvent (event_sp);
-//            StartPrivateStateThread ();
-//        }
-//        else if (state == eStateExited)
-//        {
-//            // We exited while trying to launch somehow.  Don't call DidLaunch as that's
-//            // not likely to work, and return an invalid pid.
-//            HandlePrivateEvent (event_sp);
-//        }
-//
-//        StartPrivateStateThread();
+        StartPrivateStateThread();        
+        // If we attached and actually have a process on the other end, then 
+        // this ended up being the equivalent of an attach.
+        if (GetID() != LLDB_INVALID_PROCESS_ID)
+        {
+            CompleteAttach ();
+        }
     }
     return error;
 }