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/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index ed9cc8a..860d35e 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -3584,6 +3584,8 @@
 Error
 ProcessGDBRemote::LaunchAndConnectToDebugserver (const ProcessInfo &process_info)
 {
+    using namespace std::placeholders; // For _1, _2, etc.
+
     Error error;
     if (m_debugserver_pid == LLDB_INVALID_PROCESS_ID)
     {
@@ -3595,7 +3597,8 @@
         // special terminal key sequences (^C) don't affect debugserver.
         debugserver_launch_info.SetLaunchInSeparateProcessGroup(true);
 
-        debugserver_launch_info.SetMonitorProcessCallback (MonitorDebugserverProcess, this, false);
+        debugserver_launch_info.SetMonitorProcessCallback(std::bind(MonitorDebugserverProcess, this, _1, _2, _3, _4),
+                                                          false);
         debugserver_launch_info.SetUserID(process_info.GetUserID());
 
 #if defined (__APPLE__) && (defined (__arm__) || defined (__arm64__) || defined (__aarch64__))
@@ -3657,14 +3660,11 @@
 }
 
 bool
-ProcessGDBRemote::MonitorDebugserverProcess
-(
-    void *callback_baton,
-    lldb::pid_t debugserver_pid,
-    bool exited,        // True if the process did exit
-    int signo,          // Zero for no signal
-    int exit_status     // Exit value of process if signal is zero
-)
+ProcessGDBRemote::MonitorDebugserverProcess(ProcessGDBRemote *process, lldb::pid_t debugserver_pid,
+                                            bool exited,    // True if the process did exit
+                                            int signo,      // Zero for no signal
+                                            int exit_status // Exit value of process if signal is zero
+                                            )
 {
     // The baton is a "ProcessGDBRemote *". Now this class might be gone
     // and might not exist anymore, so we need to carefully try to get the
@@ -3680,15 +3680,14 @@
     // debugserver that we are tracking...
     Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
 
-    ProcessGDBRemote *process = (ProcessGDBRemote *)callback_baton;
-
     // Get a shared pointer to the target that has a matching process pointer.
     // This target could be gone, or the target could already have a new process
     // object inside of it
     TargetSP target_sp (Debugger::FindTargetWithProcess(process));
 
     if (log)
-        log->Printf ("ProcessGDBRemote::MonitorDebugserverProcess (baton=%p, pid=%" PRIu64 ", signo=%i (0x%x), exit_status=%i)", callback_baton, debugserver_pid, signo, signo, exit_status);
+        log->Printf("ProcessGDBRemote::%s(process=%p, pid=%" PRIu64 ", signo=%i (0x%x), exit_status=%i)", __FUNCTION__,
+                    process, debugserver_pid, signo, signo, exit_status);
 
     if (target_sp)
     {