Skip to content

Commit 5db0a07

Browse files
Merge pull request #10407 from felipepiovezan/felipe/repl_simplification
[lldb][NFC] Reduce scope of Swift customizations
2 parents 1ad4595 + 2af45d3 commit 5db0a07

File tree

1 file changed

+69
-51
lines changed

1 file changed

+69
-51
lines changed

lldb/source/Target/Process.cpp

Lines changed: 69 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,69 @@ 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+
823+
/// Returns true if curr_thread is not null and it is stopped at a REPL
824+
/// breakpoint.
825+
static bool IsREPLBreakpoint(Thread *curr_thread) {
826+
if (!curr_thread)
827+
return false;
828+
829+
Process &process = *curr_thread->GetProcess();
830+
831+
if (StopInfoSP stop_info_sp = curr_thread->GetStopInfo())
832+
if (BreakpointSiteSP bp_site_sp =
833+
process.GetBreakpointSiteList().FindByID(stop_info_sp->GetValue()))
834+
return BreakpointSiteMatchesREPLBreakpoint(bp_site_sp);
835+
836+
// Only check the breakpoint site for the current PC if the stop reason didn't
837+
// have a valid breakpoint site.
838+
if (StackFrameSP frame_sp = curr_thread->GetStackFrameAtIndex(0)) {
839+
if (BreakpointSiteSP bp_site_sp =
840+
process.GetBreakpointSiteList().FindByAddress(
841+
frame_sp->GetStackID().GetPC()))
842+
return BreakpointSiteMatchesREPLBreakpoint(bp_site_sp);
843+
}
844+
845+
return false;
846+
}
847+
785848
bool Process::HandleProcessStateChangedEvent(
786849
const EventSP &event_sp, Stream *stream,
787850
SelectMostRelevant select_most_relevant,
@@ -868,7 +931,6 @@ bool Process::HandleProcessStateChangedEvent(
868931
}
869932
} else {
870933
bool check_for_repl_breakpoint = false;
871-
bool is_repl_breakpoint = false;
872934
ThreadSP curr_thread;
873935
StopInfoSP curr_thread_stop_info_sp;
874936
// Lock the thread list so it doesn't change on us, this is the scope for
@@ -933,8 +995,6 @@ bool Process::HandleProcessStateChangedEvent(
933995
case eStopReasonTrace:
934996
case eStopReasonBreakpoint:
935997
case eStopReasonWatchpoint:
936-
check_for_repl_breakpoint = repl_is_enabled;
937-
LLVM_FALLTHROUGH;
938998
case eStopReasonException:
939999
case eStopReasonExec:
9401000
case eStopReasonFork:
@@ -947,7 +1007,6 @@ bool Process::HandleProcessStateChangedEvent(
9471007
other_thread = thread;
9481008
break;
9491009
case eStopReasonPlanComplete:
950-
check_for_repl_breakpoint = repl_is_enabled;
9511010
if (!plan_thread)
9521011
plan_thread = thread;
9531012
break;
@@ -970,57 +1029,16 @@ bool Process::HandleProcessStateChangedEvent(
9701029
if (thread)
9711030
thread_list.SetSelectedThreadByID(thread->GetID());
9721031
}
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-
}
9881032
}
989-
}
990-
991-
BreakpointSiteSP bp_site_sp;
992-
if (check_for_repl_breakpoint) {
993-
// Make sure this isn't the internal "REPL" breakpoint
994-
if (curr_thread) {
995-
StopInfoSP stop_info_sp = curr_thread->GetStopInfo();
996-
if (stop_info_sp) {
997-
bp_site_sp = process_sp->GetBreakpointSiteList().FindByID(
998-
stop_info_sp->GetValue());
999-
if (bp_site_sp) {
1000-
is_repl_breakpoint =
1001-
BreakpointSiteMatchesREPLBreakpoint(bp_site_sp);
1002-
}
1003-
}
10041033

1005-
// Only check the breakpoint site for the current PC if the stop
1006-
// reason didn't have
1007-
// a valid breakpoint site
1008-
if (!bp_site_sp) {
1009-
// We might have stopped with a eStopReasonPlanComplete, see the PC
1010-
// is at
1011-
1012-
lldb::StackFrameSP frame_sp = curr_thread->GetStackFrameAtIndex(0);
1013-
if (frame_sp) {
1014-
bp_site_sp = process_sp->GetBreakpointSiteList().FindByAddress(
1015-
frame_sp->GetStackID().GetPC());
1016-
if (bp_site_sp)
1017-
is_repl_breakpoint =
1018-
BreakpointSiteMatchesREPLBreakpoint(bp_site_sp);
1019-
}
1020-
}
1021-
}
1034+
check_for_repl_breakpoint =
1035+
prefer_curr_thread ? IsDebuggerCausedStop(curr_thread_stop_reason)
1036+
: AnyDebuggerCausedStop(thread_list);
10221037
}
10231038

1039+
bool is_repl_breakpoint = repl_is_enabled && check_for_repl_breakpoint &&
1040+
IsREPLBreakpoint(curr_thread.get());
1041+
10241042
// Drop the ThreadList mutex by here, since GetThreadStatus below might
10251043
// have to run code, e.g. for Data formatters, and if we hold the
10261044
// ThreadList mutex, then the process is going to have a hard time

0 commit comments

Comments
 (0)