labath updated this revision to Diff 56903.
labath marked 3 inline comments as done.
labath added a comment.
Herald added a subscriber: emaste.

Remove the typedef and add changes to windows, osx, and freebsd-specific code. 
I didn't
try building NetBSD, but given that there is no Plugins/Process/NetBSD, I don't 
think I
need to do any changes there at all. I'll keep an eye out on the buildbots after
submitting this.

I'd like to draw attention to the osx change in Host.mm in particular, as I not 
too
familiar with objjective c, but making a copy there made the thing work for me 
(without
that, I was getting errors, presumably because the block was only capturing the
reference, which was not enough if to keep the function object alive).


http://reviews.llvm.org/D20106

Files:
  include/lldb/Host/Host.h
  include/lldb/Host/HostNativeProcessBase.h
  include/lldb/Host/HostProcess.h
  include/lldb/Host/posix/HostProcessPosix.h
  include/lldb/Host/windows/HostProcessWindows.h
  include/lldb/Target/Process.h
  include/lldb/Target/ProcessLaunchInfo.h
  source/Host/common/Host.cpp
  source/Host/common/HostProcess.cpp
  source/Host/common/MonitoringProcessLauncher.cpp
  source/Host/macosx/Host.mm
  source/Host/posix/HostProcessPosix.cpp
  source/Host/windows/Host.cpp
  source/Host/windows/HostProcessWindows.cpp
  source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
  source/Plugins/Process/FreeBSD/ProcessMonitor.h
  source/Plugins/Process/Windows/Live/ProcessWindowsLive.cpp
  source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
  source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h
  source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
  source/Target/Process.cpp
  source/Target/ProcessLaunchInfo.cpp

Index: source/Target/ProcessLaunchInfo.cpp
===================================================================
--- source/Target/ProcessLaunchInfo.cpp
+++ source/Target/ProcessLaunchInfo.cpp
@@ -244,12 +244,9 @@
 }
 
 void
-ProcessLaunchInfo::SetMonitorProcessCallback (Host::MonitorChildProcessCallback callback,
-                           void *baton,
-                           bool monitor_signals)
+ProcessLaunchInfo::SetMonitorProcessCallback(const Host::MonitorChildProcessCallback &callback, bool monitor_signals)
 {
     m_monitor_callback = callback;
-    m_monitor_callback_baton = baton;
     m_monitor_signals = monitor_signals;
 }
 
@@ -259,7 +256,6 @@
     if (m_monitor_callback && ProcessIDIsValid())
     {
         Host::StartMonitoringChildProcess (m_monitor_callback,
-                                           m_monitor_callback_baton,
                                            GetProcessID(),
                                            m_monitor_signals);
         return true;
Index: source/Target/Process.cpp
===================================================================
--- source/Target/Process.cpp
+++ source/Target/Process.cpp
@@ -1512,21 +1512,15 @@
 // found in the global target list (we want to be completely sure that the
 // lldb_private::Process doesn't go away before we can deliver the signal.
 bool
-Process::SetProcessExitStatus (void *callback_baton,
-                               lldb::pid_t pid,
-                               bool exited,
-                               int signo,          // Zero for no signal
-                               int exit_status     // Exit value of process if signal is zero
-)
+Process::SetProcessExitStatus(lldb::pid_t pid, bool exited,
+                              int signo,      // Zero for no signal
+                              int exit_status // Exit value of process if signal is zero
+                              )
 {
     Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PROCESS));
     if (log)
