Generalize child process monitoring functions

Summary:
This replaces the C-style "void *" baton of the child process monitoring functions with a more
C++-like API taking a std::function. The motivation for this was that it was very difficult to
handle the ownership of the object passed into the callback function -- each caller ended up
implementing his own way of doing it, some doing it better than others. With the new API, one can
just pass a smart pointer into the callback and all of the lifetime management will be handled
automatically.

This has enabled me to simplify the rather complicated handshake in Host::RunShellCommand. I have
left handling of MonitorDebugServerProcess (my original motivation for this change) to a separate
commit to reduce the scope of this change.

Reviewers: clayborg, zturner, emaste, krytarowski

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D20106

llvm-svn: 269205
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
index 060d795..b296974 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -124,7 +124,8 @@
     // Do not run in a new session so that it can not linger after the
     // platform closes.
     debugserver_launch_info.SetLaunchInSeparateProcessGroup(false);
-    debugserver_launch_info.SetMonitorProcessCallback(ReapDebugserverProcess, this, false);
+    debugserver_launch_info.SetMonitorProcessCallback(
+        std::bind(&GDBRemoteCommunicationServerPlatform::DebugserverProcessReaped, this, std::placeholders::_1), false);
 
     std::string platform_scheme;
     std::string platform_ip;
@@ -445,18 +446,7 @@
 {
     Mutex::Locker locker (m_spawned_pids_mutex);
     FreePortForProcess(pid);
-    return m_spawned_pids.erase(pid) > 0;
-}
-
-bool
-GDBRemoteCommunicationServerPlatform::ReapDebugserverProcess (void *callback_baton,
-                                                   lldb::pid_t pid,
-                                                   bool exited,
-                                                   int signal,    // Zero for no signal
-                                                   int status)    // Exit value of process if signal is zero
-{
-    GDBRemoteCommunicationServerPlatform *server = (GDBRemoteCommunicationServerPlatform *)callback_baton;
-    server->DebugserverProcessReaped (pid);
+    m_spawned_pids.erase(pid);
     return true;
 }
 
@@ -470,7 +460,9 @@
     // generally be what happens since we need to reap started
     // processes.
     if (!m_process_launch_info.GetMonitorProcessCallback ())
-        m_process_launch_info.SetMonitorProcessCallback(ReapDebugserverProcess, this, false);
+        m_process_launch_info.SetMonitorProcessCallback(
+            std::bind(&GDBRemoteCommunicationServerPlatform::DebugserverProcessReaped, this, std::placeholders::_1),
+            false);
 
     Error error = m_platform_sp->LaunchProcess (m_process_launch_info);
     if (!error.Success ())