Skip to content

Commit b97eb65

Browse files
committed
[lldb] Move thread_to_run selection to happen before SetupForResume() is called
Later, we'll need to know which thread will run before we determine the execution direction, which has to happen before we call `SetupForResume()`. We fix up `thread_to_run` after calling `SetupForResume()`, if required.
1 parent 8387ed9 commit b97eb65

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

lldb/source/Target/ThreadList.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,20 @@ bool ThreadList::WillResume() {
556556
}
557557
}
558558

559+
ThreadSP thread_to_run;
560+
if (run_me_only_list.GetSize(false) > 0) {
561+
if (stop_others_thread_sp) {
562+
thread_to_run = stop_others_thread_sp;
563+
} else if (run_me_only_list.GetSize(false) == 1) {
564+
thread_to_run = run_me_only_list.GetThreadAtIndex(0);
565+
} else {
566+
int random_thread =
567+
(int)((run_me_only_list.GetSize(false) * (double)rand()) /
568+
(RAND_MAX + 1.0));
569+
thread_to_run = run_me_only_list.GetThreadAtIndex(random_thread);
570+
}
571+
}
572+
559573
// Give all the threads that are likely to run a last chance to set up their
560574
// state before we negotiate who is actually going to get a chance to run...
561575
// Don't set to resume suspended threads, and if any thread wanted to stop
@@ -580,12 +594,15 @@ bool ThreadList::WillResume() {
580594
run_me_only_list.AddThread(thread_sp);
581595

582596
if (!(stop_others_thread_sp && stop_others_thread_sp->ShouldRunBeforePublicStop())) {
583-
if (thread_sp == GetSelectedThread())
597+
if (thread_sp == GetSelectedThread()) {
584598
stop_others_thread_sp = thread_sp;
599+
thread_to_run = thread_sp;
600+
}
585601

586602
if (thread_sp->ShouldRunBeforePublicStop()) {
587603
// This takes precedence, so if we find one of these, service it:
588604
stop_others_thread_sp = thread_sp;
605+
thread_to_run = thread_sp;
589606
break;
590607
}
591608
}
@@ -622,19 +639,6 @@ bool ThreadList::WillResume() {
622639
need_to_resume = false;
623640
}
624641
} else {
625-
ThreadSP thread_to_run;
626-
627-
if (stop_others_thread_sp) {
628-
thread_to_run = stop_others_thread_sp;
629-
} else if (run_me_only_list.GetSize(false) == 1) {
630-
thread_to_run = run_me_only_list.GetThreadAtIndex(0);
631-
} else {
632-
int random_thread =
633-
(int)((run_me_only_list.GetSize(false) * (double)rand()) /
634-
(RAND_MAX + 1.0));
635-
thread_to_run = run_me_only_list.GetThreadAtIndex(random_thread);
636-
}
637-
638642
for (pos = m_threads.begin(); pos != end; ++pos) {
639643
ThreadSP thread_sp(*pos);
640644
if (thread_sp == thread_to_run) {

0 commit comments

Comments
 (0)