-        log->Printf ("Process::SetProcessExitStatus (baton=%p, pid=%" PRIu64 ", exited=%i, signal=%i, exit_status=%i)\n",
-                     callback_baton,
-                     pid,
-                     exited,
-                     signo,
-                     exit_status);
+        log->Printf("Process::SetProcessExitStatus (pid=%" PRIu64 ", exited=%i, signal=%i, exit_status=%i)\n", pid,
+                    exited, signo, exit_status);
 
     if (exited)
     {
Index: source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
===================================================================
--- source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -405,11 +405,7 @@
     AsyncThread (void *arg);
 
     static bool
-    MonitorDebugserverProcess (void *callback_baton,
-                               lldb::pid_t pid,
-                               bool exited,
-                               int signo,
-                               int exit_status);
+    MonitorDebugserverProcess(ProcessGDBRemote *process, lldb::pid_t pid, bool exited, int signo, int exit_status);
 
     lldb::StateType
     SetThreadStopInfo (StringExtractor& stop_packet);
Index: source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ 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)
     {
Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h
===================================================================
--- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h
+++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h
@@ -121,13 +121,6 @@
     bool
     DebugserverProcessReaped (lldb::pid_t pid);
 
-    static bool
-    ReapDebugserverProcess (void *callback_baton,
-                            lldb::pid_t pid,
-                            bool exited,
-                            int signal,
-                            int status);
-
     static const FileSpec&
     GetDomainSocketDir();
 
Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ 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 ())
Index: source/Plugins/Process/Windows/Live/ProcessWindowsLive.cpp
===================================================================
--- source/Plugins/Process/Windows/Live/ProcessWindowsLive.cpp
+++ source/Plugins/Process/Windows/Live/ProcessWindowsLive.cpp
@@ -820,7 +820,7 @@
         target->ModulesDidUnload(unloaded_modules, true);
     }
 
-    SetProcessExitStatus(nullptr, GetID(), true, 0, exit_code);
+    SetProcessExitStatus(GetID(), true, 0, exit_code);
     SetPrivateState(eStateExited);
 }
 
Index: source/Plugins/Process/FreeBSD/ProcessMonitor.h
===================================================================
--- source/Plugins/Process/FreeBSD/ProcessMonitor.h
+++ source/Plugins/Process/FreeBSD/ProcessMonitor.h
@@ -302,8 +302,7 @@
     DupDescriptor(const lldb_private::FileSpec &file_spec, int fd, int flags);
 
     static bool
-    MonitorCallback(void *callback_baton,
-                    lldb::pid_t pid, bool exited, int signal, int status);
+    MonitorCallback(ProcessMonitor *monitor, lldb::pid_t pid, bool exited, int signal, int status);
 
     static ProcessMessage
     MonitorSIGTRAP(ProcessMonitor *monitor,
Index: source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
===================================================================
--- source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
+++ 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;
Index: source/Host/windows/HostProcessWindows.cpp
===================================================================
--- source/Host/windows/HostProcessWindows.cpp
+++ source/Host/windows/HostProcessWindows.cpp
@@ -24,8 +24,7 @@
 {
 struct MonitorInfo
 {
-    HostProcess::MonitorCallback callback;
-    void *baton;
+    Host::MonitorChildProcessCallback callback;
     HANDLE process_handle;
 };
 }
@@ -104,12 +103,11 @@
 }
 
 HostThread
-HostProcessWindows::StartMonitoring(HostProcess::MonitorCallback callback, void *callback_baton, bool monitor_signals)
+HostProcessWindows::StartMonitoring(const Host::MonitorChildProcessCallback &callback, bool monitor_signals)
 {
     HostThread monitor_thread;
     MonitorInfo *info = new MonitorInfo;
     info->callback = callback;
-    info->baton = callback_baton;
 
     // Since the life of this HostProcessWindows instance and the life of the process may be different, duplicate the handle so that
     // the monitor thread can have ownership over its own copy of the handle.
@@ -129,7 +127,7 @@
     {
         ::WaitForSingleObject(info->process_handle, INFINITE);
         ::GetExitCodeProcess(info->process_handle, &exit_code);
-        info->callback(info->baton, ::GetProcessId(info->process_handle), true, 0, exit_code);
+        info->callback(::GetProcessId(info->process_handle), true, 0, exit_code);
         ::CloseHandle(info->process_handle);
         delete (info);
     }
Index: source/Host/windows/Host.cpp
===================================================================
--- source/Host/windows/Host.cpp
+++ source/Host/windows/Host.cpp
@@ -221,7 +221,8 @@
 }
 
 HostThread
-Host::StartMonitoringChildProcess(Host::MonitorChildProcessCallback callback, void *callback_baton, lldb::pid_t pid, bool monitor_signals)
+Host::StartMonitoringChildProcess(const Host::MonitorChildProcessCallback &callback, lldb::pid_t pid,
+                                  bool monitor_signals)
 {
     return HostThread();
 }
Index: source/Host/posix/HostProcessPosix.cpp
===================================================================
--- source/Host/posix/HostProcessPosix.cpp
+++ source/Host/posix/HostProcessPosix.cpp
@@ -107,7 +107,7 @@
 }
 
 HostThread
