@@ -782,6 +782,69 @@ BreakpointSiteMatchesREPLBreakpoint(const BreakpointSiteSP &bp_site_sp) {
782
782
return false ;
783
783
}
784
784
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
+
785
848
bool Process::HandleProcessStateChangedEvent (
786
849
const EventSP &event_sp, Stream *stream,
787
850
SelectMostRelevant select_most_relevant,
@@ -868,7 +931,6 @@ bool Process::HandleProcessStateChangedEvent(
868
931
}
869
932
} else {
870
933
bool check_for_repl_breakpoint = false ;
871
- bool is_repl_breakpoint = false ;
872
934
ThreadSP curr_thread;
873
935
StopInfoSP curr_thread_stop_info_sp;
874
936
// Lock the thread list so it doesn't change on us, this is the scope for
@@ -933,8 +995,6 @@ bool Process::HandleProcessStateChangedEvent(
933
995
case eStopReasonTrace:
934
996
case eStopReasonBreakpoint:
935
997
case eStopReasonWatchpoint:
936
- check_for_repl_breakpoint = repl_is_enabled;
937
- LLVM_FALLTHROUGH;
938
998
case eStopReasonException:
939
999
case eStopReasonExec:
940
1000
case eStopReasonFork:
@@ -947,7 +1007,6 @@ bool Process::HandleProcessStateChangedEvent(
947
1007
other_thread = thread;
948
1008
break ;
949
1009
case eStopReasonPlanComplete:
950
- check_for_repl_breakpoint = repl_is_enabled;
951
1010
if (!plan_thread)
952
1011
plan_thread = thread;
953
1012
break ;
@@ -970,57 +1029,16 @@ bool Process::HandleProcessStateChangedEvent(
970
1029
if (thread)
971
1030
thread_list.SetSelectedThreadByID (thread->GetID ());
972
1031
}
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
- }
988
1032
}
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
- }
1004
1033
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);
1022
1037
}
1023
1038
1039
+ bool is_repl_breakpoint = repl_is_enabled && check_for_repl_breakpoint &&
1040
+ IsREPLBreakpoint (curr_thread.get ());
1041
+
1024
1042
// Drop the ThreadList mutex by here, since GetThreadStatus below might
1025
1043
// have to run code, e.g. for Data formatters, and if we hold the
1026
1044
// ThreadList mutex, then the process is going to have a hard time
0 commit comments