]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: change all_threads_safe to yield references
authorSimon Marchi <simon.marchi@polymtl.ca>
Wed, 3 Sep 2025 14:49:58 +0000 (10:49 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 7 Oct 2025 20:22:15 +0000 (16:22 -0400)
To be consistent with all_threads and the others, following the previous
patch.

Change-Id: I4ee4ff32b005fc5554a9d637725f10fca70cee14
Approved-By: Tom Tromey <tom@tromey.com>
gdb/gdbthread.h
gdb/infrun.c
gdb/remote.c
gdb/thread-iter.h
gdb/thread.c

index b124cee08b5c0f0a8ae44cf1c50d42178d400db5..759034f332eb08ebb852b6ae00ac7a256228e7a9 100644 (file)
@@ -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
index b69ab04472d2687b3410dae11fbbfe487378f971..77859c7b5a29fd53c376f1bcb8fa332cc7c73d16 100644 (file)
@@ -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;
        }
     }
index 774ce6252794aa7978adf3a78110665e393486ab..2e706e2d45b5403dac882238cfd48f93bcd4d13d 100644 (file)
@@ -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);
            }
        }
 
index e661155bcf41399dacac0da02870db8a8a79cf27..1d4c9b2c7d2fae0c323ae528b865c6c8696e579d 100644 (file)
@@ -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++ ()
   {
index 11d78310000fed2f6077eb076f92b6bfdbb9fd2e..1b855b4e0b3b302092092e75c4a1d43f754bc67c 100644 (file)
@@ -603,9 +603,9 @@ find_thread_by_handle (gdb::array_view<const gdb_byte> handle,
 struct thread_info *
 iterate_over_threads (gdb::function_view<bool (struct thread_info *)> 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