[Lldb-commits] [lldb] [lldb][NFC] Move ShouldShow/ShouldSelect logic into Stopinfo (PR #134160)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Wed Apr 2 23:14:15 PDT 2025
================
@@ -808,85 +808,35 @@ bool Process::HandleProcessStateChangedEvent(
std::lock_guard<std::recursive_mutex> guard(thread_list.GetMutex());
ThreadSP curr_thread(thread_list.GetSelectedThread());
- ThreadSP thread;
- StopReason curr_thread_stop_reason = eStopReasonInvalid;
- bool prefer_curr_thread = false;
- if (curr_thread && curr_thread->IsValid()) {
- curr_thread_stop_reason = curr_thread->GetStopReason();
- switch (curr_thread_stop_reason) {
- case eStopReasonNone:
- case eStopReasonInvalid:
- // Don't prefer the current thread if it didn't stop for a reason.
- break;
- case eStopReasonSignal: {
- // We need to do the same computation we do for other threads
- // below in case the current thread happens to be the one that
- // stopped for the no-stop signal.
- uint64_t signo = curr_thread->GetStopInfo()->GetValue();
- if (process_sp->GetUnixSignals()->GetShouldStop(signo))
- prefer_curr_thread = true;
- } break;
- default:
- prefer_curr_thread = true;
- break;
- }
+
+ if (curr_thread && curr_thread->IsValid())
curr_thread_stop_info_sp = curr_thread->GetStopInfo();
- }
+ bool prefer_curr_thread = curr_thread_stop_info_sp &&
+ curr_thread_stop_info_sp->ShouldSelect();
if (!prefer_curr_thread) {
// Prefer a thread that has just completed its plan over another
// thread as current thread.
ThreadSP plan_thread;
ThreadSP other_thread;
- const size_t num_threads = thread_list.GetSize();
- size_t i;
- for (i = 0; i < num_threads; ++i) {
- thread = thread_list.GetThreadAtIndex(i);
- StopReason thread_stop_reason = thread->GetStopReason();
- switch (thread_stop_reason) {
- case eStopReasonInvalid:
- case eStopReasonNone:
- case eStopReasonHistoryBoundary:
- break;
-
- case eStopReasonSignal: {
- // Don't select a signal thread if we weren't going to stop at
- // that signal. We have to have had another reason for stopping
- // here, and the user doesn't want to see this thread.
- uint64_t signo = thread->GetStopInfo()->GetValue();
- if (process_sp->GetUnixSignals()->GetShouldStop(signo)) {
- if (!other_thread)
- other_thread = thread;
- }
- break;
- }
- case eStopReasonTrace:
- case eStopReasonBreakpoint:
- case eStopReasonWatchpoint:
- case eStopReasonException:
- case eStopReasonExec:
- case eStopReasonFork:
- case eStopReasonVFork:
- case eStopReasonVForkDone:
- case eStopReasonThreadExiting:
- case eStopReasonInstrumentation:
- case eStopReasonProcessorTrace:
- case eStopReasonInterrupt:
- if (!other_thread)
- other_thread = thread;
- break;
- case eStopReasonPlanComplete:
+ for (ThreadSP thread : thread_list.Threads()) {
+ StopInfoSP stop_info = thread->GetStopInfo();
+ if (!stop_info || !stop_info->ShouldSelect())
+ continue;
+ StopReason thread_stop_reason = stop_info->GetStopReason();
+ if (thread_stop_reason == eStopReasonPlanComplete) {
if (!plan_thread)
plan_thread = thread;
- break;
- }
+ } else if (!other_thread)
+ other_thread = thread;
----------------
JDevlieghere wrote:
The [LLVM Style Guide](https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements) says to "[u]se braces for the `else if` and `else` block to keep it uniform with the `if` block."
```suggestion
} else if (!other_thread) {
other_thread = thread;
}
```
https://github.com/llvm/llvm-project/pull/134160
More information about the lldb-commits
mailing list