]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: make lwp_info_iterator yield references
authorSimon Marchi <simon.marchi@polymtl.ca>
Wed, 3 Sep 2025 14:50:00 +0000 (10:50 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 7 Oct 2025 20:22:15 +0000 (16:22 -0400)
Same rational as the previous patches.

Change-Id: I36852ec0c94dc3a87e3af033ca5e55c6b0f708b1
Approved-By: Tom Tromey <tom@tromey.com>
gdb/linux-nat.c
gdb/linux-nat.h
gdb/linux-thread-db.c

index 87fb800e5440a98a259f16f014965159f4153eab..8ca6d78bb7ea4dc3c5f91032a7cae4f692306d02 100644 (file)
@@ -481,8 +481,8 @@ num_lwps (int pid)
 {
   int count = 0;
 
-  for (const lwp_info *lp ATTRIBUTE_UNUSED : all_lwps ())
-    if (lp->ptid.pid () == pid)
+  for (const lwp_info &lp : all_lwps ())
+    if (lp.ptid.pid () == pid)
       count++;
 
   return count;
@@ -930,12 +930,12 @@ struct lwp_info *
 iterate_over_lwps (ptid_t filter,
                   gdb::function_view<iterate_over_lwps_ftype> callback)
 {
-  for (lwp_info *lp : all_lwps_safe ())
+  for (lwp_info &lp : all_lwps_safe ())
     {
-      if (lp->ptid.matches (filter))
+      if (lp.ptid.matches (filter))
        {
-         if (callback (lp) != 0)
-           return lp;
+         if (callback (&lp) != 0)
+           return &lp;
        }
     }
 
@@ -2141,9 +2141,9 @@ linux_handle_extended_wait (struct lwp_info *lp, int status)
         PTRACE_GETEVENTMSG, we'd still need to lookup the
         corresponding LWP object, and it would be an extra ptrace
         syscall, so this way may even be more efficient.  */
-      for (lwp_info *other_lp : all_lwps_safe ())
-       if (other_lp != lp && other_lp->ptid.pid () == lp->ptid.pid ())
-         exit_lwp (other_lp);
+      for (lwp_info &other_lp : all_lwps_safe ())
+       if (&other_lp != lp && other_lp.ptid.pid () == lp->ptid.pid ())
+         exit_lwp (&other_lp);
 
       return 0;
     }
@@ -3856,11 +3856,11 @@ linux_proc_xfer_memory_partial (int pid, gdb_byte *readbuf,
 static lwp_info *
 find_stopped_lwp (int pid)
 {
-  for (lwp_info *lp : all_lwps ())
-    if (lp->ptid.pid () == pid
-       && lp->stopped
-       && !is_lwp_marked_dead (lp))
-      return lp;
+  for (lwp_info &lp : all_lwps ())
+    if (lp.ptid.pid () == pid
+       && lp.stopped
+       && !is_lwp_marked_dead (&lp))
+      return &lp;
   return nullptr;
 }
 
@@ -3962,13 +3962,13 @@ linux_nat_target::update_thread_list ()
 
   /* Update the processor core that each lwp/thread was last seen
      running on.  */
-  for (lwp_info *lwp : all_lwps ())
+  for (lwp_info &lwp : all_lwps ())
     {
       /* Avoid accessing /proc if the thread hasn't run since we last
         time we fetched the thread's core.  Accessing /proc becomes
         noticeably expensive when we have thousands of LWPs.  */
-      if (lwp->core == -1)
-       lwp->core = linux_common_core_of_thread (lwp->ptid);
+      if (lwp.core == -1)
+       lwp.core = linux_common_core_of_thread (lwp.ptid);
     }
 }
 
@@ -4696,8 +4696,8 @@ maintenance_info_lwps (const char *arg, int from_tty)
      figure out the widest ptid string.  We'll use this to build our
      output table below.  */
   size_t ptid_width = 8;
-  for (lwp_info *lp : all_lwps ())
-    ptid_width = std::max (ptid_width, lp->ptid.to_string ().size ());
+  for (lwp_info &lp : all_lwps ())
+    ptid_width = std::max (ptid_width, lp.ptid.to_string ().size ());
 
   /* Setup the table headers.  */
   struct ui_out *uiout = current_uiout;
@@ -4707,13 +4707,13 @@ maintenance_info_lwps (const char *arg, int from_tty)
   uiout->table_body ();
 
   /* Display one table row for each lwp_info.  */
-  for (lwp_info *lp : all_lwps ())
+  for (lwp_info &lp : all_lwps ())
     {
       ui_out_emit_tuple tuple_emitter (uiout, "lwp-entry");
 
-      thread_info *th = linux_target->find_thread (lp->ptid);
+      thread_info *th = linux_target->find_thread (lp.ptid);
 
-      uiout->field_string ("lwp-ptid", lp->ptid.to_string ().c_str ());
+      uiout->field_string ("lwp-ptid", lp.ptid.to_string ().c_str ());
       if (th == nullptr)
        uiout->field_string ("thread-info", "None");
       else
index ed128c0ab7c631084ce0ef7ec34cf595b218b77b..70d1241c54948fbb3b136d498cc25d06e368b7ce 100644 (file)
@@ -299,8 +299,7 @@ struct lwp_info : intrusive_list_node<lwp_info>
 
 /* lwp_info iterator and range types.  */
 
-using lwp_info_iterator
-  = reference_to_pointer_iterator<intrusive_list<lwp_info>::iterator>;
+using lwp_info_iterator = intrusive_list<lwp_info>::iterator;
 using lwp_info_range = iterator_range<lwp_info_iterator>;
 using lwp_info_safe_range = basic_safe_range<lwp_info_range>;
 
index 50df32704e807105a5398e7cf033f4e189705481..d30b25f4d1964b1c08a59bffecc26e126c6f69b1 100644 (file)
@@ -918,9 +918,9 @@ try_thread_db_load_1 (struct thread_db_info *info)
 
       linux_stop_and_wait_all_lwps ();
 
-      for (const lwp_info *lp : all_lwps ())
-       if (lp->ptid.pid () == pid)
-         thread_from_lwp (curr_thread, lp->ptid);
+      for (const lwp_info &lp : all_lwps ())
+       if (lp.ptid.pid () == pid)
+         thread_from_lwp (curr_thread, lp.ptid);
 
       linux_unstop_all_lwps ();
     }