-HostProcessPosix::StartMonitoring(HostProcess::MonitorCallback callback, void *callback_baton, bool monitor_signals)
+HostProcessPosix::StartMonitoring(const Host::MonitorChildProcessCallback &callback, bool monitor_signals)
 {
-    return Host::StartMonitoringChildProcess(callback, callback_baton, m_process, monitor_signals);
+    return Host::StartMonitoringChildProcess(callback, m_process, monitor_signals);
 }
Index: source/Host/macosx/Host.mm
===================================================================
--- source/Host/macosx/Host.mm
+++ source/Host/macosx/Host.mm
@@ -1334,7 +1334,6 @@
                 callback = Process::SetProcessExitStatus;
 
             StartMonitoringChildProcess (callback,
-                                         NULL, 
                                          pid, 
                                          monitor_signals);
         }
@@ -1449,7 +1448,8 @@
 }
 
 HostThread
-Host::StartMonitoringChildProcess(Host::MonitorChildProcessCallback callback, void *callback_baton, lldb::pid_t pid, bool monitor_signals)
+Host::StartMonitoringChildProcess(const Host::MonitorChildProcessCallback &callback, lldb::pid_t pid,
+                                  bool monitor_signals)
 {
     unsigned long mask = DISPATCH_PROC_EXIT;
     if (monitor_signals)
@@ -1465,14 +1465,13 @@
 
     if (log)
         log->Printf("Host::StartMonitoringChildProcess "
-                    "(callback=%p, baton=%p, pid=%i, monitor_signals=%i) "
+                    "(callback, pid=%i, monitor_signals=%i) "
                     "source = %p\n",
-                    reinterpret_cast<void *>(callback), callback_baton,
-                    static_cast<int>(pid), monitor_signals,
-                    reinterpret_cast<void *>(source));
+                    static_cast<int>(pid), monitor_signals, reinterpret_cast<void *>(source));
 
     if (source)
     {
+        Host::MonitorChildProcessCallback callback_copy = callback;
         ::dispatch_source_set_cancel_handler (source, ^{
             ::dispatch_release (source);
         });
@@ -1524,8 +1523,8 @@
                                  signal,
                                  exit_status);
 
-                if (callback)
-                    cancel = callback (callback_baton, pid, exited, signal, exit_status);
+                if (callback_copy)
+                    cancel = callback_copy(pid, exited, signal, exit_status);
 
                 if (exited || cancel)
                 {
Index: source/Host/common/MonitoringProcessLauncher.cpp
===================================================================
--- source/Host/common/MonitoringProcessLauncher.cpp
+++ source/Host/common/MonitoringProcessLauncher.cpp
@@ -75,20 +75,18 @@
 
         Host::MonitorChildProcessCallback callback = launch_info.GetMonitorProcessCallback();
 
-        void *baton = nullptr;
         bool monitor_signals = false;
         if (callback)
         {
             // If the ProcessLaunchInfo specified a callback, use that.
-            baton = launch_info.GetMonitorProcessBaton();
             monitor_signals = launch_info.GetMonitorSignals();
         }
         else
         {
             callback = Process::SetProcessExitStatus;
         }
 
-        process.StartMonitoring(callback, baton, monitor_signals);
+        process.StartMonitoring(callback, monitor_signals);
         if (log)
             log->PutCString("started monitoring child process.");
     }
Index: source/Host/common/HostProcess.cpp
===================================================================
--- source/Host/common/HostProcess.cpp
+++ source/Host/common/HostProcess.cpp
@@ -49,9 +49,9 @@
 }
 
 HostThread
-HostProcess::StartMonitoring(HostProcess::MonitorCallback callback, void *callback_baton, bool monitor_signals)
+HostProcess::StartMonitoring(const Host::MonitorChildProcessCallback &callback, bool monitor_signals)
 {
-    return m_native_process->StartMonitoring(callback, callback_baton, monitor_signals);
+    return m_native_process->StartMonitoring(callback, monitor_signals);
 }
 
 HostNativeProcessBase &HostProcess::GetNativeProcess()
Index: source/Host/common/Host.cpp
===================================================================
--- source/Host/common/Host.cpp
+++ source/Host/common/Host.cpp
@@ -93,21 +93,20 @@
 {
     lldb::pid_t pid;                            // The process ID to monitor
     Host::MonitorChildProcessCallback callback; // The callback function to call when "pid" exits or signals
-    void *callback_baton;                       // The callback baton for the callback function
     bool monitor_signals;                       // If true, call the callback when "pid" gets signaled.
 };
 
 static thread_result_t
 MonitorChildProcessThreadFunction (void *arg);
 
 HostThread
-Host::StartMonitoringChildProcess(Host::MonitorChildProcessCallback callback, void *callback_baton, lldb::pid_t pid, bool monitor_signals)
+Host::StartMonitoringChildProcess(const Host::MonitorChildProcessCallback &callback, lldb::pid_t pid,
+                                  bool monitor_signals)
 {
     MonitorInfo * info_ptr = new MonitorInfo();
 
     info_ptr->pid = pid;
     info_ptr->callback = callback;
-    info_ptr->callback_baton = callback_baton;
     info_ptr->monitor_signals = monitor_signals;
     
     char thread_name[256];
@@ -184,7 +183,6 @@
     MonitorInfo *info = (MonitorInfo *)arg;
 
     const Host::MonitorChildProcessCallback callback = info->callback;
-    void * const callback_baton = info->callback_baton;
     const bool monitor_signals = info->monitor_signals;
 
     assert (info->pid <= UINT32_MAX);
@@ -285,8 +283,8 @@
                 {
                     bool callback_return = false;
                     if (callback)
-                        callback_return = callback (callback_baton, wait_pid, exited, signal, exit_status);
-                    
+                        callback_return = callback(wait_pid, exited, signal, exit_status);
+
                     // If our process exited, then this thread should exit
                     if (exited && wait_pid == abs(pid))
                     {
@@ -500,41 +498,30 @@
 {
     ShellInfo () :
         process_reaped (false),
-        can_delete (false),
         pid (LLDB_INVALID_PROCESS_ID),
         signo(-1),
         status(-1)
     {
     }
 
     lldb_private::Predicate<bool> process_reaped;
-    lldb_private::Predicate<bool> can_delete;
     lldb::pid_t pid;
     int signo;
     int status;
 };
 
 static bool
-MonitorShellCommand (void *callback_baton,
-                     lldb::pid_t pid,
-                     bool exited,       // True if the process did exit
-                     int signo,         // Zero for no signal
-                     int status)   // Exit value of process if signal is zero
+MonitorShellCommand(std::shared_ptr<ShellInfo> shell_info, lldb::pid_t pid,
+                    bool exited, // True if the process did exit
+                    int signo,   // Zero for no signal
+                    int status)  // Exit value of process if signal is zero
 {
-    ShellInfo *shell_info = (ShellInfo *)callback_baton;
     shell_info->pid = pid;
     shell_info->signo = signo;
     shell_info->status = status;
     // Let the thread running Host::RunShellCommand() know that the process
     // exited and that ShellInfo has been filled in by broadcasting to it
-    shell_info->process_reaped.SetValue(1, eBroadcastAlways);
-    // Now wait for a handshake back from that thread running Host::RunShellCommand
-    // so we know that we can delete shell_info_ptr
-    shell_info->can_delete.WaitForValueEqualTo(true);
-    // Sleep a bit to allow the shell_info->can_delete.SetValue() to complete...
-    usleep(1000);
-    // Now delete the shell info that was passed into this function
-    delete shell_info;
+    shell_info->process_reaped.SetValue(true, eBroadcastAlways);
     return true;
 }
 
@@ -617,34 +604,30 @@
         launch_info.AppendSuppressFileAction (STDOUT_FILENO, false, true);
         launch_info.AppendSuppressFileAction (STDERR_FILENO, false, true);
     }
-    
-    // The process monitor callback will delete the 'shell_info_ptr' below...
-    std::unique_ptr<ShellInfo> shell_info_ap (new ShellInfo());
-    
+
+    std::shared_ptr<ShellInfo> shell_info_sp(new ShellInfo());
     const bool monitor_signals = false;
-    launch_info.SetMonitorProcessCallback(MonitorShellCommand, shell_info_ap.get(), monitor_signals);
-    
+    launch_info.SetMonitorProcessCallback(std::bind(MonitorShellCommand, shell_info_sp, std::placeholders::_1,
+                                                    std::placeholders::_2, std::placeholders::_3,
+                                                    std::placeholders::_4),
+                                          monitor_signals);
+
     error = LaunchProcess (launch_info);
     const lldb::pid_t pid = launch_info.GetProcessID();
     
     if (error.Success() && pid == LLDB_INVALID_PROCESS_ID)
         error.SetErrorString("failed to get process ID");
     
     if (error.Success())
     {
-        // The process successfully launched, so we can defer ownership of
-        // "shell_info" to the MonitorShellCommand callback function that will
-        // get called when the process dies. We release the unique pointer as it
-        // doesn't need to delete the ShellInfo anymore.
-        ShellInfo *shell_info = shell_info_ap.release();
         TimeValue *timeout_ptr = nullptr;
         TimeValue timeout_time(TimeValue::Now());
         if (timeout_sec > 0) {
             timeout_time.OffsetWithSeconds(timeout_sec);
             timeout_ptr = &timeout_time;
         }
         bool timed_out = false;
-        shell_info->process_reaped.WaitForValueEqualTo(true, timeout_ptr, &timed_out);
+        shell_info_sp->process_reaped.WaitForValueEqualTo(true, timeout_ptr, &timed_out);
         if (timed_out)
         {
             error.SetErrorString("timed out waiting for shell command to complete");
@@ -655,16 +638,16 @@
             timeout_time = TimeValue::Now();
             timeout_time.OffsetWithSeconds(1);
             timed_out = false;
-            shell_info->process_reaped.WaitForValueEqualTo(true, &timeout_time, &timed_out);
+            shell_info_sp->process_reaped.WaitForValueEqualTo(true, &timeout_time, &timed_out);
         }
         else
         {
             if (status_ptr)
-                *status_ptr = shell_info->status;
-            
+                *status_ptr = shell_info_sp->status;
+
             if (signo_ptr)
-                *signo_ptr = shell_info->signo;
-            
+                *signo_ptr = shell_info_sp->signo;
+
             if (command_output_ptr)
             {
                 command_output_ptr->clear();
@@ -685,14 +668,10 @@
                 }
             }
         }
-        shell_info->can_delete.SetValue(true, eBroadcastAlways);
     }
 
     if (FileSystem::GetFileExists(output_file_spec))
         FileSystem::Unlink(output_file_spec);
-    // Handshake with the monitor thread, or just let it know in advance that
-    // it can delete "shell_info" in case we timed out and were not able to kill
-    // the process...
     return error;
 }
 
