* [PATCH 08/11] Remove usage of find_inferior when calling linux_set_resume_request
2017-11-17 18:33 [PATCH 00/11] Remove some usages of find_inferior Simon Marchi
@ 2017-11-17 18:34 ` Simon Marchi
2017-11-17 18:34 ` [PATCH 07/11] Remove usage of find_inferior in linux_stabilize_threads Simon Marchi
` (10 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2017-11-17 18:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Replace it with for_each_thread.
gdb/gdbserver/ChangeLog:
* linux-low.c (struct thread_resume_array): Remove.
(linux_set_resume_request): Return void, take arguments
directly.
(linux_resume): Use for_each_thread.
---
gdb/gdbserver/linux-low.c | 41 +++++++++++++++--------------------------
1 file changed, 15 insertions(+), 26 deletions(-)
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index b4c716c..c1d17f1 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -4569,33 +4569,22 @@ linux_resume_one_lwp (struct lwp_info *lwp,
END_CATCH
}
-struct thread_resume_array
-{
- struct thread_resume *resume;
- size_t n;
-};
-
-/* This function is called once per thread via find_inferior.
- ARG is a pointer to a thread_resume_array struct.
- We look up the thread specified by ENTRY in ARG, and mark the thread
- with a pointer to the appropriate resume request.
+/* This function is called once per thread via for_each_thread.
+ We look up which resume request applies to THREAD and mark it with a
+ pointer to the appropriate resume request.
This algorithm is O(threads * resume elements), but resume elements
is small (and will remain small at least until GDB supports thread
suspension). */
-static int
-linux_set_resume_request (thread_info *thread, void *arg)
+static void
+linux_set_resume_request (thread_info *thread, thread_resume *resume, size_t n)
{
struct lwp_info *lwp = get_thread_lwp (thread);
- int ndx;
- struct thread_resume_array *r;
-
- r = (struct thread_resume_array *) arg;
- for (ndx = 0; ndx < r->n; ndx++)
+ for (int ndx = 0; ndx < n; ndx++)
{
- ptid_t ptid = r->resume[ndx].thread;
+ ptid_t ptid = resume[ndx].thread;
if (ptid_equal (ptid, minus_one_ptid)
|| ptid == thread->id
/* Handle both 'pPID' and 'pPID.-1' as meaning 'all threads
@@ -4604,7 +4593,7 @@ linux_set_resume_request (thread_info *thread, void *arg)
&& (ptid_is_pid (ptid)
|| ptid_get_lwp (ptid) == -1)))
{
- if (r->resume[ndx].kind == resume_stop
+ if (resume[ndx].kind == resume_stop
&& thread->last_resume_kind == resume_stop)
{
if (debug_threads)
@@ -4620,7 +4609,7 @@ linux_set_resume_request (thread_info *thread, void *arg)
/* Ignore (wildcard) resume requests for already-resumed
threads. */
- if (r->resume[ndx].kind != resume_stop
+ if (resume[ndx].kind != resume_stop
&& thread->last_resume_kind != resume_stop)
{
if (debug_threads)
@@ -4662,7 +4651,7 @@ linux_set_resume_request (thread_info *thread, void *arg)
continue;
}
- lwp->resume = &r->resume[ndx];
+ lwp->resume = &resume[ndx];
thread->last_resume_kind = lwp->resume->kind;
lwp->step_range_start = lwp->resume->step_range_start;
@@ -4684,14 +4673,12 @@ linux_set_resume_request (thread_info *thread, void *arg)
lwpid_of (thread));
}
- return 0;
+ return;
}
}
/* No resume action for this thread. */
lwp->resume = NULL;
-
- return 0;
}
/* find_inferior callback for linux_resume.
@@ -5104,7 +5091,6 @@ linux_resume_one_thread (thread_info *thread, void *arg)
static void
linux_resume (struct thread_resume *resume_info, size_t n)
{
- struct thread_resume_array array = { resume_info, n };
struct thread_info *need_step_over = NULL;
int any_pending;
int leave_all_stopped;
@@ -5115,7 +5101,10 @@ linux_resume (struct thread_resume *resume_info, size_t n)
debug_printf ("linux_resume:\n");
}
- find_inferior (&all_threads, linux_set_resume_request, &array);
+ for_each_thread ([&] (thread_info *thread)
+ {
+ linux_set_resume_request (thread, resume_info, n);
+ });
/* If there is a thread which would otherwise be resumed, which has
a pending status, then don't resume any threads - we can just
--
2.7.4
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 07/11] Remove usage of find_inferior in linux_stabilize_threads
2017-11-17 18:33 [PATCH 00/11] Remove some usages of find_inferior Simon Marchi
2017-11-17 18:34 ` [PATCH 08/11] Remove usage of find_inferior when calling linux_set_resume_request Simon Marchi
@ 2017-11-17 18:34 ` Simon Marchi
2017-11-17 18:34 ` [PATCH 06/11] Remove usage of find_inferior in unsuspend_all_lwps Simon Marchi
` (9 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2017-11-17 18:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Simply replace with find_thread.
gdb/gdbserver/ChangeLog:
* linux-low.c (stuck_in_jump_pad_callback): Change prototype,
return bool, remove data argument.
(linux_stabilize_threads): Use find_thread.
---
gdb/gdbserver/linux-low.c | 23 ++++++++---------------
1 file changed, 8 insertions(+), 15 deletions(-)
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index fce3fd0..b4c716c 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -2985,7 +2985,7 @@ unsuspend_all_lwps (struct lwp_info *except)
}
static void move_out_of_jump_pad_callback (thread_info *thread);
-static int stuck_in_jump_pad_callback (thread_info *thread, void *data);
+static bool stuck_in_jump_pad_callback (thread_info *thread);
static int lwp_running (thread_info *thread, void *data);
static ptid_t linux_wait_1 (ptid_t ptid,
struct target_waitstatus *ourstatus,
@@ -3024,13 +3024,8 @@ static ptid_t linux_wait_1 (ptid_t ptid,
static void
linux_stabilize_threads (void)
{
- struct thread_info *saved_thread;
- struct thread_info *thread_stuck;
+ thread_info *thread_stuck = find_thread (stuck_in_jump_pad_callback);
- thread_stuck
- = (struct thread_info *) find_inferior (&all_threads,
- stuck_in_jump_pad_callback,
- NULL);
if (thread_stuck != NULL)
{
if (debug_threads)
@@ -3039,7 +3034,7 @@ linux_stabilize_threads (void)
return;
}
- saved_thread = current_thread;
+ thread_info *saved_thread = current_thread;
stabilizing_threads = 1;
@@ -3082,10 +3077,8 @@ linux_stabilize_threads (void)
if (debug_threads)
{
- thread_stuck
- = (struct thread_info *) find_inferior (&all_threads,
- stuck_in_jump_pad_callback,
- NULL);
+ thread_stuck = find_thread (stuck_in_jump_pad_callback);
+
if (thread_stuck != NULL)
debug_printf ("couldn't stabilize, LWP %ld got stuck in jump pad\n",
lwpid_of (thread_stuck));
@@ -4111,13 +4104,13 @@ wait_for_sigstop (void)
}
}
-/* Returns true if LWP ENTRY is stopped in a jump pad, and we can't
+/* Returns true if THREAD is stopped in a jump pad, and we can't
move it out, because we need to report the stop event to GDB. For
example, if the user puts a breakpoint in the jump pad, it's
because she wants to debug it. */
-static int
-stuck_in_jump_pad_callback (thread_info *thread, void *data)
+static bool
+stuck_in_jump_pad_callback (thread_info *thread)
{
struct lwp_info *lwp = get_thread_lwp (thread);
--
2.7.4
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 06/11] Remove usage of find_inferior in unsuspend_all_lwps
2017-11-17 18:33 [PATCH 00/11] Remove some usages of find_inferior Simon Marchi
2017-11-17 18:34 ` [PATCH 08/11] Remove usage of find_inferior when calling linux_set_resume_request Simon Marchi
2017-11-17 18:34 ` [PATCH 07/11] Remove usage of find_inferior in linux_stabilize_threads Simon Marchi
@ 2017-11-17 18:34 ` Simon Marchi
2017-11-17 18:34 ` [PATCH 04/11] Remove usage of find_inferior in reset_lwp_ptrace_options_callback Simon Marchi
` (8 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2017-11-17 18:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Replace with for_each_thread. I inlined unsuspend_one_lwp in
unsuspend_all_lwps, since it is very simple.
gdb/gdbserver/ChangeLog:
* linux-low.c (unsuspend_one_lwp): Remove.
(unsuspend_all_lwps): Use for_each_thread, inline code from
unsuspend_one_lwp.
---
gdb/gdbserver/linux-low.c | 23 +++++++----------------
1 file changed, 7 insertions(+), 16 deletions(-)
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index fd8e45e..fce3fd0 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -2969,28 +2969,19 @@ select_event_lwp (struct lwp_info **orig_lp)
}
}
-/* Decrement the suspend count of an LWP. */
-
-static int
-unsuspend_one_lwp (thread_info *thread, void *except)
-{
- struct lwp_info *lwp = get_thread_lwp (thread);
-
- /* Ignore EXCEPT. */
- if (lwp == except)
- return 0;
-
- lwp_suspended_decr (lwp);
- return 0;
-}
-
/* Decrement the suspend count of all LWPs, except EXCEPT, if non
NULL. */
static void
unsuspend_all_lwps (struct lwp_info *except)
{
- find_inferior (&all_threads, unsuspend_one_lwp, except);
+ for_each_thread ([&] (thread_info *thread)
+ {
+ lwp_info *lwp = get_thread_lwp (thread);
+
+ if (lwp != except)
+ lwp_suspended_decr (lwp);
+ });
}
static void move_out_of_jump_pad_callback (thread_info *thread);
--
2.7.4
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 04/11] Remove usage of find_inferior in reset_lwp_ptrace_options_callback
2017-11-17 18:33 [PATCH 00/11] Remove some usages of find_inferior Simon Marchi
` (2 preceding siblings ...)
2017-11-17 18:34 ` [PATCH 06/11] Remove usage of find_inferior in unsuspend_all_lwps Simon Marchi
@ 2017-11-17 18:34 ` Simon Marchi
2017-11-17 18:34 ` [PATCH 03/11] Remove usages of find_inferior in linux-arm-low.c Simon Marchi
` (7 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2017-11-17 18:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Replace with for_each_thread, and inline code from
reset_lwp_ptrace_options_callback.
gdb/gdbserver/ChangeLog:
* 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.
---
gdb/gdbserver/linux-low.c | 50 +++++++++++++++++++----------------------------
1 file changed, 20 insertions(+), 30 deletions(-)
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index b267c70..628135a 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -6434,33 +6434,6 @@ linux_supports_exec_events (void)
return linux_supports_traceexec ();
}
-/* Callback for 'find_inferior'. Set the (possibly changed) ptrace
- options for the specified lwp. */
-
-static int
-reset_lwp_ptrace_options_callback (thread_info *thread, void *args)
-{
- struct lwp_info *lwp = get_thread_lwp (thread);
-
- if (!lwp->stopped)
- {
- /* Stop the lwp so we can modify its ptrace options. */
- lwp->must_set_ptrace_flags = 1;
- linux_stop_lwp (lwp);
- }
- else
- {
- /* Already stopped; go ahead and set the ptrace options. */
- struct process_info *proc = find_process_pid (pid_of (thread));
- int options = linux_low_ptrace_options (proc->attached);
-
- linux_enable_event_reporting (lwpid_of (thread), options);
- lwp->must_set_ptrace_flags = 0;
- }
-
- return 0;
-}
-
/* Target hook for 'handle_new_gdb_connection'. Causes a reset of the
ptrace flags for all inferiors. This is in case the new GDB connection
doesn't support the same set of events that the previous one did. */
@@ -6468,10 +6441,27 @@ reset_lwp_ptrace_options_callback (thread_info *thread, void *args)
static void
linux_handle_new_gdb_connection (void)
{
- pid_t pid;
-
/* Request that all the lwps reset their ptrace options. */
- find_inferior (&all_threads, reset_lwp_ptrace_options_callback , &pid);
+ for_each_thread ([] (thread_info *thread)
+ {
+ struct lwp_info *lwp = get_thread_lwp (thread);
+
+ if (!lwp->stopped)
+ {
+ /* Stop the lwp so we can modify its ptrace options. */
+ lwp->must_set_ptrace_flags = 1;
+ linux_stop_lwp (lwp);
+ }
+ else
+ {
+ /* Already stopped; go ahead and set the ptrace options. */
+ struct process_info *proc = find_process_pid (pid_of (thread));
+ int options = linux_low_ptrace_options (proc->attached);
+
+ linux_enable_event_reporting (lwpid_of (thread), options);
+ lwp->must_set_ptrace_flags = 0;
+ }
+ });
}
static int
--
2.7.4
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 03/11] Remove usages of find_inferior in linux-arm-low.c
2017-11-17 18:33 [PATCH 00/11] Remove some usages of find_inferior Simon Marchi
` (3 preceding siblings ...)
2017-11-17 18:34 ` [PATCH 04/11] Remove usage of find_inferior in reset_lwp_ptrace_options_callback Simon Marchi
@ 2017-11-17 18:34 ` Simon Marchi
2017-11-17 18:34 ` [PATCH 02/11] Remove usage of find_inferior in win32-low.c Simon Marchi
` (6 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2017-11-17 18:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Replace two usages with the overload of for_each_thread that filters on
pid. It allows to simplify the callback a little bit.
gdb/gdbserver/ChangeLog:
* linux-arm-low.c (struct update_registers_data): Remove.
(update_registers_callback): Return void, take arguments
directly, don't check thread's pid.
(arm_insert_point, arm_remove_point): Use for_each_thread.
---
gdb/gdbserver/linux-arm-low.c | 55 ++++++++++++++++++++-----------------------
1 file changed, 26 insertions(+), 29 deletions(-)
diff --git a/gdb/gdbserver/linux-arm-low.c b/gdb/gdbserver/linux-arm-low.c
index 3fddec6..f2c030d 100644
--- a/gdb/gdbserver/linux-arm-low.c
+++ b/gdb/gdbserver/linux-arm-low.c
@@ -460,35 +460,22 @@ arm_linux_hw_point_initialize (enum raw_bkpt_type raw_type, CORE_ADDR addr,
/* Callback to mark a watch-/breakpoint to be updated in all threads of
the current process. */
-struct update_registers_data
-{
- int watch;
- int i;
-};
-
-static int
-update_registers_callback (thread_info *thread, void *arg)
+static void
+update_registers_callback (thread_info *thread, int watch, int i)
{
struct lwp_info *lwp = get_thread_lwp (thread);
- struct update_registers_data *data = (struct update_registers_data *) arg;
-
- /* Only update the threads of the current process. */
- if (pid_of (thread) == pid_of (current_thread))
- {
- /* The actual update is done later just before resuming the lwp,
- we just mark that the registers need updating. */
- if (data->watch)
- lwp->arch_private->wpts_changed[data->i] = 1;
- else
- lwp->arch_private->bpts_changed[data->i] = 1;
- /* If the lwp isn't stopped, force it to momentarily pause, so
- we can update its breakpoint registers. */
- if (!lwp->stopped)
- linux_stop_lwp (lwp);
- }
+ /* The actual update is done later just before resuming the lwp,
+ we just mark that the registers need updating. */
+ if (watch)
+ lwp->arch_private->wpts_changed[i] = 1;
+ else
+ lwp->arch_private->bpts_changed[i] = 1;
- return 0;
+ /* If the lwp isn't stopped, force it to momentarily pause, so
+ we can update its breakpoint registers. */
+ if (!lwp->stopped)
+ linux_stop_lwp (lwp);
}
static int
@@ -538,9 +525,14 @@ arm_insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
for (i = 0; i < count; i++)
if (!arm_hwbp_control_is_enabled (pts[i].control))
{
- struct update_registers_data data = { watch, i };
pts[i] = p;
- find_inferior (&all_threads, update_registers_callback, &data);
+
+ /* Only update the threads of the current process. */
+ for_each_thread (current_thread->id.pid (), [&] (thread_info *thread)
+ {
+ update_registers_callback (thread, watch, i);
+ });
+
return 0;
}
@@ -578,9 +570,14 @@ arm_remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
for (i = 0; i < count; i++)
if (arm_linux_hw_breakpoint_equal (&p, pts + i))
{
- struct update_registers_data data = { watch, i };
pts[i].control = arm_hwbp_control_disable (pts[i].control);
- find_inferior (&all_threads, update_registers_callback, &data);
+
+ /* Only update the threads of the current process. */
+ for_each_thread (current_thread->id.pid (), [&] (thread_info *thread)
+ {
+ update_registers_callback (thread, watch, i);
+ });
+
return 0;
}
--
2.7.4
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 02/11] Remove usage of find_inferior in win32-low.c
2017-11-17 18:33 [PATCH 00/11] Remove some usages of find_inferior Simon Marchi
` (4 preceding siblings ...)
2017-11-17 18:34 ` [PATCH 03/11] Remove usages of find_inferior in linux-arm-low.c Simon Marchi
@ 2017-11-17 18:34 ` Simon Marchi
2017-11-17 18:34 ` [PATCH 05/11] Remove usage of find_inferior in iterate_over_lwps Simon Marchi
` (5 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2017-11-17 18:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Replace with for_each_thread.
gdb/gdbserver/ChangeLog:
* win32-low.c (continue_one_thread): Return void, take argument
directly.
(child_continue): Use for_each_thread.
---
gdb/gdbserver/win32-low.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c
index 66fc52c..c7684b7 100644
--- a/gdb/gdbserver/win32-low.c
+++ b/gdb/gdbserver/win32-low.c
@@ -428,10 +428,9 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int attached)
/* Resume all artificially suspended threads if we are continuing
execution. */
-static int
-continue_one_thread (thread_info *thread, void *id_ptr)
+static void
+continue_one_thread (thread_info *thread, int thread_id)
{
- int thread_id = * (int *) id_ptr;
win32_thread_info *th = (win32_thread_info *) thread_target_data (thread);
if (thread_id == -1 || thread_id == th->tid)
@@ -455,8 +454,6 @@ continue_one_thread (thread_info *thread, void *id_ptr)
th->suspended = 0;
}
}
-
- return 0;
}
static BOOL
@@ -464,7 +461,10 @@ child_continue (DWORD continue_status, int thread_id)
{
/* The inferior will only continue after the ContinueDebugEvent
call. */
- find_inferior (&all_threads, continue_one_thread, &thread_id);
+ for_each_thread ([&] (thread_info *thread)
+ {
+ continue_one_thread (thread, thread_id);
+ });
faked_breakpoint = 0;
if (!ContinueDebugEvent (current_event.dwProcessId,
--
2.7.4
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 05/11] Remove usage of find_inferior in iterate_over_lwps
2017-11-17 18:33 [PATCH 00/11] Remove some usages of find_inferior Simon Marchi
` (5 preceding siblings ...)
2017-11-17 18:34 ` [PATCH 02/11] Remove usage of find_inferior in win32-low.c Simon Marchi
@ 2017-11-17 18:34 ` Simon Marchi
2017-11-17 18:34 ` [PATCH 01/11] Remove usage of find_inferior in win32-i386-low.c Simon Marchi
` (4 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2017-11-17 18:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
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.
---
gdb/gdbserver/gdbthread.h | 12 ++++++++++++
gdb/gdbserver/linux-low.c | 45 ++++++---------------------------------------
2 files changed, 18 insertions(+), 39 deletions(-)
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;
--
2.7.4
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 01/11] Remove usage of find_inferior in win32-i386-low.c
2017-11-17 18:33 [PATCH 00/11] Remove some usages of find_inferior Simon Marchi
` (6 preceding siblings ...)
2017-11-17 18:34 ` [PATCH 05/11] Remove usage of find_inferior in iterate_over_lwps Simon Marchi
@ 2017-11-17 18:34 ` Simon Marchi
2017-11-17 18:34 ` [PATCH 11/11] Remove usage of find_inferior when calling kill_one_lwp_callback Simon Marchi
` (3 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2017-11-17 18:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Straightforward replacement of find_inferior with the overload of
for_each_thread that filters on pid. I am able to build-test this
patch, but not run it.
gdb/gdbserver/ChangeLog:
* win32-i386-low.c (update_debug_registers_callback): Rename
to ...
(update_debug_registers): ... this, return void, remove pid_p arg.
(x86_dr_low_set_addr, x86_dr_low_set_control): Use for_each_thread.
---
gdb/gdbserver/win32-i386-low.c | 29 +++++++++--------------------
1 file changed, 9 insertions(+), 20 deletions(-)
diff --git a/gdb/gdbserver/win32-i386-low.c b/gdb/gdbserver/win32-i386-low.c
index fd99ca9..1961a98 100644
--- a/gdb/gdbserver/win32-i386-low.c
+++ b/gdb/gdbserver/win32-i386-low.c
@@ -36,21 +36,14 @@
static struct x86_debug_reg_state debug_reg_state;
-static int
-update_debug_registers_callback (thread_info *thr, void *pid_p)
+static void
+update_debug_registers (thread_info *thread)
{
- win32_thread_info *th = (win32_thread_info *) thread_target_data (thr);
- int pid = *(int *) pid_p;
-
- /* Only update the threads of this process. */
- if (pid_of (thr) == pid)
- {
- /* The actual update is done later just before resuming the lwp,
- we just mark that the registers need updating. */
- th->debug_registers_changed = 1;
- }
+ win32_thread_info *th = (win32_thread_info *) thread_target_data (thread);
- return 0;
+ /* The actual update is done later just before resuming the lwp,
+ we just mark that the registers need updating. */
+ th->debug_registers_changed = 1;
}
/* Update the inferior's debug register REGNUM from STATE. */
@@ -58,12 +51,10 @@ update_debug_registers_callback (thread_info *thr, void *pid_p)
static void
x86_dr_low_set_addr (int regnum, CORE_ADDR addr)
{
- /* Only update the threads of this process. */
- int pid = pid_of (current_thread);
-
gdb_assert (DR_FIRSTADDR <= regnum && regnum <= DR_LASTADDR);
- find_inferior (&all_threads, update_debug_registers_callback, &pid);
+ /* Only update the threads of this process. */
+ for_each_thread (current_thread->id.pid (), update_debug_registers);
}
/* Update the inferior's DR7 debug control register from STATE. */
@@ -72,9 +63,7 @@ static void
x86_dr_low_set_control (unsigned long control)
{
/* Only update the threads of this process. */
- int pid = pid_of (current_thread);
-
- find_inferior (&all_threads, update_debug_registers_callback, &pid);
+ for_each_thread (current_thread->id.pid (), update_debug_registers);
}
/* Return the current value of a DR register of the current thread's
--
2.7.4
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 11/11] Remove usage of find_inferior when calling kill_one_lwp_callback
2017-11-17 18:33 [PATCH 00/11] Remove some usages of find_inferior Simon Marchi
` (7 preceding siblings ...)
2017-11-17 18:34 ` [PATCH 01/11] Remove usage of find_inferior in win32-i386-low.c Simon Marchi
@ 2017-11-17 18:34 ` Simon Marchi
2017-11-17 18:34 ` [PATCH 09/11] Remove usage of find_thread when calling resume_status_pending_p Simon Marchi
` (2 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2017-11-17 18:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Replace with for_each_thread.
gdb/gdbserver/ChangeLog:
* linux-low.c (kill_one_lwp_callback): Return void, take
argument directly, don't filter on pid.
(linux_kill): Use for_each_thread.
---
gdb/gdbserver/linux-low.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 33eb4f8..274263a 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -1356,17 +1356,13 @@ kill_wait_lwp (struct lwp_info *lwp)
perror_with_name ("kill_wait_lwp");
}
-/* Callback for `find_inferior'. Kills an lwp of a given process,
+/* Callback for `for_each_thread'. Kills an lwp of a given process,
except the leader. */
-static int
-kill_one_lwp_callback (thread_info *thread, void *args)
+static void
+kill_one_lwp_callback (thread_info *thread, int pid)
{
struct lwp_info *lwp = get_thread_lwp (thread);
- int pid = * (int *) args;
-
- if (thread->id.pid () != pid)
- return 0;
/* We avoid killing the first thread here, because of a Linux kernel (at
least 2.6.0-test7 through 2.6.8-rc4) bug; if we kill the parent before
@@ -1378,11 +1374,10 @@ kill_one_lwp_callback (thread_info *thread, void *args)
if (debug_threads)
debug_printf ("lkop: is last of process %s\n",
target_pid_to_str (thread->id));
- return 0;
+ return;
}
kill_wait_lwp (lwp);
- return 0;
}
static int
@@ -1399,7 +1394,10 @@ linux_kill (int pid)
first, as PTRACE_KILL will not work otherwise. */
stop_all_lwps (0, NULL);
- find_inferior (&all_threads, kill_one_lwp_callback , &pid);
+ for_each_thread (pid, [&] (thread_info *thread)
+ {
+ kill_one_lwp_callback (thread, pid);
+ });
/* See the comment in linux_kill_one_lwp. We did not kill the first
thread in the list, so do so now. */
--
2.7.4
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 09/11] Remove usage of find_thread when calling resume_status_pending_p
2017-11-17 18:33 [PATCH 00/11] Remove some usages of find_inferior Simon Marchi
` (8 preceding siblings ...)
2017-11-17 18:34 ` [PATCH 11/11] Remove usage of find_inferior when calling kill_one_lwp_callback Simon Marchi
@ 2017-11-17 18:34 ` Simon Marchi
2017-11-17 18:34 ` [PATCH 10/11] Remove usages of find_thread when calling need_step_over_p Simon Marchi
2017-11-19 19:21 ` [PATCH 00/11] Remove some usages of find_inferior Sergio Durigan Junior
11 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2017-11-17 18:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Replace with find_thread. Instead of setting the flag in the callback,
make the callback return true/false, and check the result against NULL
in the caller.
gdb/gdbserver/ChangeLog:
* linux-low.c (resume_status_pending_p): Return bool, remove
flag_p argument.
(linux_resume): Use find_thread.
---
gdb/gdbserver/linux-low.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index c1d17f1..ed897e9 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -4684,20 +4684,17 @@ linux_set_resume_request (thread_info *thread, thread_resume *resume, size_t n)
/* find_inferior callback for linux_resume.
Set *FLAG_P if this lwp has an interesting status pending. */
-static int
-resume_status_pending_p (thread_info *thread, void *flag_p)
+static bool
+resume_status_pending_p (thread_info *thread)
{
struct lwp_info *lwp = get_thread_lwp (thread);
/* LWPs which will not be resumed are not interesting, because
we might not wait for them next time through linux_wait. */
if (lwp->resume == NULL)
- return 0;
+ return false;
- if (thread_still_has_status_pending_p (thread))
- * (int *) flag_p = 1;
-
- return 0;
+ return thread_still_has_status_pending_p (thread);
}
/* Return 1 if this lwp that GDB wants running is stopped at an
@@ -5092,7 +5089,6 @@ static void
linux_resume (struct thread_resume *resume_info, size_t n)
{
struct thread_info *need_step_over = NULL;
- int any_pending;
int leave_all_stopped;
if (debug_threads)
@@ -5112,9 +5108,9 @@ linux_resume (struct thread_resume *resume_info, size_t n)
would otherwise be sent. In non-stop mode, we'll apply this
logic to each thread individually. We consume all pending events
before considering to start a step-over (in all-stop). */
- any_pending = 0;
+ bool any_pending = false;
if (!non_stop)
- find_inferior (&all_threads, resume_status_pending_p, &any_pending);
+ any_pending = find_thread (resume_status_pending_p) != NULL;
/* If there is a thread which would otherwise be resumed, which is
stopped at a breakpoint that needs stepping over, then don't
--
2.7.4
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 10/11] Remove usages of find_thread when calling need_step_over_p
2017-11-17 18:33 [PATCH 00/11] Remove some usages of find_inferior Simon Marchi
` (9 preceding siblings ...)
2017-11-17 18:34 ` [PATCH 09/11] Remove usage of find_thread when calling resume_status_pending_p Simon Marchi
@ 2017-11-17 18:34 ` Simon Marchi
2017-11-19 19:21 ` [PATCH 00/11] Remove some usages of find_inferior Sergio Durigan Junior
11 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2017-11-17 18:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Replace with find_thread.
gdb/gdbserver/ChangeLog:
* linux-low.c (need_step_over_p): Return bool, remove dummy
argument.
(linux_resume, proceed_all_lwps): Use find_thread.
---
gdb/gdbserver/linux-low.c | 32 ++++++++++++++------------------
1 file changed, 14 insertions(+), 18 deletions(-)
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index ed897e9..33eb4f8 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -4702,8 +4702,8 @@ resume_status_pending_p (thread_info *thread)
required STOP_PC adjustment has already been propagated to the
inferior's regcache. */
-static int
-need_step_over_p (thread_info *thread, void *dummy)
+static bool
+need_step_over_p (thread_info *thread)
{
struct lwp_info *lwp = get_thread_lwp (thread);
struct thread_info *saved_thread;
@@ -4713,7 +4713,7 @@ need_step_over_p (thread_info *thread, void *dummy)
/* GDBserver is skipping the extra traps from the wrapper program,
don't have to do step over. */
if (proc->tdesc == NULL)
- return 0;
+ return false;
/* LWPs which will not be resumed are not interesting, because we
might not wait for them next time through linux_wait. */
@@ -4723,7 +4723,7 @@ need_step_over_p (thread_info *thread, void *dummy)
if (debug_threads)
debug_printf ("Need step over [LWP %ld]? Ignoring, not stopped\n",
lwpid_of (thread));
- return 0;
+ return false;
}
if (thread->last_resume_kind == resume_stop)
@@ -4732,7 +4732,7 @@ need_step_over_p (thread_info *thread, void *dummy)
debug_printf ("Need step over [LWP %ld]? Ignoring, should remain"
" stopped\n",
lwpid_of (thread));
- return 0;
+ return false;
}
gdb_assert (lwp->suspended >= 0);
@@ -4742,7 +4742,7 @@ need_step_over_p (thread_info *thread, void *dummy)
if (debug_threads)
debug_printf ("Need step over [LWP %ld]? Ignoring, suspended\n",
lwpid_of (thread));
- return 0;
+ return false;
}
if (lwp->status_pending_p)
@@ -4751,7 +4751,7 @@ need_step_over_p (thread_info *thread, void *dummy)
debug_printf ("Need step over [LWP %ld]? Ignoring, has pending"
" status.\n",
lwpid_of (thread));
- return 0;
+ return false;
}
/* Note: PC, not STOP_PC. Either GDB has adjusted the PC already,
@@ -4770,7 +4770,7 @@ need_step_over_p (thread_info *thread, void *dummy)
"Old stop_pc was 0x%s, PC is now 0x%s\n",
lwpid_of (thread),
paddress (lwp->stop_pc), paddress (pc));
- return 0;
+ return false;
}
/* On software single step target, resume the inferior with signal
@@ -4784,7 +4784,7 @@ need_step_over_p (thread_info *thread, void *dummy)
" signals.\n",
lwpid_of (thread));
- return 0;
+ return false;
}
saved_thread = current_thread;
@@ -4806,7 +4806,7 @@ need_step_over_p (thread_info *thread, void *dummy)
lwpid_of (thread), paddress (pc));
current_thread = saved_thread;
- return 0;
+ return false;
}
else
{
@@ -4819,7 +4819,7 @@ need_step_over_p (thread_info *thread, void *dummy)
that find_inferior stops looking. */
current_thread = saved_thread;
- return 1;
+ return true;
}
}
@@ -4830,7 +4830,7 @@ need_step_over_p (thread_info *thread, void *dummy)
" at 0x%s\n",
lwpid_of (thread), paddress (pc));
- return 0;
+ return false;
}
/* Start a step-over operation on LWP. When LWP stopped at a
@@ -5119,9 +5119,7 @@ linux_resume (struct thread_resume *resume_info, size_t n)
to queue any signals that would otherwise be delivered or
queued. */
if (!any_pending && supports_breakpoints ())
- need_step_over
- = (struct thread_info *) find_inferior (&all_threads,
- need_step_over_p, NULL);
+ need_step_over = find_thread (need_step_over_p);
leave_all_stopped = (need_step_over != NULL || any_pending);
@@ -5291,9 +5289,7 @@ proceed_all_lwps (void)
if (supports_breakpoints ())
{
- need_step_over
- = (struct thread_info *) find_inferior (&all_threads,
- need_step_over_p, NULL);
+ need_step_over = find_thread (need_step_over_p);
if (need_step_over != NULL)
{
--
2.7.4
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 00/11] Remove some usages of find_inferior
2017-11-17 18:33 [PATCH 00/11] Remove some usages of find_inferior Simon Marchi
` (10 preceding siblings ...)
2017-11-17 18:34 ` [PATCH 10/11] Remove usages of find_thread when calling need_step_over_p Simon Marchi
@ 2017-11-19 19:21 ` Sergio Durigan Junior
2017-11-20 3:24 ` Simon Marchi
11 siblings, 1 reply; 14+ messages in thread
From: Sergio Durigan Junior @ 2017-11-19 19:21 UTC (permalink / raw)
To: Simon Marchi; +Cc: gdb-patches
On Friday, November 17 2017, Simon Marchi wrote:
> This is a random sampling of removals of find_inferior, replacing them with the
> new-ish find_thread/for_each_thread.
Thanks for the patch. I looked over it, specifically the Linux-related
bits, and they seem fine. Having hacked this code a bit on gdbserver
some time ago, I for one welcome this change.
> Simon Marchi (11):
> Remove usage of find_inferior in win32-i386-low.c
> Remove usage of find_inferior in win32-low.c
> Remove usages of find_inferior in linux-arm-low.c
> Remove usage of find_inferior in reset_lwp_ptrace_options_callback
> Remove usage of find_inferior in iterate_over_lwps
> Remove usage of find_inferior in unsuspend_all_lwps
> Remove usage of find_inferior in linux_stabilize_threads
> Remove usage of find_inferior when calling linux_set_resume_request
> Remove usage of find_thread when calling resume_status_pending_p
> Remove usages of find_thread when calling need_step_over_p
> Remove usage of find_inferior when calling kill_one_lwp_callback
>
> gdb/gdbserver/gdbthread.h | 12 ++
> gdb/gdbserver/linux-arm-low.c | 55 +++++----
> gdb/gdbserver/linux-low.c | 248 ++++++++++++++---------------------------
> gdb/gdbserver/win32-i386-low.c | 29 ++---
> gdb/gdbserver/win32-low.c | 12 +-
> 5 files changed, 137 insertions(+), 219 deletions(-)
>
> --
> 2.7.4
--
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 00/11] Remove some usages of find_inferior
2017-11-19 19:21 ` [PATCH 00/11] Remove some usages of find_inferior Sergio Durigan Junior
@ 2017-11-20 3:24 ` Simon Marchi
0 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2017-11-20 3:24 UTC (permalink / raw)
To: Sergio Durigan Junior, Simon Marchi; +Cc: gdb-patches
On 2017-11-19 02:21 PM, Sergio Durigan Junior wrote:
> On Friday, November 17 2017, Simon Marchi wrote:
>
>> This is a random sampling of removals of find_inferior, replacing them with the
>> new-ish find_thread/for_each_thread.
>
> Thanks for the patch. I looked over it, specifically the Linux-related
> bits, and they seem fine. Having hacked this code a bit on gdbserver
> some time ago, I for one welcome this change.
Thanks a lot for looking at it! I am pushing the series.
Simon
^ permalink raw reply [flat|nested] 14+ messages in thread