[Lldb-commits] [lldb] 82951cf - Fix HostProcessWindows for D120321
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Wed Feb 23 05:52:55 PST 2022
Author: Pavel Labath
Date: 2022-02-23T14:52:34+01:00
New Revision: 82951cfb8a413aab9c4b8aeecbd7475dda8f1fb1
URL: https://github.com/llvm/llvm-project/commit/82951cfb8a413aab9c4b8aeecbd7475dda8f1fb1
DIFF: https://github.com/llvm/llvm-project/commit/82951cfb8a413aab9c4b8aeecbd7475dda8f1fb1.diff
LOG: Fix HostProcessWindows for D120321
Added:
Modified:
lldb/include/lldb/Host/windows/HostProcessWindows.h
lldb/source/Host/windows/HostProcessWindows.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Host/windows/HostProcessWindows.h b/lldb/include/lldb/Host/windows/HostProcessWindows.h
index dc27bdc46bb8f..4c69a2f434cf1 100644
--- a/lldb/include/lldb/Host/windows/HostProcessWindows.h
+++ b/lldb/include/lldb/Host/windows/HostProcessWindows.h
@@ -34,8 +34,6 @@ class HostProcessWindows : public HostNativeProcessBase {
bool monitor_signals) override;
private:
- static lldb::thread_result_t MonitorThread(void *thread_arg);
-
void Close();
bool m_owns_handle;
diff --git a/lldb/source/Host/windows/HostProcessWindows.cpp b/lldb/source/Host/windows/HostProcessWindows.cpp
index 741ec68d1d1ee..6ccb725ef56ee 100644
--- a/lldb/source/Host/windows/HostProcessWindows.cpp
+++ b/lldb/source/Host/windows/HostProcessWindows.cpp
@@ -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
diff erent, 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);
More information about the lldb-commits
mailing list