Skip to content

Commit 0b5e136

Browse files
[lldb][NFC] Reduce scope of Swift customizations
The code in Process::HandleProcessStateChangedEvent is pretty complicated, and a lot of Swift customizations were added on top of it to support the repl. This commit reduces the area of those customizations by moving them into a separate function; in particular, the code computing whether to "check for a repl breakpoint" was factored out. The main motivation is that we would like to make some changes in HandleProcessStateChangedEvent, which would run into nasty merge conflicts otherwise.
1 parent 8670986 commit 0b5e136

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

lldb/source/Target/Process.cpp

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,44 @@ BreakpointSiteMatchesREPLBreakpoint(const BreakpointSiteSP &bp_site_sp) {
782782
return false;
783783
}
784784

785+
/// Returns true if reason is Trace/Breakpoint/Watchpoint/PlanComplete.
786+
static bool IsDebuggerCausedStop(StopReason reason) {
787+
switch (reason) {
788+
case eStopReasonInvalid:
789+
case eStopReasonNone:
790+
case eStopReasonSignal:
791+
case eStopReasonException:
792+
case eStopReasonExec:
793+
case eStopReasonFork:
794+
case eStopReasonVFork:
795+
case eStopReasonVForkDone:
796+
case eStopReasonThreadExiting:
797+
case eStopReasonInstrumentation:
798+
case eStopReasonProcessorTrace:
799+
return false;
800+
801+
case eStopReasonTrace:
802+
case eStopReasonBreakpoint:
803+
case eStopReasonWatchpoint:
804+
case eStopReasonPlanComplete:
805+
return true;
806+
}
807+
return false;
808+
}
809+
810+
/// Returns true if any thread in thread_list has a stop reason of
811+
/// Trace/Breakpoint/Watchpoint/PlanComplete.
812+
static bool AnyDebuggerCausedStop(ThreadList &thread_list) {
813+
for (const auto &thread_sp : thread_list.Threads()) {
814+
if (!thread_sp)
815+
continue;
816+
StopReason stop_reason = thread_sp->GetStopReason();
817+
if (IsDebuggerCausedStop(stop_reason))
818+
return true;
819+
}
820+
return false;
821+
}
822+
785823
bool Process::HandleProcessStateChangedEvent(
786824
const EventSP &event_sp, Stream *stream,
787825
SelectMostRelevant select_most_relevant,
@@ -933,8 +971,6 @@ bool Process::HandleProcessStateChangedEvent(
933971
case eStopReasonTrace:
934972
case eStopReasonBreakpoint:
935973
case eStopReasonWatchpoint:
936-
check_for_repl_breakpoint = repl_is_enabled;
937-
LLVM_FALLTHROUGH;
938974
case eStopReasonException:
939975
case eStopReasonExec:
940976
case eStopReasonFork:
@@ -947,7 +983,6 @@ bool Process::HandleProcessStateChangedEvent(
947983
other_thread = thread;
948984
break;
949985
case eStopReasonPlanComplete:
950-
check_for_repl_breakpoint = repl_is_enabled;
951986
if (!plan_thread)
952987
plan_thread = thread;
953988
break;
@@ -970,26 +1005,15 @@ bool Process::HandleProcessStateChangedEvent(
9701005
if (thread)
9711006
thread_list.SetSelectedThreadByID(thread->GetID());
9721007
}
973-
} else {
974-
switch (curr_thread_stop_reason) {
975-
case eStopReasonBreakpoint:
976-
case eStopReasonWatchpoint:
977-
check_for_repl_breakpoint = repl_is_enabled;
978-
break;
979-
case eStopReasonPlanComplete:
980-
// We might have hit a breakpoint during our REPL evaluation and be
981-
// stopped
982-
// at the REPL breakpoint
983-
check_for_repl_breakpoint = repl_is_enabled;
984-
break;
985-
default:
986-
break;
987-
}
9881008
}
1009+
1010+
check_for_repl_breakpoint =
1011+
prefer_curr_thread ? IsDebuggerCausedStop(curr_thread_stop_reason)
1012+
: AnyDebuggerCausedStop(thread_list);
9891013
}
9901014

9911015
BreakpointSiteSP bp_site_sp;
992-
if (check_for_repl_breakpoint) {
1016+
if (repl_is_enabled && check_for_repl_breakpoint) {
9931017
// Make sure this isn't the internal "REPL" breakpoint
9941018
if (curr_thread) {
9951019
StopInfoSP stop_info_sp = curr_thread->GetStopInfo();

0 commit comments

Comments
 (0)