<rdar://problem/3535148>

Added ability to debug root processes on OS X. This uses XPC service that is available on Lion and above only.


git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@151419 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 53b7a24..aa934e1 100644
--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -496,7 +496,7 @@
         // Make sure we aren't already connected?
         if (!m_gdb_comm.IsConnected())
         {
-            error = StartDebugserverProcess (host_port);
+            error = StartDebugserverProcess (host_port, launch_info);
             if (error.Fail())
             {
                 if (log)
@@ -762,6 +762,13 @@
 Error
 ProcessGDBRemote::DoAttachToProcessWithID (lldb::pid_t attach_pid)
 {
+    ProcessAttachInfo attach_info;
+    return DoAttachToProcessWithID(attach_pid, attach_info);
+}
+
+Error
+ProcessGDBRemote::DoAttachToProcessWithID (lldb::pid_t attach_pid, const ProcessAttachInfo &attach_info)
+{
     Error error;
     // Clear out and clean up from any current state
     Clear();
@@ -775,7 +782,7 @@
             char connect_url[128];
             snprintf (connect_url, sizeof(connect_url), "connect://%s", host_port);
 
-            error = StartDebugserverProcess (host_port);
+            error = StartDebugserverProcess (host_port, attach_info);
             
             if (error.Fail())
             {
@@ -824,7 +831,7 @@
 }
 
 Error
-ProcessGDBRemote::DoAttachToProcessWithName (const char *process_name, bool wait_for_launch)
+ProcessGDBRemote::DoAttachToProcessWithName (const char *process_name, bool wait_for_launch, const ProcessAttachInfo &attach_info)
 {
     Error error;
     // Clear out and clean up from any current state
@@ -840,7 +847,7 @@
             char connect_url[128];
             snprintf (connect_url, sizeof(connect_url), "connect://%s", host_port);
 
-            error = StartDebugserverProcess (host_port);
+            error = StartDebugserverProcess (host_port, attach_info);
             if (error.Fail())
             {
                 const char *error_string = error.AsCString();
@@ -2019,7 +2026,14 @@
 }
 
 Error
-ProcessGDBRemote::StartDebugserverProcess (const char *debugserver_url)    // The connection string to use in the spawned debugserver ("localhost:1234" or "/dev/tty...")
+ProcessGDBRemote::StartDebugserverProcess (const char *debugserver_url)
+{
+    ProcessLaunchInfo launch_info;
+    return StartDebugserverProcess(debugserver_url, launch_info);
+}
+
+Error
+ProcessGDBRemote::StartDebugserverProcess (const char *debugserver_url, const ProcessInfo &process_info)    // The connection string to use in the spawned debugserver ("localhost:1234" or "/dev/tty...")
 {
     Error error;
     if (m_debugserver_pid == LLDB_INVALID_PROCESS_ID)
@@ -2027,9 +2041,9 @@
         // If we locate debugserver, keep that located version around
         static FileSpec g_debugserver_file_spec;
 
-        ProcessLaunchInfo launch_info;
+        ProcessLaunchInfo debugserver_launch_info;
         char debugserver_path[PATH_MAX];
-        FileSpec &debugserver_file_spec = launch_info.GetExecutableFile();
+        FileSpec &debugserver_file_spec = debugserver_launch_info.GetExecutableFile();
 
         // Always check to see if we have an environment override for the path
         // to the debugserver to use and use it if we do.
@@ -2067,7 +2081,7 @@
 
             LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
 
-            Args &debugserver_args = launch_info.GetArguments();
+            Args &debugserver_args = debugserver_launch_info.GetArguments();
             char arg_cstr[PATH_MAX];
 
             // Start args with "debugserver /file/path -r --"
@@ -2130,11 +2144,11 @@
             // Close STDIN, STDOUT and STDERR. We might need to redirect them
             // to "/dev/null" if we run into any problems.
             file_action.Close (STDIN_FILENO);
-            launch_info.AppendFileAction (file_action);
+            debugserver_launch_info.AppendFileAction (file_action);
             file_action.Close (STDOUT_FILENO);
-            launch_info.AppendFileAction (file_action);
+            debugserver_launch_info.AppendFileAction (file_action);
             file_action.Close (STDERR_FILENO);
-            launch_info.AppendFileAction (file_action);
+            debugserver_launch_info.AppendFileAction (file_action);
 
             if (log)
             {
@@ -2143,12 +2157,13 @@
                 log->Printf("%s arguments:\n%s", debugserver_args.GetArgumentAtIndex(0), strm.GetData());
             }
 
-            launch_info.SetMonitorProcessCallback (MonitorDebugserverProcess, this, false);
+            debugserver_launch_info.SetMonitorProcessCallback (MonitorDebugserverProcess, this, false);
+            debugserver_launch_info.SetUserID(process_info.GetUserID());
 
-            error = Host::LaunchProcess(launch_info);
+            error = Host::LaunchProcess(debugserver_launch_info);
 
             if (error.Success ())
-                m_debugserver_pid = launch_info.GetProcessID();
+                m_debugserver_pid = debugserver_launch_info.GetProcessID();
             else
                 m_debugserver_pid = LLDB_INVALID_PROCESS_ID;
 
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
index 894aae2..4ecd3a0 100644
--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -103,7 +103,12 @@
     DoAttachToProcessWithID (lldb::pid_t pid);
     
     virtual lldb_private::Error
-    DoAttachToProcessWithName (const char *process_name, bool wait_for_launch);
+    DoAttachToProcessWithID (lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info);
+    
+    virtual lldb_private::Error
+    DoAttachToProcessWithName (const char *process_name,
+                               bool wait_for_launch,
+                               const lldb_private::ProcessAttachInfo &attach_info);
 
     virtual void
     DidAttach ();
@@ -260,6 +265,9 @@
 
     lldb_private::Error
     StartDebugserverProcess (const char *debugserver_url);
+    
+    lldb_private::Error
+    StartDebugserverProcess (const char *debugserver_url, const lldb_private::ProcessInfo &process_info);
 
     void
     KillDebugserverProcess ();