debugserver all-stop thread coordination
ProcessWillResume applies a resume plan across the task’s threads, keeping non-selected threads suspended and preparing the selected stepping or running thread.
MachThreadList::ProcessWillResume source
void MachThreadList::ProcessWillResume(
MachProcess *process, const DNBThreadResumeActions &thread_actions) {
std::lock_guard<std::recursive_mutex> guard(m_threads_mutex);
// Update our thread list, because sometimes libdispatch or the kernel
// will spawn threads while a task is suspended.
MachThreadList::collection new_threads;
// First figure out if we were planning on running only one thread, and if so
// force that thread to resume.
bool run_one_thread;
nub_thread_t solo_thread = INVALID_NUB_THREAD;
if (thread_actions.GetSize() > 0 &&
thread_actions.NumActionsWithState(eStateStepping) +
thread_actions.NumActionsWithState(eStateRunning) ==
1) {
run_one_thread = true;
const DNBThreadResumeAction *action_ptr = thread_actions.GetFirst();
size_t num_actions = thread_actions.GetSize();
for (size_t i = 0; i < num_actions; i++, action_ptr++) {
if (action_ptr->state == eStateStepping ||
action_ptr->state == eStateRunning) {
solo_thread = action_ptr->tid;
break;
}
}
} else
run_one_thread = false;
UpdateThreadList(process, true, &new_threads);
… more in source