Skip to content

Commit 82951cf

Browse files
committed
Fix HostProcessWindows for D120321
1 parent 27d9a58 commit 82951cf

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

lldb/include/lldb/Host/windows/HostProcessWindows.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ class HostProcessWindows : public HostNativeProcessBase {
3434
bool monitor_signals) override;
3535

3636
private:
37-
static lldb::thread_result_t MonitorThread(void *thread_arg);
38-
3937
void Close();
4038

4139
bool m_owns_handle;

lldb/source/Host/windows/HostProcessWindows.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,38 +63,36 @@ bool HostProcessWindows::IsRunning() const {
6363
return (code == STILL_ACTIVE);
6464
}
6565

66+
static lldb::thread_result_t
67+
MonitorThread(const Host::MonitorChildProcessCallback &callback,
68+
HANDLE process_handle) {
69+
DWORD exit_code;
70+
71+
::WaitForSingleObject(process_handle, INFINITE);
72+
::GetExitCodeProcess(process_handle, &exit_code);
73+
callback(::GetProcessId(process_handle), true, 0, exit_code);
74+
::CloseHandle(process_handle);
75+
return {};
76+
}
77+
6678
llvm::Expected<HostThread> HostProcessWindows::StartMonitoring(
6779
const Host::MonitorChildProcessCallback &callback, bool monitor_signals) {
68-
MonitorInfo *info = new MonitorInfo;
69-
info->callback = callback;
80+
HANDLE process_handle;
7081

7182
// Since the life of this HostProcessWindows instance and the life of the
7283
// process may be different, duplicate the handle so that the monitor thread
7384
// can have ownership over its own copy of the handle.
7485
if (::DuplicateHandle(GetCurrentProcess(), m_process, GetCurrentProcess(),
75-
&info->process_handle, 0, FALSE, DUPLICATE_SAME_ACCESS)) {
76-
return ThreadLauncher::LaunchThread("ChildProcessMonitor",
77-
HostProcessWindows::MonitorThread,
78-
info);
86+
&process_handle, 0, FALSE, DUPLICATE_SAME_ACCESS)) {
87+
return ThreadLauncher::LaunchThread(
88+
"ChildProcessMonitor", [callback, process_handle] {
89+
return MonitorThread(callback, process_handle);
90+
});
7991
} else {
8092
return llvm::errorCodeToError(llvm::mapWindowsError(GetLastError()));
8193
}
8294
}
8395

84-
lldb::thread_result_t HostProcessWindows::MonitorThread(void *thread_arg) {
85-
DWORD exit_code;
86-
87-
MonitorInfo *info = static_cast<MonitorInfo *>(thread_arg);
88-
if (info) {
89-
::WaitForSingleObject(info->process_handle, INFINITE);
90-
::GetExitCodeProcess(info->process_handle, &exit_code);
91-
info->callback(::GetProcessId(info->process_handle), true, 0, exit_code);
92-
::CloseHandle(info->process_handle);
93-
delete (info);
94-
}
95-
return {};
96-
}
97-
9896
void HostProcessWindows::Close() {
9997
if (m_owns_handle && m_process != LLDB_INVALID_PROCESS)
10098
::CloseHandle(m_process);

0 commit comments

Comments
 (0)