]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdbserver: remove for_each_thread(pid, func)
authorSimon Marchi <simon.marchi@polymtl.ca>
Wed, 6 Nov 2024 18:39:48 +0000 (13:39 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 8 Nov 2024 14:16:23 +0000 (09:16 -0500)
Remove this overload, prefer to use `process_info::for_each_thread`.  In
many instances, the `process_info` is already available, so this saves a
map lookup.  In other instances, add the `process_info` lookup at the
call site.

In `linux-arm-low.cc` and `win32-i386-low.cc`, use `current_process ()`
instead of `current_thread->id.pid ()`.  I presume that if
`current_process ()` and `current_thread` don't match, it's a bug
orthogonal to this change.

Change-Id: I751ed497cb1f313cf937b35125151bee9316fc51
Reviewed-By: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
gdbserver/gdbthread.h
gdbserver/inferiors.cc
gdbserver/linux-arm-low.cc
gdbserver/linux-low.cc
gdbserver/linux-mips-low.cc
gdbserver/netbsd-low.cc
gdbserver/regcache.cc
gdbserver/win32-i386-low.cc

index b9783d0394791a4b69474f7c70d178b8c6997365..ab59d660a6cbeb41e6bd8dfdbd8a2ad854480df6 100644 (file)
@@ -116,10 +116,6 @@ thread_info *find_thread (ptid_t filter,
 
 void for_each_thread (gdb::function_view<void (thread_info *)> func);
 
-/* Like the above, but only consider threads with pid PID.  */
-
-void for_each_thread (int pid, gdb::function_view<void (thread_info *)> func);
-
 /* Like the above, but only consider threads matching PTID.  */
 
 void for_each_thread
index 07c74c66af402acbf1153d445bee9bee88589c96..93555ec64cee4577330cc5c663ab42d02d23414a 100644 (file)
@@ -352,25 +352,18 @@ process_info::for_each_thread (gdb::function_view<void (thread_info *)> func)
 
 /* See gdbthread.h.  */
 
-void
-for_each_thread (int pid, gdb::function_view<void (thread_info *)> func)
-{
-  process_info *process = find_process_pid (pid);
-  if (process == nullptr)
-    return;
-
-  process->for_each_thread (func);
-}
-
-/* See gdbthread.h.  */
-
 void
 for_each_thread (ptid_t ptid, gdb::function_view<void (thread_info *)> func)
 {
   if (ptid == minus_one_ptid)
     for_each_thread (func);
   else if (ptid.is_pid ())
-    for_each_thread (ptid.pid (), func);
+    {
+      process_info *process = find_process_pid (ptid.pid ());
+
+      if (process != nullptr)
+       process->for_each_thread (func);
+    }
   else
     find_thread (ptid, [func] (thread_info *thread)
       {
index af534c7e818696d5a33a48cb4eb1ab04af27ce52..59d639c1eafadb3c2cd72218cd639bded5d39cab 100644 (file)
@@ -636,7 +636,7 @@ arm_target::low_insert_point (raw_bkpt_type type, CORE_ADDR addr,
        pts[i] = p;
 
        /* Only update the threads of the current process.  */
-       for_each_thread (current_thread->id.pid (), [&] (thread_info *thread)
+       current_process ()->for_each_thread ([&] (thread_info *thread)
          {
            update_registers_callback (thread, watch, i);
          });
@@ -681,7 +681,7 @@ arm_target::low_remove_point (raw_bkpt_type type, CORE_ADDR addr,
        pts[i].control = arm_hwbp_control_disable (pts[i].control);
 
        /* Only update the threads of the current process.  */
-       for_each_thread (current_thread->id.pid (), [&] (thread_info *thread)
+       current_process ()->for_each_thread ([&] (thread_info *thread)
          {
            update_registers_callback (thread, watch, i);
          });
index 79512c07a224c66b9e2531d8530b6d0b71176305..39a7180e38849f34b59aa0552d29334255b344ee 100644 (file)
@@ -1385,7 +1385,7 @@ linux_process_target::kill (process_info *process)
      first, as PTRACE_KILL will not work otherwise.  */
   stop_all_lwps (0, NULL);
 
-  for_each_thread (pid, [&] (thread_info *thread)
+  process->for_each_thread ([&] (thread_info *thread)
     {
       kill_one_lwp_callback (thread, pid);
     });
@@ -1588,7 +1588,7 @@ linux_process_target::detach (process_info *process)
   /* Detach from the clone lwps first.  If the thread group exits just
      while we're detaching, we must reap the clone lwps before we're
      able to reap the leader.  */
-  for_each_thread (process->pid, [this] (thread_info *thread)
+  process->for_each_thread ([this] (thread_info *thread)
     {
       /* We don't actually detach from the thread group leader just yet.
         If the thread group exits, we must reap the zombie clone lwps
@@ -1621,7 +1621,7 @@ linux_process_target::mourn (process_info *process)
   thread_db_mourn (process);
 #endif
 
-  for_each_thread (process->pid, [this] (thread_info *thread)
+  process->for_each_thread ([this] (thread_info *thread)
     {
       delete_lwp (get_thread_lwp (thread));
     });
@@ -1756,14 +1756,14 @@ find_lwp_pid (ptid_t ptid)
   return get_thread_lwp (thread);
 }
 
-/* Return the number of known LWPs in the tgid given by PID.  */
+/* Return the number of known LWPs in PROCESS.  */
 
 static int
-num_lwps (int pid)
+num_lwps (process_info *process)
 {
   int count = 0;
 
-  for_each_thread (pid, [&] (thread_info *thread)
+  process->for_each_thread ([&] (thread_info *thread)
     {
       count++;
     });
@@ -1802,7 +1802,7 @@ linux_process_target::check_zombie_leaders ()
 
       threads_debug_printf ("leader_pid=%d, leader_lp!=NULL=%d, "
                            "num_lwps=%d, zombie=%d",
-                           leader_pid, leader_lp!= NULL, num_lwps (leader_pid),
+                           leader_pid, leader_lp!= NULL, num_lwps (proc),
                            linux_proc_pid_is_zombie (leader_pid));
 
       if (leader_lp != NULL && !leader_lp->stopped
index 6cf4a6d2d9b7fdd9c5349fbb9582e0350995e4ea..9c03741153ea07b6e7152632a3bc57cc71eae728 100644 (file)
@@ -575,7 +575,7 @@ mips_target::low_insert_point (raw_bkpt_type type, CORE_ADDR addr,
   priv->watch_mirror = regs;
 
   /* Only update the threads of this process.  */
-  for_each_thread (proc->pid, update_watch_registers_callback);
+  proc->for_each_thread (update_watch_registers_callback);
 
   return 0;
 }
@@ -624,7 +624,7 @@ mips_target::low_remove_point (raw_bkpt_type type, CORE_ADDR addr,
                                  &priv->watch_mirror);
 
   /* Only update the threads of this process.  */
-  for_each_thread (proc->pid, update_watch_registers_callback);
+  proc->for_each_thread (pid, update_watch_registers_callback);
 
   return 0;
 }
index 4b58826e0914f22c7b6883cee1b0cb8a22b0679c..1a3ef16b00a246ce133855809912a48f06e6a715 100644 (file)
@@ -455,7 +455,7 @@ netbsd_process_target::detach (process_info *process)
 void
 netbsd_process_target::mourn (struct process_info *proc)
 {
-  for_each_thread (proc->pid, remove_thread);
+  proc->for_each_thread (remove_thread);
 
   remove_process (proc);
 }
index 1bb71d10328873027e649dc472fbb00a4523978a..64b6e3176188191e0ce22f75194e5f44ed221bf3 100644 (file)
@@ -97,8 +97,10 @@ regcache_invalidate_thread (struct thread_info *thread)
 void
 regcache_invalidate_pid (int pid)
 {
-  /* Only invalidate the regcaches of threads of this process.  */
-  for_each_thread (pid, regcache_invalidate_thread);
+  process_info *process = find_process_pid (pid);
+
+  if (process != nullptr)
+    process->for_each_thread (regcache_invalidate_thread);
 }
 
 /* See regcache.h.  */
index 0a761ca58ef38d89844c931175c0f468e560f2cd..af641200a052d15e36a1c3afc3a8bc1c70176f71 100644 (file)
@@ -65,7 +65,7 @@ x86_dr_low_set_addr (int regnum, CORE_ADDR addr)
   gdb_assert (DR_FIRSTADDR <= regnum && regnum <= DR_LASTADDR);
 
   /* Only update the threads of this process.  */
-  for_each_thread (current_thread->id.pid (), update_debug_registers);
+  current_process ()->for_each_thread (update_debug_registers);
 }
 
 /* Update the inferior's DR7 debug control register from STATE.  */
@@ -74,7 +74,7 @@ static void
 x86_dr_low_set_control (unsigned long control)
 {
   /* Only update the threads of this process.  */
-  for_each_thread (current_thread->id.pid (), update_debug_registers);
+  current_process ()->for_each_thread (update_debug_registers);
 }
 
 /* Return the current value of a DR register of the current thread's