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();
505 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
508 collection::iterator pos, end =
m_threads.end();
515 for (
const auto &thread_sp :
m_threads) {
516 ThreadPlan *plan = thread_sp->GetCurrentPlan();
523 if (bp_plan->GetDeferReenableBreakpointSite()) {
527 bp_plan->SetReenabledBreakpointSite();
528 thread_sp->DiscardPlan();
538 llvm::SmallVector<ThreadSP> batched_step_threads;
551 for (pos =
m_threads.begin(); pos != end; ++pos) {
554 thread_sp->GetCurrentPlan()->StopOthers()) {
555 if (thread_sp->IsOperatingSystemPluginThread() &&
556 !thread_sp->GetBackingThread())
564 thread_to_run = thread_sp;
566 if (thread_sp->ShouldRunBeforePublicStop()) {
568 thread_to_run = thread_sp;
574 if (run_me_only_list.
GetSize(
false) > 0 && !thread_to_run) {
575 if (run_me_only_list.
GetSize(
false) == 1) {
579 (int)((run_me_only_list.
GetSize(
false) * (
double)rand()) /
585 if (thread_to_run !=
nullptr) {
586 direction = thread_to_run->GetCurrentPlan()->GetDirection();
588 direction =
m_process.GetBaseDirection();
595 if (thread_to_run !=
nullptr) {
602 if (thread_to_run->SetupToStepOverBreakpointIfNeeded(direction)) {
606 assert(thread_to_run->GetCurrentPlan()->GetDirection() == direction);
613 llvm::DenseMap<lldb::addr_t, llvm::SmallVector<ThreadSP>> breakpoint_groups;
614 bool found_run_before_public_stop =
false;
616 for (pos =
m_threads.begin(); pos != end; ++pos) {
619 if (thread_sp->IsOperatingSystemPluginThread() &&
620 !thread_sp->GetBackingThread())
622 if (thread_sp->SetupToStepOverBreakpointIfNeeded(direction)) {
626 assert(thread_sp->GetCurrentPlan()->GetDirection() == direction);
631 ThreadPlan *current_plan = thread_sp->GetCurrentPlan();
637 breakpoint_groups[bp_addr].push_back(thread_sp);
640 thread_to_run = thread_sp;
641 if (thread_sp->ShouldRunBeforePublicStop()) {
643 found_run_before_public_stop =
true;
654 if (!found_run_before_public_stop) {
659 for (
auto &group : breakpoint_groups) {
661 llvm::SmallVector<ThreadSP> &threads = group.second;
663 if (threads.size() > 1) {
666 for (
ThreadSP &thread_sp : threads) {
671 ThreadPlan *plan = thread_sp->GetCurrentPlan();
682 if (threads.size() > batched_step_threads.size())
683 batched_step_threads = threads;
689 if (!batched_step_threads.empty())
690 thread_to_run = batched_step_threads[0];
694 if (thread_to_run !=
nullptr) {
697 LLDB_LOGF(log,
"Turning on notification of new threads while single "
698 "stepping a thread.");
703 LLDB_LOGF(log,
"Turning off notification of new threads while single "
704 "stepping a thread.");
708 bool need_to_resume =
true;
710 if (!batched_step_threads.empty()) {
713 llvm::DenseSet<lldb::tid_t> batch_tids;
714 for (
ThreadSP &thread_sp : batched_step_threads)
715 batch_tids.insert(thread_sp->GetID());
717 for (
const auto &thread_sp :
m_threads) {
718 if (batch_tids.count(thread_sp->GetID()) > 0) {
720 if (!thread_sp->ShouldResume(thread_sp->GetCurrentPlan()->RunState()))
721 need_to_resume =
false;
727 }
else if (thread_to_run ==
nullptr) {
729 for (pos =
m_threads.begin(); pos != end; ++pos) {
733 run_state = thread_sp->GetCurrentPlan()->RunState();
736 if (!thread_sp->ShouldResume(run_state))
737 need_to_resume =
false;
739 if (need_to_resume) {
741 for (pos =
m_threads.begin(); pos != end; ++pos) {
743 while (thread_sp->GetCurrentPlan()->GetDirection() != direction) {
746 thread_sp->DiscardPlan();
751 for (pos =
m_threads.begin(); pos != end; ++pos) {
753 if (thread_sp == thread_to_run) {
757 if (!thread_sp->ShouldResume(thread_sp->GetCurrentPlan()->RunState()))
758 need_to_resume =
false;
764 return need_to_resume;
930 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
938 "ThreadList::%s: Thread 0x%" PRIx64
939 " finished stepping over breakpoint at 0x%" PRIx64
940 " but no threads were registered, re-enabling directly",
941 __FUNCTION__, tid, breakpoint_addr);
943 m_process.GetBreakpointSiteList().FindByAddress(breakpoint_addr))
944 m_process.EnableBreakpointSite(bp_site_sp.get());
949 it->second.erase(tid);
952 "ThreadList::%s: Thread 0x%" PRIx64
953 " finished stepping over breakpoint at 0x%" PRIx64
954 " (%zu threads remaining)",
955 __FUNCTION__, tid, breakpoint_addr,
956 static_cast<size_t>(it->second.size()));
959 if (it->second.empty()) {
961 "ThreadList::%s: All threads finished stepping over breakpoint "
962 "at 0x%" PRIx64
", re-enabling breakpoint",
963 __FUNCTION__, breakpoint_addr);
966 m_process.GetBreakpointSiteList().FindByAddress(breakpoint_addr))
967 m_process.EnableBreakpointSite(bp_site_sp.get());