230 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
245 thread_sp->IsStillAtLastBreakpointHit()
246 || thread_sp->ShouldRunBeforePublicStop())
247 threads_copy.push_back(thread_sp);
254 if (threads_copy.size() == 0)
258 collection::iterator pos, end = threads_copy.end();
263 "ThreadList::%s: %" PRIu64
" threads, %" PRIu64
264 " unsuspended threads",
265 __FUNCTION__, (uint64_t)
m_threads.size(),
266 (uint64_t)threads_copy.size());
269 bool did_anybody_stop_for_a_reason =
false;
273 bool should_stop =
false;
276 log,
"ThreadList::%s handling interrupt event, should stop set to true",
289 for (pos = threads_copy.begin(); pos != end; ++pos) {
291 thread_sp->GetStopInfo();
297 bool a_thread_needs_to_run =
false;
298 for (pos = threads_copy.begin(); pos != end; ++pos) {
321 if (thread_sp->GetProcess()->GetStopID() > 1)
322 did_anybody_stop_for_a_reason =
true;
324 did_anybody_stop_for_a_reason |= thread_sp->ThreadStoppedForAReason();
326 const bool thread_should_stop = thread_sp->ShouldStop(event_ptr);
328 if (thread_should_stop)
331 bool this_thread_forces_run = thread_sp->ShouldRunBeforePublicStop();
332 a_thread_needs_to_run |= this_thread_forces_run;
333 if (this_thread_forces_run)
335 "ThreadList::{0} thread: {1:x}, "
336 "says it needs to run before public stop.",
337 __FUNCTION__, thread_sp->GetID());
341 if (a_thread_needs_to_run) {
343 }
else if (!should_stop && !did_anybody_stop_for_a_reason) {
346 "ThreadList::%s we stopped but no threads had a stop reason, "
347 "overriding should_stop and stopping.",
351 LLDB_LOGF(log,
"ThreadList::%s overall should_stop = %i", __FUNCTION__,
355 for (pos = threads_copy.begin(); pos != end; ++pos) {
357 thread_sp->WillStop();
506 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
509 collection::iterator pos, end =
m_threads.end();
516 for (
const auto &thread_sp :
m_threads) {
517 ThreadPlan *plan = thread_sp->GetCurrentPlan();
524 if (bp_plan->GetDeferReenableBreakpointSite()) {
528 bp_plan->SetReenabledBreakpointSite();
529 thread_sp->DiscardPlan();
539 llvm::SmallVector<ThreadSP> batched_step_threads;
552 for (pos =
m_threads.begin(); pos != end; ++pos) {
555 thread_sp->GetCurrentPlan()->StopOthers()) {
556 if (thread_sp->IsOperatingSystemPluginThread() &&
557 !thread_sp->GetBackingThread())
565 thread_to_run = thread_sp;
567 if (thread_sp->ShouldRunBeforePublicStop()) {
569 thread_to_run = thread_sp;
575 if (run_me_only_list.
GetSize(
false) > 0 && !thread_to_run) {
576 if (run_me_only_list.
GetSize(
false) == 1) {
580 (int)((run_me_only_list.
GetSize(
false) * (
double)rand()) /
586 if (thread_to_run !=
nullptr) {
587 direction = thread_to_run->GetCurrentPlan()->GetDirection();
589 direction =
m_process.GetBaseDirection();
596 if (thread_to_run !=
nullptr) {
603 if (thread_to_run->SetupToStepOverBreakpointIfNeeded(direction)) {
607 assert(thread_to_run->GetCurrentPlan()->GetDirection() == direction);
614 llvm::DenseMap<lldb::addr_t, llvm::SmallVector<ThreadSP>> breakpoint_groups;
615 bool found_run_before_public_stop =
false;
617 for (pos =
m_threads.begin(); pos != end; ++pos) {
620 if (thread_sp->IsOperatingSystemPluginThread() &&
621 !thread_sp->GetBackingThread())
623 if (thread_sp->SetupToStepOverBreakpointIfNeeded(direction)) {
627 assert(thread_sp->GetCurrentPlan()->GetDirection() == direction);
632 ThreadPlan *current_plan = thread_sp->GetCurrentPlan();
638 breakpoint_groups[bp_addr].push_back(thread_sp);
641 thread_to_run = thread_sp;
642 if (thread_sp->ShouldRunBeforePublicStop()) {
644 found_run_before_public_stop =
true;
655 if (!found_run_before_public_stop) {
660 for (
auto &group : breakpoint_groups) {
662 llvm::SmallVector<ThreadSP> &threads = group.second;
664 if (threads.size() > 1) {
667 for (
ThreadSP &thread_sp : threads) {
672 ThreadPlan *plan = thread_sp->GetCurrentPlan();
683 if (threads.size() > batched_step_threads.size())
684 batched_step_threads = threads;
690 if (!batched_step_threads.empty())
691 thread_to_run = batched_step_threads[0];
695 if (thread_to_run !=
nullptr) {
697 "Turning on notification of new threads while single "
698 "stepping a thread.");
702 "Turning off notification of new threads while single "
703 "stepping a thread.");
707 bool need_to_resume =
true;
714 const char *name = thread_sp->GetName();
717 llvm::StringRef name_str(name);
722 "Thread \"{0}\" (tid={1:x}) will continue due to "
723 "always-run-thread-names setting",
724 name, thread_sp->GetID());
731 if (!batched_step_threads.empty()) {
734 llvm::DenseSet<lldb::tid_t> batch_tids;
735 for (
ThreadSP &thread_sp : batched_step_threads)
736 batch_tids.insert(thread_sp->GetID());
738 for (
const auto &thread_sp :
m_threads) {
739 if (batch_tids.count(thread_sp->GetID()) > 0) {
741 if (!thread_sp->ShouldResume(thread_sp->GetCurrentPlan()->RunState()))
742 need_to_resume =
false;
745 thread_sp->ShouldResume(resume_state_for_thread(thread_sp));
748 }
else if (thread_to_run ==
nullptr) {
750 for (pos =
m_threads.begin(); pos != end; ++pos) {
754 run_state = thread_sp->GetCurrentPlan()->RunState();
757 if (!thread_sp->ShouldResume(run_state))
758 need_to_resume =
false;
760 if (need_to_resume) {
762 for (pos =
m_threads.begin(); pos != end; ++pos) {
764 while (thread_sp->GetCurrentPlan()->GetDirection() != direction) {
767 thread_sp->DiscardPlan();
772 for (pos =
m_threads.begin(); pos != end; ++pos) {
774 if (thread_sp == thread_to_run) {
778 if (!thread_sp->ShouldResume(thread_sp->GetCurrentPlan()->RunState()))
779 need_to_resume =
false;
781 thread_sp->ShouldResume(resume_state_for_thread(thread_sp));
785 return need_to_resume;