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/FreeBSD/ProcessMonitor.cpp b/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
index cd016fb..2318a65 100644
--- a/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
@@ -819,6 +819,8 @@
       m_terminal_fd(-1),
       m_operation(0)
 {
+    using namespace std::placeholders;
+
     std::unique_ptr<LaunchArgs> args(new LaunchArgs(this, module, argv, envp,
                                                     stdin_file_spec,
                                                     stdout_file_spec,
@@ -856,7 +858,7 @@
 
     // Finally, start monitoring the child process for change in state.
     m_monitor_thread = Host::StartMonitoringChildProcess(
-        ProcessMonitor::MonitorCallback, this, GetPID(), true);
+        std::bind(&ProcessMonitor::MonitorCallback, this, _1, _2, _3, _4), GetPID(), true);
     if (!m_monitor_thread.IsJoinable())
     {
         error.SetErrorToGenericError();
@@ -873,6 +875,8 @@
       m_terminal_fd(-1),
       m_operation(0)
 {
+    using namespace std::placeholders;
+
     sem_init(&m_operation_pending, 0, 0);
     sem_init(&m_operation_done, 0, 0);
 
@@ -906,7 +910,7 @@
 
     // Finally, start monitoring the child process for change in state.
     m_monitor_thread = Host::StartMonitoringChildProcess(
-        ProcessMonitor::MonitorCallback, this, GetPID(), true);
+        std::bind(&ProcessMonitor::MonitorCallback, this, _1, _2, _3, _4), GetPID(), true);
     if (!m_monitor_thread.IsJoinable())
     {
         error.SetErrorToGenericError();
@@ -1180,14 +1184,9 @@
 }
 
 bool
-ProcessMonitor::MonitorCallback(void *callback_baton,
-                                lldb::pid_t pid,
-                                bool exited,
-                                int signal,
-                                int status)
+ProcessMonitor::MonitorCallback(ProcessMonitor *monitor, lldb::pid_t pid, bool exited, int signal, int status)
 {
     ProcessMessage message;
-    ProcessMonitor *monitor = static_cast<ProcessMonitor*>(callback_baton);
     ProcessFreeBSD *process = monitor->m_process;
     assert(process);
     bool stop_monitoring;