Skip to content

Commit ce18439

Browse files
Merge pull request #10490 from felipepiovezan/felipe/override_should_show_should_select_62
[cherry-pick][lldb] Override Should{Select,Show} in StopReasonBreakpoint (llvm#135637)
2 parents 25fb7ff + cc12b57 commit ce18439

File tree

3 files changed

+42
-67
lines changed

3 files changed

+42
-67
lines changed

lldb/include/lldb/Target/StopInfo.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ class StopInfo : public std::enable_shared_from_this<StopInfo> {
117117

118118
StructuredData::ObjectSP GetExtendedInfo() { return m_extended_info; }
119119

120+
/// Returns true if this is a stop reason that should be shown to a user when
121+
/// stopping.
122+
virtual bool ShouldShow() const { return IsValid(); }
123+
124+
/// Returns true if this is a stop reason that should cause a thread to be
125+
/// selected when stopping.
126+
virtual bool ShouldSelect() const {
127+
return GetStopReason() != lldb::eStopReasonNone &&
128+
GetStopReason() != lldb::eStopReasonInvalid;
129+
}
130+
120131
static lldb::StopInfoSP
121132
CreateStopReasonWithBreakpointSiteID(Thread &thread,
122133
lldb::break_id_t break_id);

lldb/source/Target/Process.cpp

Lines changed: 17 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -940,77 +940,29 @@ bool Process::HandleProcessStateChangedEvent(
940940
std::lock_guard<std::recursive_mutex> guard(thread_list.GetMutex());
941941

942942
curr_thread = thread_list.GetSelectedThread();
943-
ThreadSP thread;
944-
StopReason curr_thread_stop_reason = eStopReasonInvalid;
945-
bool prefer_curr_thread = false;
946-
if (curr_thread && curr_thread->IsValid()) {
947-
curr_thread_stop_reason = curr_thread->GetStopReason();
948-
switch (curr_thread_stop_reason) {
949-
case eStopReasonNone:
950-
case eStopReasonInvalid:
951-
// Don't prefer the current thread if it didn't stop for a reason.
952-
break;
953-
case eStopReasonSignal: {
954-
// We need to do the same computation we do for other threads
955-
// below in case the current thread happens to be the one that
956-
// stopped for the no-stop signal.
957-
uint64_t signo = curr_thread->GetStopInfo()->GetValue();
958-
if (process_sp->GetUnixSignals()->GetShouldStop(signo))
959-
prefer_curr_thread = true;
960-
} break;
961-
default:
962-
prefer_curr_thread = true;
963-
break;
964-
}
943+
944+
if (curr_thread && curr_thread->IsValid())
965945
curr_thread_stop_info_sp = curr_thread->GetStopInfo();
966-
}
946+
bool prefer_curr_thread = curr_thread_stop_info_sp &&
947+
curr_thread_stop_info_sp->ShouldSelect();
967948

968949
if (!prefer_curr_thread) {
969950
// Prefer a thread that has just completed its plan over another
970951
// thread as current thread.
971952
ThreadSP plan_thread;
972953
ThreadSP other_thread;
973954

974-
const size_t num_threads = thread_list.GetSize();
975-
size_t i;
976-
for (i = 0; i < num_threads; ++i) {
977-
thread = thread_list.GetThreadAtIndex(i);
978-
StopReason thread_stop_reason = thread->GetStopReason();
979-
switch (thread_stop_reason) {
980-
case eStopReasonInvalid:
981-
case eStopReasonNone:
982-
break;
983-
984-
case eStopReasonSignal: {
985-
// Don't select a signal thread if we weren't going to stop at
986-
// that signal. We have to have had another reason for stopping
987-
// here, and the user doesn't want to see this thread.
988-
uint64_t signo = thread->GetStopInfo()->GetValue();
989-
if (process_sp->GetUnixSignals()->GetShouldStop(signo)) {
990-
if (!other_thread)
991-
other_thread = thread;
992-
}
993-
break;
994-
}
995-
case eStopReasonTrace:
996-
case eStopReasonBreakpoint:
997-
case eStopReasonWatchpoint:
998-
case eStopReasonException:
999-
case eStopReasonExec:
1000-
case eStopReasonFork:
1001-
case eStopReasonVFork:
1002-
case eStopReasonVForkDone:
1003-
case eStopReasonThreadExiting:
1004-
case eStopReasonInstrumentation:
1005-
case eStopReasonProcessorTrace:
1006-
if (!other_thread)
1007-
other_thread = thread;
1008-
break;
1009-
case eStopReasonPlanComplete:
955+
for (ThreadSP thread : thread_list.Threads()) {
956+
StopInfoSP stop_info = thread->GetStopInfo();
957+
if (!stop_info || !stop_info->ShouldSelect())
958+
continue;
959+
StopReason thread_stop_reason = stop_info->GetStopReason();
960+
if (thread_stop_reason == eStopReasonPlanComplete) {
1010961
if (!plan_thread)
1011962
plan_thread = thread;
1012-
break;
1013963
}
964+
else if (!other_thread)
965+
other_thread = thread;
1014966
}
1015967
if (plan_thread) {
1016968
thread_list.SetSelectedThreadByID(plan_thread->GetID());
@@ -1019,6 +971,7 @@ bool Process::HandleProcessStateChangedEvent(
1019971
thread_list.SetSelectedThreadByID(other_thread->GetID());
1020972
curr_thread = other_thread;
1021973
} else {
974+
ThreadSP thread;
1022975
if (curr_thread && curr_thread->IsValid())
1023976
thread = curr_thread;
1024977
else {
@@ -1031,6 +984,9 @@ bool Process::HandleProcessStateChangedEvent(
1031984
}
1032985
}
1033986

987+
StopReason curr_thread_stop_reason =
988+
curr_thread_stop_info_sp ? curr_thread_stop_info_sp->GetStopReason()
989+
: eStopReasonInvalid;
1034990
check_for_repl_breakpoint =
1035991
prefer_curr_thread ? IsDebuggerCausedStop(curr_thread_stop_reason)
1036992
: AnyDebuggerCausedStop(thread_list);
@@ -5940,7 +5896,7 @@ size_t Process::GetThreadStatus(Stream &strm,
59405896
if (thread_sp) {
59415897
if (only_threads_with_stop_reason) {
59425898
StopInfoSP stop_info_sp = thread_sp->GetStopInfo();
5943-
if (!stop_info_sp || !stop_info_sp->IsValid())
5899+
if (!stop_info_sp || !stop_info_sp->ShouldShow())
59445900
continue;
59455901
}
59465902
thread_sp->GetStatus(strm, start_frame, num_frames,

lldb/source/Target/StopInfo.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ class StopInfoBreakpoint : public StopInfo {
263263
return bp_site_sp->GetSuggestedStackFrameIndex();
264264
}
265265

266+
bool ShouldShow() const override { return !m_was_all_internal; }
267+
268+
bool ShouldSelect() const override { return !m_was_all_internal; }
269+
266270
protected:
267271
bool ShouldStop(Event *event_ptr) override {
268272
// This just reports the work done by PerformAction or the synchronous
@@ -1080,12 +1084,7 @@ class StopInfoUnixSignal : public StopInfo {
10801084
return false;
10811085
}
10821086

1083-
bool ShouldStop(Event *event_ptr) override {
1084-
ThreadSP thread_sp(m_thread_wp.lock());
1085-
if (thread_sp)
1086-
return thread_sp->GetProcess()->GetUnixSignals()->GetShouldStop(m_value);
1087-
return false;
1088-
}
1087+
bool ShouldStop(Event *event_ptr) override { return IsShouldStopSignal(); }
10891088

10901089
// If should stop returns false, check if we should notify of this event
10911090
bool DoShouldNotify(Event *event_ptr) override {
@@ -1137,9 +1136,18 @@ class StopInfoUnixSignal : public StopInfo {
11371136
return m_description.c_str();
11381137
}
11391138

1139+
bool ShouldSelect() const override { return IsShouldStopSignal(); }
1140+
11401141
private:
11411142
// In siginfo_t terms, if m_value is si_signo, m_code is si_code.
11421143
std::optional<int> m_code;
1144+
1145+
bool IsShouldStopSignal() const {
1146+
ThreadSP thread_sp(m_thread_wp.lock());
1147+
if (thread_sp)
1148+
return thread_sp->GetProcess()->GetUnixSignals()->GetShouldStop(m_value);
1149+
return false;
1150+
}
11431151
};
11441152

11451153
// StopInfoTrace

0 commit comments

Comments
 (0)