================ @@ -169,6 +169,38 @@ Status ProcessWindows::DoDetach(bool keep_stopped) { Log *log = GetLog(WindowsLog::Process); StateType private_state = GetPrivateState(); if (private_state != eStateExited && private_state != eStateDetached) { + if (!keep_stopped) { + // if the thread is suspended by lldb, we have to resume threads before + // detaching process. When we do after DetachProcess(), thread handles + // become invalid so we do before detach. + if (private_state == eStateStopped || private_state == eStateCrashed) { + LLDB_LOG(log, "process {0} is in state {1}. Resuming for detach...", + m_session_data->m_debugger->GetProcess().GetProcessId(), + GetPrivateState()); + + LLDB_LOG(log, "resuming {0} threads for detach.", + m_thread_list.GetSize()); + + bool failed = false; + for (uint32_t i = 0; i < m_thread_list.GetSize(); ++i) { + auto thread = std::static_pointer_cast<TargetThreadWindows>( + m_thread_list.GetThreadAtIndex(i)); + Status result = thread->DoResume(); ---------------- labath wrote:
Does this mean that if the thread/process gets another exception before we manage to detach from it, it will remain suspended? I'm not familiar with windows debugging API, so I don't know if there's a way to handle this, but I believe this is the reason why linux (and others) have a PTRACE_DETACH call which (atomically) detaches from a process/thread *and* resumes it. https://github.com/llvm/llvm-project/pull/115712 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits