aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2024-11-06 13:39:48 -0500
committerSimon Marchi <simon.marchi@polymtl.ca>2024-11-08 09:16:23 -0500
commit3470a0e144df6c01f8479fa649f43aa907936e7e (patch)
tree2b66e9a0acc8136adfd1d8756e73b9bd33a5f97d
parent6672ccafd90865b9a8916caa3a2f9a0687c301d2 (diff)
downloadgdb-3470a0e144df6c01f8479fa649f43aa907936e7e.zip
gdb-3470a0e144df6c01f8479fa649f43aa907936e7e.tar.gz
gdb-3470a0e144df6c01f8479fa649f43aa907936e7e.tar.bz2
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 <tankut.baris.aktemur@intel.com>
-rw-r--r--gdbserver/gdbthread.h4
-rw-r--r--gdbserver/inferiors.cc19
-rw-r--r--gdbserver/linux-arm-low.cc4
-rw-r--r--gdbserver/linux-low.cc14
-rw-r--r--gdbserver/linux-mips-low.cc4
-rw-r--r--gdbserver/netbsd-low.cc2
-rw-r--r--gdbserver/regcache.cc6
-rw-r--r--gdbserver/win32-i386-low.cc4
8 files changed, 24 insertions, 33 deletions
diff --git a/gdbserver/gdbthread.h b/gdbserver/gdbthread.h
index b9783d0..ab59d66 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<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
diff --git a/gdbserver/inferiors.cc b/gdbserver/inferiors.cc
index 07c74c6..93555ec 100644
--- a/gdbserver/inferiors.cc
+++ b/gdbserver/inferiors.cc
@@ -353,24 +353,17 @@ 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)
{
diff --git a/gdbserver/linux-arm-low.cc b/gdbserver/linux-arm-low.cc
index af534c7..59d639c 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 79512c0..39a7180 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 6cf4a6d..9c03741 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 4b58826..1a3ef16 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 1bb71d1..64b6e31 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 0a761ca..af64120 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