File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
lldb/source/Plugins/Process/Windows/Common Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -169,6 +169,38 @@ Status ProcessWindows::DoDetach(bool keep_stopped) {
169169 Log *log = GetLog (WindowsLog::Process);
170170 StateType private_state = GetPrivateState ();
171171 if (private_state != eStateExited && private_state != eStateDetached) {
172+ if (!keep_stopped) {
173+ // if the thread is suspended by lldb, we have to resume threads before
174+ // detaching process. When we do after DetachProcess(), thread handles
175+ // become invalid so we do before detach.
176+ if (private_state == eStateStopped || private_state == eStateCrashed) {
177+ LLDB_LOG (log, " process {0} is in state {1}. Resuming for detach..." ,
178+ m_session_data->m_debugger ->GetProcess ().GetProcessId (),
179+ GetPrivateState ());
180+
181+ LLDB_LOG (log, " resuming {0} threads for detach." ,
182+ m_thread_list.GetSize ());
183+
184+ bool failed = false ;
185+ for (uint32_t i = 0 ; i < m_thread_list.GetSize (); ++i) {
186+ auto thread = std::static_pointer_cast<TargetThreadWindows>(
187+ m_thread_list.GetThreadAtIndex (i));
188+ Status result = thread->DoResume ();
189+ if (result.Fail ()) {
190+ failed = true ;
191+ LLDB_LOG (log,
192+ " Trying to resume thread at index {0}, but failed with "
193+ " error {1}." ,
194+ i, result);
195+ }
196+ }
197+
198+ if (failed) {
199+ error = Status::FromErrorString (" Resuming Threads for Detach failed" );
200+ }
201+ }
202+ }
203+
172204 error = DetachProcess ();
173205 if (error.Success ())
174206 SetPrivateState (eStateDetached);
You can’t perform that action at this time.
0 commit comments