Index: include/lldb/Target/ProcessLaunchInfo.h
===================================================================
--- include/lldb/Target/ProcessLaunchInfo.h
+++ include/lldb/Target/ProcessLaunchInfo.h
@@ -148,22 +148,14 @@
                                              int32_t num_resumes);
 
         void
-        SetMonitorProcessCallback (Host::MonitorChildProcessCallback callback,
-                                   void *baton,
-                                   bool monitor_signals);
+        SetMonitorProcessCallback(const Host::MonitorChildProcessCallback &callback, bool monitor_signals);
 
         Host::MonitorChildProcessCallback
         GetMonitorProcessCallback() const
         {
             return m_monitor_callback;
         }
 
-        void *
-        GetMonitorProcessBaton() const
-        {
-            return m_monitor_callback_baton;
-        }
-
         bool
         GetMonitorSignals() const
         {
Index: include/lldb/Target/Process.h
===================================================================
--- include/lldb/Target/Process.h
+++ include/lldb/Target/Process.h
@@ -999,16 +999,14 @@
     /// Subclasses should call Host::StartMonitoringChildProcess ()
     /// with:
     ///     callback = Process::SetHostProcessExitStatus
-    ///     callback_baton = nullptr
     ///     pid = Process::GetID()
     ///     monitor_signals = false
     //------------------------------------------------------------------
     static bool
-    SetProcessExitStatus(void *callback_baton,   // The callback baton which should be set to nullptr
-                         lldb::pid_t pid,        // The process ID we want to monitor
+    SetProcessExitStatus(lldb::pid_t pid, // The process ID we want to monitor
                          bool exited,
-                         int signo,              // Zero for no signal
-                         int status);            // Exit value of process if signal is zero
+                         int signo,   // Zero for no signal
+                         int status); // Exit value of process if signal is zero
 
     lldb::ByteOrder
     GetByteOrder () const;
Index: include/lldb/Host/windows/HostProcessWindows.h
===================================================================
--- include/lldb/Host/windows/HostProcessWindows.h
+++ include/lldb/Host/windows/HostProcessWindows.h
@@ -33,9 +33,10 @@
     virtual lldb::pid_t GetProcessId() const;
     virtual bool IsRunning() const;
 
-    virtual HostThread StartMonitoring(HostProcess::MonitorCallback callback, void *callback_baton, bool monitor_signals);
+    HostThread
+    StartMonitoring(const Host::MonitorChildProcessCallback &callback, bool monitor_signals) override;
 
-  private:
+private:
     static lldb::thread_result_t MonitorThread(void *thread_arg);
 
     void Close();
Index: include/lldb/Host/posix/HostProcessPosix.h
===================================================================
--- include/lldb/Host/posix/HostProcessPosix.h
+++ include/lldb/Host/posix/HostProcessPosix.h
@@ -39,7 +39,8 @@
     lldb::pid_t GetProcessId() const override;
     bool IsRunning() const override;
 
-    HostThread StartMonitoring(HostProcess::MonitorCallback callback, void *callback_baton, bool monitor_signals) override;
+    HostThread
+    StartMonitoring(const Host::MonitorChildProcessCallback &callback, bool monitor_signals) override;
 };
 
 } // namespace lldb_private
