aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbserver/gdbthread.h
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2017-10-21 12:20:21 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2017-10-21 12:20:21 -0400
commit4d3bb80e5db40cd2308157db3c446f35ae97a915 (patch)
tree886f563e207d3cedc783d48de60126f045dd8c94 /gdb/gdbserver/gdbthread.h
parenta664f67e50eff30198097d51cec0ec4690abb2a1 (diff)
downloadgdb-4d3bb80e5db40cd2308157db3c446f35ae97a915.zip
gdb-4d3bb80e5db40cd2308157db3c446f35ae97a915.tar.gz
gdb-4d3bb80e5db40cd2308157db3c446f35ae97a915.tar.bz2
Add overloads of for_each_thread/find_thread that filter on pid
It happens often that we want to iterate or find threads restricted to a given pid. I think it's worth having an overload to help with this. Right now there is a single user of each of the find_thread and for_each_thread overload, but as we replace the usages of find_inferior with for_each_thread/find_thread, more usages will pop up. gdb/gdbserver/ChangeLog: * gdbthread.h (find_thread, for_each_thread): New functions. * inferiors.c (thread_of_pid): Remove. (find_any_thread_of_pid): Use find_thread. * linux-low.c (num_lwps): Use for_each_thread.
Diffstat (limited to 'gdb/gdbserver/gdbthread.h')
-rw-r--r--gdb/gdbserver/gdbthread.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/gdb/gdbserver/gdbthread.h b/gdb/gdbserver/gdbthread.h
index 8ace051..b82d5b0 100644
--- a/gdb/gdbserver/gdbthread.h
+++ b/gdb/gdbserver/gdbthread.h
@@ -111,6 +111,18 @@ find_thread (Func func)
return NULL;
}
+/* Like the above, but only consider threads with pid PID. */
+
+template <typename Func>
+static thread_info *
+find_thread (int pid, Func func)
+{
+ return find_thread ([&] (thread_info *thread)
+ {
+ return thread->id.pid () == pid && func (thread);
+ });
+}
+
/* Invoke FUNC for each thread. */
template <typename Func>
@@ -128,6 +140,19 @@ for_each_thread (Func func)
}
}
+/* Like the above, but only consider threads with pid PID. */
+
+template <typename Func>
+static void
+for_each_thread (int pid, Func func)
+{
+ for_each_thread ([&] (thread_info *thread)
+ {
+ if (pid == thread->id.pid ())
+ func (thread);
+ });
+}
+
/* Find the a random thread for which FUNC (THREAD) returns true. If
no entry is found then return NULL. */