From: Simon Marchi Date: Wed, 6 Nov 2024 18:39:48 +0000 (-0500) Subject: gdbserver: remove for_each_thread(pid, func) X-Git-Tag: gdb-16-branchpoint~502 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3470a0e144df6c01f8479fa649f43aa907936e7e;p=thirdparty%2Fbinutils-gdb.git gdbserver: remove for_each_thread(pid, func) 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 --- diff --git a/gdbserver/gdbthread.h b/gdbserver/gdbthread.h index b9783d03947..ab59d660a6c 100644 --- a/gdbserver/gdbthread.h +++ b/gdbserver/gdbthread.h @@ -116,10 +116,6 @@ thread_info *find_thread (ptid_t filter, void for_each_thread (gdb::function_view func); -/* Like the above, but only consider threads with pid PID. */ - -void for_each_thread (int pid, gdb::function_view func); - /* Like the above, but only consider threads matching PTID. */ void for_each_thread diff --git a/gdbserver/inferiors.cc b/gdbserver/inferiors.cc index 07c74c66af4..93555ec64ce 100644 --- a/gdbserver/inferiors.cc +++ b/gdbserver/inferiors.cc @@ -352,25 +352,18 @@ process_info::for_each_thread (gdb::function_view func) /* See gdbthread.h. */ -void -for_each_thread (int pid, gdb::function_view 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 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) { diff --git a/gdbserver/linux-arm-low.cc b/gdbserver/linux-arm-low.cc index af534c7e818..59d639c1eaf 100644 --- a/gdbserver/linux-arm-low.cc +++ b/gdbserver/linux-arm-low.cc @@ -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); }); diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc index 79512c07a22..39a7180e388 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -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 diff --git a/gdbserver/linux-mips-low.cc b/gdbserver/linux-mips-low.cc index 6cf4a6d2d9b..9c03741153e 100644 --- a/gdbserver/linux-mips-low.cc +++ b/gdbserver/linux-mips-low.cc @@ -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; } diff --git a/gdbserver/netbsd-low.cc b/gdbserver/netbsd-low.cc index 4b58826e091..1a3ef16b00a 100644 --- a/gdbserver/netbsd-low.cc +++ b/gdbserver/netbsd-low.cc @@ -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); } diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc index 1bb71d10328..64b6e317618 100644 --- a/gdbserver/regcache.cc +++ b/gdbserver/regcache.cc @@ -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. */ diff --git a/gdbserver/win32-i386-low.cc b/gdbserver/win32-i386-low.cc index 0a761ca58ef..af641200a05 100644 --- a/gdbserver/win32-i386-low.cc +++ b/gdbserver/win32-i386-low.cc @@ -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