Skip to content

Commit b0186c2

Browse files
committed
[lldb] Refine ThreadPlan::ShouldAutoContinue
Adjust `ShouldAutoContinue` to be available to any thread plan previous to the plan that explains a stop, not limited to the parent to the plan that explains the stop. Before this change, `Thread::ShouldStop` did the following: 1. find the plan that explains the stop 2. if it's not a master plan, continue processing previous (aka parent) plans 3. first, call `ShouldAutoContinue` on the immediate parent of the explaining plan 4. then loop over previous plans, calling `ShouldStop` and `MischiefManaged` Of note, the iteration in step 4 does not call `ShouldAutoContinue`, so again only the plan just prior to the explaining plan is given the opportunity to override whether to continue or stop. This commit changes the loop call `ShouldAutoContinue`, giving each plan the opportunity to override `ShouldStop` of previous plans. Why? This allows a plan to do the following: 1. mark itself done and be popped off the stack 2. allow parent plans to finish their work, and to also be popped off the stack 3. and finally, have the thread continue, not stop This is useful for stepping into async functions. A plan will would step far enough enough to set a breakpoint on the async target, and then use `ShouldAutoContinue` to unwind the necessary stepping, and then have the calling thread continue. Differential Revision: https://reviews.llvm.org/D97076
1 parent fa211f3 commit b0186c2

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

lldb/include/lldb/Target/ThreadPlan.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,12 @@ class ThreadPlan : public std::enable_shared_from_this<ThreadPlan>,
361361

362362
virtual bool ShouldStop(Event *event_ptr) = 0;
363363

364+
/// Returns whether this thread plan overrides the `ShouldStop` of
365+
/// subsequently processed plans.
366+
///
367+
/// When processing the thread plan stack, this function gives plans the
368+
/// ability to continue - even when subsequent plans return true from
369+
/// `ShouldStop`. \see Thread::ShouldStop
364370
virtual bool ShouldAutoContinue(Event *event_ptr) { return false; }
365371

366372
// Whether a "stop class" event should be reported to the "outside world".

lldb/source/Target/Thread.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,8 @@ bool Thread::ShouldStop(Event *event_ptr) {
829829
ThreadPlan *plan_ptr = current_plan;
830830
while ((plan_ptr = GetPreviousPlan(plan_ptr)) != nullptr) {
831831
if (plan_ptr->PlanExplainsStop(event_ptr)) {
832+
LLDB_LOGF(log, "Plan %s explains stop.", plan_ptr->GetName());
833+
832834
should_stop = plan_ptr->ShouldStop(event_ptr);
833835

834836
// plan_ptr explains the stop, next check whether plan_ptr is done,
@@ -860,10 +862,7 @@ bool Thread::ShouldStop(Event *event_ptr) {
860862
}
861863

862864
if (!done_processing_current_plan) {
863-
bool over_ride_stop = current_plan->ShouldAutoContinue(event_ptr);
864-
865-
LLDB_LOGF(log, "Plan %s explains stop, auto-continue %i.",
866-
current_plan->GetName(), over_ride_stop);
865+
bool override_stop = false;
867866

868867
// We're starting from the base plan, so just let it decide;
869868
if (current_plan->IsBasePlan()) {
@@ -884,28 +883,32 @@ bool Thread::ShouldStop(Event *event_ptr) {
884883
if (should_stop)
885884
current_plan->WillStop();
886885

887-
// If a Master Plan wants to stop, and wants to stick on the stack,
888-
// we let it. Otherwise, see if the plan's parent wants to stop.
886+
if (current_plan->ShouldAutoContinue(event_ptr)) {
887+
override_stop = true;
888+
LLDB_LOGF(log, "Plan %s auto-continue: true.",
889+
current_plan->GetName());
890+
}
891+
892+
// If a Master Plan wants to stop, we let it. Otherwise, see if the
893+
// plan's parent wants to stop.
889894

895+
PopPlan();
890896
if (should_stop && current_plan->IsMasterPlan() &&
891897
!current_plan->OkayToDiscard()) {
892-
PopPlan();
893898
break;
894-
} else {
895-
PopPlan();
899+
}
896900

897-
current_plan = GetCurrentPlan();
898-
if (current_plan == nullptr) {
899-
break;
900-
}
901+
current_plan = GetCurrentPlan();
902+
if (current_plan == nullptr) {
903+
break;
901904
}
902905
} else {
903906
break;
904907
}
905908
}
906909
}
907910

908-
if (over_ride_stop)
911+
if (override_stop)
909912
should_stop = false;
910913
}
911914

0 commit comments

Comments
 (0)