From: Simon Marchi Date: Wed, 3 Sep 2025 14:49:58 +0000 (-0400) Subject: gdb: change all_threads_safe to yield references X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=675a17a8a5cde1d8be86536df2ae6366ef0ec759;p=thirdparty%2Fbinutils-gdb.git gdb: change all_threads_safe to yield references To be consistent with all_threads and the others, following the previous patch. Change-Id: I4ee4ff32b005fc5554a9d637725f10fca70cee14 Approved-By: Tom Tromey --- diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index b124cee08b5..759034f332e 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -787,9 +787,9 @@ all_non_exited_threads (process_stratum_target *proc_target = nullptr, currently-iterated thread. When combined with range-for, this allow convenient patterns like this: - for (thread_info *t : all_threads_safe ()) + for (thread_info &t : all_threads_safe ()) if (some_condition ()) - delete f; + delete &f; */ inline all_threads_safe_range diff --git a/gdb/infrun.c b/gdb/infrun.c index b69ab04472d..77859c7b5a2 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -1270,9 +1270,9 @@ follow_exec (ptid_t ptid, const char *exec_file_target) them. Deleting them now rather than at the next user-visible stop provides a nicer sequence of events for user and MI notifications. */ - for (thread_info *th : all_threads_safe ()) - if (th->ptid.pid () == pid && th->ptid != ptid) - delete_thread (th); + for (thread_info &th : all_threads_safe ()) + if (th.ptid.pid () == pid && th.ptid != ptid) + delete_thread (&th); /* We also need to clear any left over stale state for the leader/event thread. E.g., if there was any step-resume @@ -4482,18 +4482,18 @@ clean_up_just_stopped_threads_fsms (struct execution_control_state *ecs) { scoped_restore_current_thread restore_thread; - for (thread_info *thr : all_threads_safe ()) + for (thread_info &thr : all_threads_safe ()) { - if (thr->state == THREAD_EXITED) + if (thr.state == THREAD_EXITED) continue; - if (thr == ecs->event_thread) + if (&thr == ecs->event_thread) continue; - if (thr->thread_fsm () != nullptr) + if (thr.thread_fsm () != nullptr) { - switch_to_thread (thr); - thr->thread_fsm ()->clean_up (thr); + switch_to_thread (&thr); + thr.thread_fsm ()->clean_up (&thr); } /* As we are cancelling the command/FSM of this thread, @@ -4501,10 +4501,10 @@ clean_up_just_stopped_threads_fsms (struct execution_control_state *ecs) exited event to the user, that reason is gone. Delete the thread, so that the user doesn't see it in the thread list, the next proceed doesn't try to resume it, etc. */ - if (thr->has_pending_waitstatus () - && (thr->pending_waitstatus ().kind () + if (thr.has_pending_waitstatus () + && (thr.pending_waitstatus ().kind () == TARGET_WAITKIND_THREAD_EXITED)) - delete_thread (thr); + delete_thread (&thr); } } } @@ -8448,51 +8448,51 @@ restart_stepped_thread (process_stratum_target *resume_target, if (start_step_over ()) return true; - for (thread_info *tp : all_threads_safe ()) + for (thread_info &tp : all_threads_safe ()) { - if (tp->state == THREAD_EXITED) + if (tp.state == THREAD_EXITED) continue; - if (tp->has_pending_waitstatus ()) + if (tp.has_pending_waitstatus ()) continue; /* Ignore threads of processes the caller is not resuming. */ if (!sched_multi - && (tp->inf->process_target () != resume_target - || tp->inf->pid != resume_ptid.pid ())) + && (tp.inf->process_target () != resume_target + || tp.inf->pid != resume_ptid.pid ())) continue; - if (tp->control.trap_expected) + if (tp.control.trap_expected) { infrun_debug_printf ("switching back to stepped thread (step-over)"); - if (keep_going_stepped_thread (tp)) + if (keep_going_stepped_thread (&tp)) return true; } } - for (thread_info *tp : all_threads_safe ()) + for (thread_info &tp : all_threads_safe ()) { - if (tp->state == THREAD_EXITED) + if (tp.state == THREAD_EXITED) continue; - if (tp->has_pending_waitstatus ()) + if (tp.has_pending_waitstatus ()) continue; /* Ignore threads of processes the caller is not resuming. */ if (!sched_multi - && (tp->inf->process_target () != resume_target - || tp->inf->pid != resume_ptid.pid ())) + && (tp.inf->process_target () != resume_target + || tp.inf->pid != resume_ptid.pid ())) continue; /* Did we find the stepping thread? */ - if (tp->control.step_range_end) + if (tp.control.step_range_end) { infrun_debug_printf ("switching back to stepped thread (stepping)"); - if (keep_going_stepped_thread (tp)) + if (keep_going_stepped_thread (&tp)) return true; } } diff --git a/gdb/remote.c b/gdb/remote.c index 774ce625279..2e706e2d45b 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -4484,19 +4484,19 @@ remote_target::update_thread_list () /* CONTEXT now holds the current thread list on the remote target end. Delete GDB-side threads no longer found on the target. */ - for (thread_info *tp : all_threads_safe ()) + for (thread_info &tp : all_threads_safe ()) { - if (tp->inf->process_target () != this) + if (tp.inf->process_target () != this) continue; - if (!context.contains_thread (tp->ptid)) + if (!context.contains_thread (tp.ptid)) { /* Do not remove the thread if it is the last thread in the inferior. This situation happens when we have a pending exit process status to process. Otherwise we may end up with a seemingly live inferior (i.e. pid != 0) that has no threads. */ - if (has_single_non_exited_thread (tp->inf)) + if (has_single_non_exited_thread (tp.inf)) continue; /* Do not remove the thread if we've requested to be @@ -4505,11 +4505,11 @@ remote_target::update_thread_list () exit event, and displaced stepping info is recorded in the thread object. If we deleted the thread now, we'd lose that info. */ - if ((tp->thread_options () & GDB_THREAD_OPTION_EXIT) != 0) + if ((tp.thread_options () & GDB_THREAD_OPTION_EXIT) != 0) continue; /* Not found. */ - delete_thread (tp); + delete_thread (&tp); } } diff --git a/gdb/thread-iter.h b/gdb/thread-iter.h index e661155bcf4..1d4c9b2c7d2 100644 --- a/gdb/thread-iter.h +++ b/gdb/thread-iter.h @@ -35,9 +35,9 @@ class all_threads_iterator { public: typedef all_threads_iterator self_type; - typedef struct thread_info *value_type; - typedef struct thread_info *&reference; - typedef struct thread_info **pointer; + typedef struct thread_info value_type; + typedef struct thread_info &reference; + typedef struct thread_info *pointer; typedef std::forward_iterator_tag iterator_category; typedef int difference_type; @@ -53,7 +53,7 @@ public: : m_thr (nullptr) {} - thread_info *operator* () const { return m_thr; } + reference operator* () const { return *m_thr; } all_threads_iterator &operator++ () { diff --git a/gdb/thread.c b/gdb/thread.c index 11d78310000..1b855b4e0b3 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -603,9 +603,9 @@ find_thread_by_handle (gdb::array_view handle, struct thread_info * iterate_over_threads (gdb::function_view callback) { - for (thread_info *tp : all_threads_safe ()) - if (callback (tp)) - return tp; + for (thread_info &tp : all_threads_safe ()) + if (callback (&tp)) + return &tp; return NULL; } @@ -757,12 +757,12 @@ prune_threads (void) { scoped_restore_current_thread restore_thread; - for (thread_info *tp : all_threads_safe ()) + for (thread_info &tp : all_threads_safe ()) { - switch_to_inferior_no_thread (tp->inf); + switch_to_inferior_no_thread (tp.inf); - if (!thread_alive (tp)) - delete_thread (tp); + if (!thread_alive (&tp)) + delete_thread (&tp); } } @@ -771,9 +771,9 @@ prune_threads (void) void delete_exited_threads (void) { - for (thread_info *tp : all_threads_safe ()) - if (tp->state == THREAD_EXITED) - delete_thread (tp); + for (thread_info &tp : all_threads_safe ()) + if (tp.state == THREAD_EXITED) + delete_thread (&tp); } /* Return true value if stack temporaries are enabled for the thread