aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2017-11-19 22:23:23 -0500
committerSimon Marchi <simon.marchi@polymtl.ca>2017-11-19 22:23:23 -0500
commit6d1e5673fec830f0f1c86632a5d9333e34582bb3 (patch)
tree5b97ec9b3961721e101c4d4aca812c01617054fb /gdb
parentbbf550d50e4c85666877456f014421089503e83b (diff)
downloadgdb-6d1e5673fec830f0f1c86632a5d9333e34582bb3.zip
gdb-6d1e5673fec830f0f1c86632a5d9333e34582bb3.tar.gz
gdb-6d1e5673fec830f0f1c86632a5d9333e34582bb3.tar.bz2
Remove usage of find_inferior in iterate_over_lwps
Replace find_inferior with find_thread. Since it may be useful in the future, I added another overload to find_thread which filters based on a ptid (using ptid_t::matches), so now iterate_over_lwps doesn't have to do the filtering itself. iterate_over_lwps_filter is removed and inlined into iterate_over_lwps. gdb/gdbserver/ChangeLog: * gdbthread.h (find_thread): Add overload with ptid_t filter. * linux-low.c (struct iterate_over_lwps_args): Remove. (iterate_over_lwps_filter): Remove. (iterate_over_lwps): Use find_thread.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/gdbserver/ChangeLog7
-rw-r--r--gdb/gdbserver/gdbthread.h12
-rw-r--r--gdb/gdbserver/linux-low.c45
3 files changed, 25 insertions, 39 deletions
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 3a233bb..5183022 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,5 +1,12 @@
2017-11-19 Simon Marchi <simon.marchi@ericsson.com>
+ * gdbthread.h (find_thread): Add overload with ptid_t filter.
+ * linux-low.c (struct iterate_over_lwps_args): Remove.
+ (iterate_over_lwps_filter): Remove.
+ (iterate_over_lwps): Use find_thread.
+
+2017-11-19 Simon Marchi <simon.marchi@ericsson.com>
+
* linux-low.c (reset_lwp_ptrace_options_callback): Remove.
(linux_handle_new_gdb_connection): Use for_each_thread, inline
code from reset_lwp_ptrace_options_callback.
diff --git a/gdb/gdbserver/gdbthread.h b/gdb/gdbserver/gdbthread.h
index b82d5b0..df1e477 100644
--- a/gdb/gdbserver/gdbthread.h
+++ b/gdb/gdbserver/gdbthread.h
@@ -123,6 +123,18 @@ find_thread (int pid, Func func)
});
}
+/* Find the first thread that matches FILTER for which FUNC returns true.
+ Return NULL if no thread satisfying these conditions is found. */
+
+template <typename Func>
+static thread_info *
+find_thread (ptid_t filter, Func func)
+{
+ return find_thread ([&] (thread_info *thread) {
+ return thread->id.matches (filter) && func (thread);
+ });
+}
+
/* Invoke FUNC for each thread. */
template <typename Func>
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 628135a..fd8e45e 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -1876,42 +1876,6 @@ num_lwps (int pid)
return count;
}
-/* The arguments passed to iterate_over_lwps. */
-
-struct iterate_over_lwps_args
-{
- /* The FILTER argument passed to iterate_over_lwps. */
- ptid_t filter;
-
- /* The CALLBACK argument passed to iterate_over_lwps. */
- iterate_over_lwps_ftype *callback;
-
- /* The DATA argument passed to iterate_over_lwps. */
- void *data;
-};
-
-/* Callback for find_inferior used by iterate_over_lwps to filter
- calls to the callback supplied to that function. Returning a
- nonzero value causes find_inferiors to stop iterating and return
- the current inferior_list_entry. Returning zero indicates that
- find_inferiors should continue iterating. */
-
-static int
-iterate_over_lwps_filter (thread_info *thread, void *args_p)
-{
- struct iterate_over_lwps_args *args
- = (struct iterate_over_lwps_args *) args_p;
-
- if (thread->id.matches (args->filter))
- {
- struct lwp_info *lwp = get_thread_lwp (thread);
-
- return (*args->callback) (lwp, args->data);
- }
-
- return 0;
-}
-
/* See nat/linux-nat.h. */
struct lwp_info *
@@ -1919,10 +1883,13 @@ iterate_over_lwps (ptid_t filter,
iterate_over_lwps_ftype callback,
void *data)
{
- struct iterate_over_lwps_args args = {filter, callback, data};
+ thread_info *thread = find_thread (filter, [&] (thread_info *thread)
+ {
+ lwp_info *lwp = get_thread_lwp (thread);
+
+ return callback (lwp, data);
+ });
- thread_info *thread = find_inferior (&all_threads, iterate_over_lwps_filter,
- &args);
if (thread == NULL)
return NULL;