Fix HostProcessWindows for D120321
authorPavel Labath <pavel@labath.sk>
Wed, 23 Feb 2022 13:51:55 +0000 (14:51 +0100)
committerPavel Labath <pavel@labath.sk>
Wed, 23 Feb 2022 13:52:34 +0000 (14:52 +0100)
lldb/include/lldb/Host/windows/HostProcessWindows.h
lldb/source/Host/windows/HostProcessWindows.cpp

index dc27bdc..4c69a2f 100644 (file)
@@ -34,8 +34,6 @@ public:
                   bool monitor_signals) override;
 
 private:
-  static lldb::thread_result_t MonitorThread(void *thread_arg);
-
   void Close();
 
   bool m_owns_handle;
index 741ec68..6ccb725 100644 (file)
@@ -63,38 +63,36 @@ bool HostProcessWindows::IsRunning() const {
   return (code == STILL_ACTIVE);
 }
 
+static lldb::thread_result_t
+MonitorThread(const Host::MonitorChildProcessCallback &callback,
+              HANDLE process_handle) {
+  DWORD exit_code;
+
+  ::WaitForSingleObject(process_handle, INFINITE);
+  ::GetExitCodeProcess(process_handle, &exit_code);
+  callback(::GetProcessId(process_handle), true, 0, exit_code);
+  ::CloseHandle(process_handle);
+  return {};
+}
+
 llvm::Expected<HostThread> HostProcessWindows::StartMonitoring(
     const Host::MonitorChildProcessCallback &callback, bool monitor_signals) {
-  MonitorInfo *info = new MonitorInfo;
-  info->callback = callback;
+  HANDLE process_handle;
 
   // 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.
   if (::DuplicateHandle(GetCurrentProcess(), m_process, GetCurrentProcess(),
-                        &info->process_handle, 0, FALSE, DUPLICATE_SAME_ACCESS)) {
-    return ThreadLauncher::LaunchThread("ChildProcessMonitor",
-                                        HostProcessWindows::MonitorThread,
-                                        info);
+                        &process_handle, 0, FALSE, DUPLICATE_SAME_ACCESS)) {
+    return ThreadLauncher::LaunchThread(
+        "ChildProcessMonitor", [callback, process_handle] {
+          return MonitorThread(callback, process_handle);
+        });
   } else {
     return llvm::errorCodeToError(llvm::mapWindowsError(GetLastError()));
   }
 }
 
-lldb::thread_result_t HostProcessWindows::MonitorThread(void *thread_arg) {
-  DWORD exit_code;
-
-  MonitorInfo *info = static_cast<MonitorInfo *>(thread_arg);
-  if (info) {
-    ::WaitForSingleObject(info->process_handle, INFINITE);
-    ::GetExitCodeProcess(info->process_handle, &exit_code);
-    info->callback(::GetProcessId(info->process_handle), true, 0, exit_code);
-    ::CloseHandle(info->process_handle);
-    delete (info);
-  }
-  return {};
-}
-
 void HostProcessWindows::Close() {
   if (m_owns_handle && m_process != LLDB_INVALID_PROCESS)
     ::CloseHandle(m_process);