Index: include/lldb/Host/HostProcess.h
===================================================================
--- include/lldb/Host/HostProcess.h
+++ include/lldb/Host/HostProcess.h
@@ -10,6 +10,7 @@
 #ifndef lldb_Host_HostProcess_h_
 #define lldb_Host_HostProcess_h_
 
+#include "lldb/Host/Host.h"
 #include "lldb/lldb-types.h"
 
 //----------------------------------------------------------------------
@@ -36,9 +37,7 @@
 
 class HostProcess
 {
-  public:
-    typedef bool (*MonitorCallback)(void *callback_baton, lldb::pid_t process, bool exited, int signal, int status);
-
+public:
     HostProcess();
     HostProcess(lldb::process_t process);
     ~HostProcess();
@@ -49,7 +48,8 @@
     lldb::pid_t GetProcessId() const;
     bool IsRunning() const;
 
-    HostThread StartMonitoring(MonitorCallback callback, void *callback_baton, bool monitor_signals);
+    HostThread
+    StartMonitoring(const Host::MonitorChildProcessCallback &callback, bool monitor_signals);
 
     HostNativeProcessBase &GetNativeProcess();
     const HostNativeProcessBase &GetNativeProcess() const;
Index: include/lldb/Host/HostNativeProcessBase.h
===================================================================
--- include/lldb/Host/HostNativeProcessBase.h
+++ include/lldb/Host/HostNativeProcessBase.h
@@ -46,9 +46,10 @@
         return m_process;
     }
 
-    virtual HostThread StartMonitoring(HostProcess::MonitorCallback callback, void *callback_baton, bool monitor_signals) = 0;
+    virtual HostThread
+    StartMonitoring(const Host::MonitorChildProcessCallback &callback, bool monitor_signals) = 0;
 
-  protected:
+protected:
     lldb::process_t m_process;
 };
 
Index: include/lldb/Host/Host.h
===================================================================
--- include/lldb/Host/Host.h
+++ include/lldb/Host/Host.h
@@ -38,12 +38,10 @@
 class Host
 {
 public:
-
-    typedef bool (*MonitorChildProcessCallback) (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
+    typedef std::function<bool(lldb::pid_t pid, bool exited,
+                               int signal,  // Zero for no signal
+                               int status)> // Exit value of process if signal is zero
+        MonitorChildProcessCallback;
 
     //------------------------------------------------------------------
     /// Start monitoring a child process.
@@ -65,10 +63,6 @@
     ///     A function callback to call when a child receives a signal
     ///     (if \a monitor_signals is true) or a child exits.
     ///
-    /// @param[in] callback_baton
-    ///     A void * of user data that will be pass back when
-    ///     \a callback is called.
-    ///
     /// @param[in] pid
     ///     The process ID of a child process to monitor, -1 for all
     ///     processes.
@@ -84,8 +78,8 @@
     ///
     /// @see static void Host::StopMonitoringChildProcess (uint32_t)
     //------------------------------------------------------------------
-    static HostThread StartMonitoringChildProcess(MonitorChildProcessCallback callback, void *callback_baton, lldb::pid_t pid,
-                                                  bool monitor_signals);
+    static HostThread
+    StartMonitoringChildProcess(const MonitorChildProcessCallback &callback, lldb::pid_t pid, bool monitor_signals);
 
     enum SystemLogType
     {
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to