public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 03/19] Remove usages of find_inferior in linux-mips-low.c
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
                   ` (15 preceding siblings ...)
  2017-11-20 16:35 ` [PATCH 08/19] Remove usage of find_inferior in linux_mourn Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-11-20 16:35 ` [PATCH 06/19] Remove usage of find_inferior in last_thread_of_process_p Simon Marchi
                   ` (2 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace with for_each_thread with pid filtering.  This allows
simplifying the callback a little bit.

gdb/gdbserver/ChangeLog:

	* linux-mips-low.c (update_watch_registers_callback): Return
	void, remove pid_p parameter, don't check for pid.
	(mips_insert_point, mips_remove_point): Use for_each_thread.
---
 gdb/gdbserver/linux-mips-low.c | 37 +++++++++++++------------------------
 1 file changed, 13 insertions(+), 24 deletions(-)

diff --git a/gdb/gdbserver/linux-mips-low.c b/gdb/gdbserver/linux-mips-low.c
index 07becd6..7298e16 100644
--- a/gdb/gdbserver/linux-mips-low.c
+++ b/gdb/gdbserver/linux-mips-low.c
@@ -289,29 +289,21 @@ mips_breakpoint_at (CORE_ADDR where)
   return 0;
 }
 
-/* Mark the watch registers of lwp, represented by ENTRY, as changed,
-   if the lwp's process id is *PID_P.  */
+/* Mark the watch registers of lwp, represented by ENTRY, as changed.  */
 
-static int
-update_watch_registers_callback (thread_info *thread, void *pid_p)
+static void
+update_watch_registers_callback (thread_info *thread)
 {
   struct lwp_info *lwp = get_thread_lwp (thread);
-  int pid = *(int *) pid_p;
 
-  /* Only update the threads of this process.  */
-  if (pid_of (thread) == pid)
-    {
-      /* The actual update is done later just before resuming the lwp,
-	 we just mark that the registers need updating.  */
-      lwp->arch_private->watch_registers_changed = 1;
-
-      /* If the lwp isn't stopped, force it to momentarily pause, so
-	 we can update its watch 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.  */
+  lwp->arch_private->watch_registers_changed = 1;
 
-  return 0;
+  /* If the lwp isn't stopped, force it to momentarily pause, so
+     we can update its watch registers.  */
+  if (!lwp->stopped)
+    linux_stop_lwp (lwp);
 }
 
 /* This is the implementation of linux_target_ops method
@@ -471,7 +463,6 @@ mips_insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
   struct process_info *proc = current_process ();
   struct arch_process_info *priv = proc->priv->arch_private;
   struct pt_watch_regs regs;
-  int pid;
   long lwpid;
   enum target_hw_bp_type watch_type;
   uint32_t irw;
@@ -502,8 +493,7 @@ mips_insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
   priv->watch_mirror = regs;
 
   /* Only update the threads of this process.  */
-  pid = pid_of (proc);
-  find_inferior (&all_threads, update_watch_registers_callback, &pid);
+  for_each_thread (proc->pid, update_watch_registers_callback);
 
   return 0;
 }
@@ -519,7 +509,6 @@ mips_remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
   struct arch_process_info *priv = proc->priv->arch_private;
 
   int deleted_one;
-  int pid;
   enum target_hw_bp_type watch_type;
 
   struct mips_watchpoint **pw;
@@ -553,8 +542,8 @@ mips_remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
 				  &priv->watch_mirror);
 
   /* Only update the threads of this process.  */
-  pid = pid_of (proc);
-  find_inferior (&all_threads, update_watch_registers_callback, &pid);
+  for_each_thread (proc->pid, update_watch_registers_callback);
+
   return 0;
 }
 
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 02/19] Remove usage of find_inferior in lynx_mourn
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
                   ` (9 preceding siblings ...)
  2017-11-20 16:35 ` [PATCH 12/19] Remove usage of find_inferior in linux_stabilize_threads Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-11-20 16:35 ` [PATCH 18/19] Remove for_each_inferior Simon Marchi
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace it with for_each_thread with pid filtering.  We can remove
lynx_delete_thread_callback and pass remove_thread directly.

I can't build/test this change, but it should be obvious enough.

gdb/gdbserver/ChangeLog:

	* lynx.low (lynx_delete_thread_callback): Remove.
	(lynx_mourn): Use for_each_thread.
---
 gdb/gdbserver/lynx-low.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/gdb/gdbserver/lynx-low.c b/gdb/gdbserver/lynx-low.c
index ca9adc4..6039364 100644
--- a/gdb/gdbserver/lynx-low.c
+++ b/gdb/gdbserver/lynx-low.c
@@ -555,26 +555,12 @@ lynx_detach (int pid)
   return 0;
 }
 
-/* A callback for find_inferior which removes from the thread list
-   all threads belonging to process PROC.  */
-
-static int
-lynx_delete_thread_callback (thread_info *thread, void *proc)
-{
-  struct process_info *process = (struct process_info *) proc;
-
-  if (thread->id.pid () == pid_of (process))
-    remove_thread (thread);
-
-  return 0;
-}
-
 /* Implement the mourn target_ops method.  */
 
 static void
 lynx_mourn (struct process_info *proc)
 {
-  find_inferior (&all_threads, lynx_delete_thread_callback, proc);
+  for_each_thread (proc->pid, remove_thread);
 
   /* Free our private data.  */
   free (proc->priv);
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 04/19] Remove find_inferior_id
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
                   ` (5 preceding siblings ...)
  2017-11-20 16:35 ` [PATCH 16/19] Update comments Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-11-20 16:35 ` [PATCH 19/19] Remove for_each_inferior_with_data Simon Marchi
                   ` (12 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Remove find_inferior_id, replacing its usages with find_thread_ptid.
find_thread_ptid was implemented using find_inferior_id, so move the
implementation there instead.

gdb/gdbserver/ChangeLog:

	* inferiors.c (find_inferior_id): Remove.
	(find_thread_ptid): Move implemention from find_inferior_id to
	here.
	* inferiors.h (find_inferior_id): Remove.
	* server.c (handle_status): Use find_thread_ptid.
	(process_serial_event): Likewise.
	* thread-db.c (find_one_thread): Likewise.
	(thread_db_thread_handle): Likewise.
	* win32-low.c (thread_rec): Likewise.
	(child_delete_thread): Likewise.
	(win32_thread_alive): Likewise.
	(get_child_debug_event): Likewise.
---
 gdb/gdbserver/inferiors.c | 14 +++-----------
 gdb/gdbserver/inferiors.h |  2 --
 gdb/gdbserver/server.c    |  6 ++----
 gdb/gdbserver/thread-db.c |  8 +++-----
 gdb/gdbserver/win32-low.c | 23 +++++------------------
 5 files changed, 13 insertions(+), 40 deletions(-)

diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c
index f4101c7..be3f3ef 100644
--- a/gdb/gdbserver/inferiors.c
+++ b/gdb/gdbserver/inferiors.c
@@ -43,16 +43,6 @@ find_inferior (std::list<thread_info *> *thread_list,
 }
 
 thread_info *
-find_inferior_id (std::list<thread_info *> *thread_list, ptid_t id)
-{
-  gdb_assert (thread_list == &all_threads);
-
-  return find_thread ([&] (thread_info *thread) {
-    return thread->id == id;
-  });
-}
-
-thread_info *
 find_inferior_in_random (std::list<thread_info *> *thread_list,
 			 int (*func) (thread_info *, void *),
 			 void *arg)
@@ -120,7 +110,9 @@ get_first_thread (void)
 struct thread_info *
 find_thread_ptid (ptid_t ptid)
 {
-  return (struct thread_info *) find_inferior_id (&all_threads, ptid);
+  return find_thread ([&] (thread_info *thread) {
+    return thread->id == ptid;
+  });
 }
 
 /* Find a thread associated with the given PROCESS, or NULL if no
diff --git a/gdb/gdbserver/inferiors.h b/gdb/gdbserver/inferiors.h
index 4c66a74..a8a374e 100644
--- a/gdb/gdbserver/inferiors.h
+++ b/gdb/gdbserver/inferiors.h
@@ -142,8 +142,6 @@ void clear_inferiors (void);
 
 thread_info *find_inferior (std::list<thread_info *> *thread_list,
 			    int (*func) (thread_info *, void *), void *arg);
-thread_info *find_inferior_id (std::list<thread_info *> *thread_list,
-			       ptid_t id);
 thread_info *find_inferior_in_random (std::list<thread_info *> *thread_list,
 				      int (*func) (thread_info *, void *),
 				      void *arg);
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index f0dac95..26c4a01 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -3355,7 +3355,7 @@ handle_status (char *own_buf)
       if (last_status.kind != TARGET_WAITKIND_IGNORE
 	  && last_status.kind != TARGET_WAITKIND_EXITED
 	  && last_status.kind != TARGET_WAITKIND_SIGNALLED)
-	thread = find_inferior_id (&all_threads, last_ptid);
+	thread = find_thread_ptid (last_ptid);
 
       /* If the last event thread is not found for some reason, look
 	 for some other thread that might have an event to report.  */
@@ -4081,9 +4081,7 @@ process_serial_event (void)
 		  /* GDB is telling us to choose any thread.  Check if
 		     the currently selected thread is still valid. If
 		     it is not, select the first available.  */
-		  struct thread_info *thread =
-		    (struct thread_info *) find_inferior_id (&all_threads,
-							     general_thread);
+		  thread_info *thread = find_thread_ptid (general_thread);
 		  if (thread == NULL)
 		    thread = get_first_thread ();
 		  thread_id = thread->id;
diff --git a/gdb/gdbserver/thread-db.c b/gdb/gdbserver/thread-db.c
index 67970f4..537758c 100644
--- a/gdb/gdbserver/thread-db.c
+++ b/gdb/gdbserver/thread-db.c
@@ -165,13 +165,12 @@ find_one_thread (ptid_t ptid)
   td_thrhandle_t th;
   td_thrinfo_t ti;
   td_err_e err;
-  struct thread_info *inferior;
   struct lwp_info *lwp;
   struct thread_db *thread_db = current_process ()->priv->thread_db;
   int lwpid = ptid_get_lwp (ptid);
 
-  inferior = (struct thread_info *) find_inferior_id (&all_threads, ptid);
-  lwp = get_thread_lwp (inferior);
+  thread_info *thread = find_thread_ptid (ptid);
+  lwp = get_thread_lwp (thread);
   if (lwp->thread_known)
     return 1;
 
@@ -452,8 +451,7 @@ thread_db_thread_handle (ptid_t ptid, gdb_byte **handle, int *handle_len)
 {
   struct thread_db *thread_db;
   struct lwp_info *lwp;
-  struct thread_info *thread
-    = (struct thread_info *) find_inferior_id (&all_threads, ptid);
+  thread_info *thread = find_thread_ptid (ptid);
 
   if (thread == NULL)
     return false;
diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c
index c7684b7..fecab84 100644
--- a/gdb/gdbserver/win32-low.c
+++ b/gdb/gdbserver/win32-low.c
@@ -193,14 +193,11 @@ win32_require_context (win32_thread_info *th)
 static win32_thread_info *
 thread_rec (ptid_t ptid, int get_context)
 {
-  struct thread_info *thread;
-  win32_thread_info *th;
-
-  thread = (struct thread_info *) find_inferior_id (&all_threads, ptid);
+  thread_info *thread = find_thread_ptid (ptid);
   if (thread == NULL)
     return NULL;
 
-  th = (win32_thread_info *) thread_target_data (thread);
+  win32_thread_info *th = (win32_thread_info *) thread_target_data (thread);
   if (get_context)
     win32_require_context (th);
   return th;
@@ -244,14 +241,11 @@ delete_thread_info (thread_info *thread)
 static void
 child_delete_thread (DWORD pid, DWORD tid)
 {
-  ptid_t ptid;
-
   /* If the last thread is exiting, just return.  */
   if (all_threads.size () == 1)
     return;
 
-  ptid = ptid_build (pid, tid, 0);
-  thread_info *thread = find_inferior_id (&all_threads, ptid);
+  thread_info *thread = find_thread_ptid (ptid_t (pid, tid));
   if (thread == NULL)
     return;
 
@@ -892,15 +886,9 @@ win32_join (int pid)
 static int
 win32_thread_alive (ptid_t ptid)
 {
-  int res;
-
   /* Our thread list is reliable; don't bother to poll target
      threads.  */
-  if (find_inferior_id (&all_threads, ptid) != NULL)
-    res = 1;
-  else
-    res = 0;
-  return res;
+  return find_thread_ptid (ptid) != NULL;
 }
 
 /* Resume the inferior process.  RESUME_INFO describes how we want
@@ -1582,8 +1570,7 @@ get_child_debug_event (struct target_waitstatus *ourstatus)
     }
 
   ptid = debug_event_ptid (&current_event);
-  current_thread =
-    (struct thread_info *) find_inferior_id (&all_threads, ptid);
+  current_thread = find_thread_ptid (ptid);
   return 1;
 }
 
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 12/19] Remove usage of find_inferior in linux_stabilize_threads
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
                   ` (8 preceding siblings ...)
  2017-11-20 16:35 ` [PATCH 10/19] Remove usages of find_inferior calling not_stopped_callback Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-11-20 16:35 ` [PATCH 02/19] Remove usage of find_inferior in lynx_mourn Simon Marchi
                   ` (9 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace with find_thread.

gdb/gdbserver/ChangeLog:

	* linux-low.c (lwp_running): Return bool, remove unused
	argument.
	(linux_stabilize_threads): Use find_thread.
---
 gdb/gdbserver/linux-low.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index bffbc53..63a187e 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -2918,7 +2918,7 @@ unsuspend_all_lwps (struct lwp_info *except)
 
 static void move_out_of_jump_pad_callback (thread_info *thread);
 static bool stuck_in_jump_pad_callback (thread_info *thread);
-static int lwp_running (thread_info *thread, void *data);
+static bool lwp_running (thread_info *thread);
 static ptid_t linux_wait_1 (ptid_t ptid,
 			    struct target_waitstatus *ourstatus,
 			    int target_options);
@@ -2974,7 +2974,7 @@ linux_stabilize_threads (void)
   for_each_inferior (&all_threads, move_out_of_jump_pad_callback);
 
   /* Loop until all are stopped out of the jump pads.  */
-  while (find_inferior (&all_threads, lwp_running, NULL) != NULL)
+  while (find_thread (lwp_running) != NULL)
     {
       struct target_waitstatus ourstatus;
       struct lwp_info *lwp;
@@ -4120,16 +4120,15 @@ move_out_of_jump_pad_callback (thread_info *thread)
   current_thread = saved_thread;
 }
 
-static int
-lwp_running (thread_info *thread, void *data)
+static bool
+lwp_running (thread_info *thread)
 {
   struct lwp_info *lwp = get_thread_lwp (thread);
 
   if (lwp_is_marked_dead (lwp))
-    return 0;
-  if (lwp->stopped)
-    return 0;
-  return 1;
+    return false;
+
+  return !lwp->stopped;
 }
 
 /* Stop all lwps that aren't stopped yet, except EXCEPT, if not NULL.
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 19/19] Remove for_each_inferior_with_data
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
                   ` (6 preceding siblings ...)
  2017-11-20 16:35 ` [PATCH 04/19] Remove find_inferior_id Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-11-20 16:35 ` [PATCH 10/19] Remove usages of find_inferior calling not_stopped_callback Simon Marchi
                   ` (11 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Remove for_each_inferior_with_data, replacing its sole usage with
for_each_thread.

gdb/gdbserver/ChangeLog:

	* inferiors.c (for_each_inferior_with_data): Remove.
	* inferiors.h (for_each_inferior_with_data): Remove.
	* server.c (handle_qxfer_threads_worker): Change parameter type.
	(handle_qxfer_threads_proper): Use for_each_thread.
---
 gdb/gdbserver/inferiors.c | 12 ------------
 gdb/gdbserver/inferiors.h |  4 ----
 gdb/gdbserver/server.c    |  9 +++++----
 3 files changed, 5 insertions(+), 20 deletions(-)

diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c
index 093080d..6f4427c 100644
--- a/gdb/gdbserver/inferiors.c
+++ b/gdb/gdbserver/inferiors.c
@@ -30,18 +30,6 @@ struct thread_info *current_thread;
 /* The current working directory used to start the inferior.  */
 static const char *current_inferior_cwd = NULL;
 
-void
-for_each_inferior_with_data (std::list<thread_info *> *thread_list,
-			     void (*action) (thread_info *, void *),
-			     void *data)
-{
-  gdb_assert (thread_list == &all_threads);
-
-  for_each_thread ([&] (thread_info *thread) {
-    action (thread, data);
-  });
-}
-
 struct thread_info *
 add_thread (ptid_t thread_id, void *target_data)
 {
diff --git a/gdb/gdbserver/inferiors.h b/gdb/gdbserver/inferiors.h
index 030d9c3..947b56e 100644
--- a/gdb/gdbserver/inferiors.h
+++ b/gdb/gdbserver/inferiors.h
@@ -140,10 +140,6 @@ int have_attached_inferiors_p (void);
 
 void clear_inferiors (void);
 
-void for_each_inferior_with_data (std::list<thread_info *> *thread_list,
-				  void (*action) (thread_info *, void *),
-				  void *data);
-
 void *thread_target_data (struct thread_info *);
 struct regcache *thread_regcache_data (struct thread_info *);
 void set_thread_regcache_data (struct thread_info *, struct regcache *);
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index cfc4a12..e2b7537 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -1650,9 +1650,8 @@ handle_qxfer_statictrace (const char *annex,
    Emit the XML to describe the thread of INF.  */
 
 static void
-handle_qxfer_threads_worker (thread_info *thread, void *arg)
+handle_qxfer_threads_worker (thread_info *thread, struct buffer *buffer)
 {
-  struct buffer *buffer = (struct buffer *) arg;
   ptid_t ptid = ptid_of (thread);
   char ptid_s[100];
   int core = target_core_of_thread (ptid);
@@ -1692,8 +1691,10 @@ handle_qxfer_threads_proper (struct buffer *buffer)
 {
   buffer_grow_str (buffer, "<threads>\n");
 
-  for_each_inferior_with_data (&all_threads, handle_qxfer_threads_worker,
-			       buffer);
+  for_each_thread ([&] (thread_info *thread)
+    {
+      handle_qxfer_threads_worker (thread, buffer);
+    });
 
   buffer_grow_str0 (buffer, "</threads>\n");
 }
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 17/19] Remove find_inferior
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
                   ` (11 preceding siblings ...)
  2017-11-20 16:35 ` [PATCH 18/19] Remove for_each_inferior Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-11-20 16:35 ` [PATCH 11/19] Remove usages of find_inferior in select_event_lwp Simon Marchi
                   ` (6 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

All the usages of find_inferior were removed, so the function itself can
be removed.

gdb/gdbserver/ChangeLog:

	* inferiors.h (find_inferior): Remove.
	* inferiors.c (find_inferior): Remove.
---
 gdb/gdbserver/inferiors.c | 12 ------------
 gdb/gdbserver/inferiors.h |  2 --
 2 files changed, 14 deletions(-)

diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c
index 053f675..47cc13a 100644
--- a/gdb/gdbserver/inferiors.c
+++ b/gdb/gdbserver/inferiors.c
@@ -30,18 +30,6 @@ struct thread_info *current_thread;
 /* The current working directory used to start the inferior.  */
 static const char *current_inferior_cwd = NULL;
 
-thread_info *
-find_inferior (std::list<thread_info *> *thread_list,
-	       int (*func) (thread_info *, void *),
-	       void *arg)
-{
-  gdb_assert (thread_list == &all_threads);
-
-  return find_thread ([&] (thread_info *thread) {
-    return func (thread, arg);
-  });
-}
-
 void
 for_each_inferior (std::list<thread_info *> *thread_list,
 		   void (*action) (thread_info *))
diff --git a/gdb/gdbserver/inferiors.h b/gdb/gdbserver/inferiors.h
index 44644c2..2aab846 100644
--- a/gdb/gdbserver/inferiors.h
+++ b/gdb/gdbserver/inferiors.h
@@ -140,8 +140,6 @@ int have_attached_inferiors_p (void);
 
 void clear_inferiors (void);
 
-thread_info *find_inferior (std::list<thread_info *> *thread_list,
-			    int (*func) (thread_info *, void *), void *arg);
 void for_each_inferior (std::list<thread_info *> *thread_list,
 			void (*action) (thread_info *));
 void for_each_inferior_with_data (std::list<thread_info *> *thread_list,
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 09/19] Remove usage of find_inferior in find_lwp_pid
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-11-20 16:35 ` [PATCH 14/19] Remove usage of find_inferior in linux_resume Simon Marchi
                   ` (18 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace with find_thread.  We could almost use find_thread_ptid, except
that find_lwp_pid uses the pid of the input ptid of the lwp is 0, so the
behavior is not quite the same.

gdb/gdbserver/ChangeLog:

	* linux-low.c (same_lwp): Remove.
	(find_lwp_pid): Use find_thread.
---
 gdb/gdbserver/linux-low.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 6ec9a16..08f7f90 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -1807,27 +1807,14 @@ status_pending_p_callback (thread_info *thread, ptid_t ptid)
   return lp->status_pending_p;
 }
 
-static int
-same_lwp (thread_info *thread, void *data)
-{
-  ptid_t ptid = *(ptid_t *) data;
-  int lwp;
-
-  if (ptid_get_lwp (ptid) != 0)
-    lwp = ptid_get_lwp (ptid);
-  else
-    lwp = ptid_get_pid (ptid);
-
-  if (thread->id.lwp () == lwp)
-    return 1;
-
-  return 0;
-}
-
 struct lwp_info *
 find_lwp_pid (ptid_t ptid)
 {
-  thread_info *thread = find_inferior (&all_threads, same_lwp, &ptid);
+  thread_info *thread = find_thread ([&] (thread_info *thread)
+    {
+      int lwp = ptid.lwp () != 0 ? ptid.lwp () : ptid.pid ();
+      return thread->id.lwp () == lwp;
+    });
 
   if (thread == NULL)
     return NULL;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 05/19] Remove find_inferior_in_random
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
  2017-11-20 16:35 ` [PATCH 09/19] Remove usage of find_inferior in find_lwp_pid Simon Marchi
  2017-11-20 16:35 ` [PATCH 14/19] Remove usage of find_inferior in linux_resume Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-11-20 16:35 ` [PATCH 13/19] Remove usages of find_inferior in stop_all_lwps Simon Marchi
                   ` (16 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace with find_thread_in_random.

gdb/gdbserver/ChangeLog:

	* inferiors.c (find_inferior_in_random): Remove.
	* inferiors.h (find_inferior_in_random): Remove.
	* linux-low.c (status_pending_p_callback): Return bool, accept
	parameter ptid directly.
	(linux_wait_for_event_filtered): Use find_thread_in_random.
	(linux_wait_1): Likewise.
---
 gdb/gdbserver/inferiors.c | 12 ------------
 gdb/gdbserver/inferiors.h |  3 ---
 gdb/gdbserver/linux-low.c | 34 ++++++++++++++++++++--------------
 3 files changed, 20 insertions(+), 29 deletions(-)

diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c
index be3f3ef..053f675 100644
--- a/gdb/gdbserver/inferiors.c
+++ b/gdb/gdbserver/inferiors.c
@@ -42,18 +42,6 @@ find_inferior (std::list<thread_info *> *thread_list,
   });
 }
 
-thread_info *
-find_inferior_in_random (std::list<thread_info *> *thread_list,
-			 int (*func) (thread_info *, void *),
-			 void *arg)
-{
-  gdb_assert (thread_list == &all_threads);
-
-  return find_thread_in_random ([&] (thread_info *thread) {
-    return func (thread, arg);
-  });
-}
-
 void
 for_each_inferior (std::list<thread_info *> *thread_list,
 		   void (*action) (thread_info *))
diff --git a/gdb/gdbserver/inferiors.h b/gdb/gdbserver/inferiors.h
index a8a374e..44644c2 100644
--- a/gdb/gdbserver/inferiors.h
+++ b/gdb/gdbserver/inferiors.h
@@ -142,9 +142,6 @@ void clear_inferiors (void);
 
 thread_info *find_inferior (std::list<thread_info *> *thread_list,
 			    int (*func) (thread_info *, void *), void *arg);
-thread_info *find_inferior_in_random (std::list<thread_info *> *thread_list,
-				      int (*func) (thread_info *, void *),
-				      void *arg);
 void for_each_inferior (std::list<thread_info *> *thread_list,
 			void (*action) (thread_info *));
 void for_each_inferior_with_data (std::list<thread_info *> *thread_list,
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 274263a..60f049d 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -1806,16 +1806,15 @@ lwp_resumed (struct lwp_info *lwp)
   return 0;
 }
 
-/* Return 1 if this lwp has an interesting status pending.  */
-static int
-status_pending_p_callback (thread_info *thread, void *arg)
+/* Return true if this lwp has an interesting status pending.  */
+static bool
+status_pending_p_callback (thread_info *thread, ptid_t ptid)
 {
   struct lwp_info *lp = get_thread_lwp (thread);
-  ptid_t ptid = * (ptid_t *) arg;
 
   /* Check if we're only interested in events from a specific process
      or a specific LWP.  */
-  if (!ptid_match (ptid_of (thread), ptid))
+  if (!thread->id.matches (ptid))
     return 0;
 
   if (!lwp_resumed (lp))
@@ -2666,9 +2665,11 @@ linux_wait_for_event_filtered (ptid_t wait_ptid, ptid_t filter_ptid,
 
   if (ptid_equal (filter_ptid, minus_one_ptid) || ptid_is_pid (filter_ptid))
     {
-      event_thread = (struct thread_info *)
-	find_inferior_in_random (&all_threads, status_pending_p_callback,
-				 &filter_ptid);
+      event_thread = find_thread_in_random ([&] (thread_info *thread)
+	{
+	  return status_pending_p_callback (thread, filter_ptid);
+	});
+
       if (event_thread != NULL)
 	event_child = get_thread_lwp (event_thread);
       if (debug_threads && event_thread)
@@ -2779,9 +2780,11 @@ linux_wait_for_event_filtered (ptid_t wait_ptid, ptid_t filter_ptid,
 
       /* ... and find an LWP with a status to report to the core, if
 	 any.  */
-      event_thread = (struct thread_info *)
-	find_inferior_in_random (&all_threads, status_pending_p_callback,
-				 &filter_ptid);
+      event_thread = find_thread_in_random ([&] (thread_info *thread)
+	{
+	  return status_pending_p_callback (thread, filter_ptid);
+	});
+
       if (event_thread != NULL)
 	{
 	  event_child = get_thread_lwp (event_thread);
@@ -3192,10 +3195,13 @@ linux_wait_1 (ptid_t ptid,
   in_step_range = 0;
   ourstatus->kind = TARGET_WAITKIND_IGNORE;
 
+  auto status_pending_p_any = [&] (thread_info *thread)
+    {
+      return status_pending_p_callback (thread, minus_one_ptid);
+    };
+
   /* Find a resumed LWP, if any.  */
-  if (find_inferior (&all_threads,
-		     status_pending_p_callback,
-		     &minus_one_ptid) != NULL)
+  if (find_thread (status_pending_p_any) != NULL)
     any_resumed = 1;
   else if ((find_inferior (&all_threads,
 			   not_stopped_callback,
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 16/19] Update comments
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
                   ` (4 preceding siblings ...)
  2017-11-20 16:35 ` [PATCH 01/19] Remove usage of find_inferior in regcache_invalidate_pid Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-11-20 16:35 ` [PATCH 04/19] Remove find_inferior_id Simon Marchi
                   ` (13 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

These functions were modified in the previous patch series, but I forgot
to update some comments.

gdb/gdbserver/ChangeLog:

	* linux-low.c (resume_status_pending_p): Update comment.
	(need_step_over_p): Update comment.
---
 gdb/gdbserver/linux-low.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 58145a5..630340f 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -4624,8 +4624,8 @@ linux_set_resume_request (thread_info *thread, thread_resume *resume, size_t n)
   lwp->resume = NULL;
 }
 
-/* find_inferior callback for linux_resume.
-   Set *FLAG_P if this lwp has an interesting status pending.  */
+/* find_thread callback for linux_resume.  Return true if this lwp has an
+   interesting status pending.  */
 
 static bool
 resume_status_pending_p (thread_info *thread)
@@ -4759,7 +4759,7 @@ need_step_over_p (thread_info *thread)
 			  lwpid_of (thread), paddress (pc));
 
 	  /* We've found an lwp that needs stepping over --- return 1 so
-	     that find_inferior stops looking.  */
+	     that find_thread stops looking.  */
 	  current_thread = saved_thread;
 
 	  return true;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 07/19] Remove usage of find_inferior in linux_detach
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
                   ` (13 preceding siblings ...)
  2017-11-20 16:35 ` [PATCH 11/19] Remove usages of find_inferior in select_event_lwp Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-11-20 16:35 ` [PATCH 08/19] Remove usage of find_inferior in linux_mourn Simon Marchi
                   ` (4 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace with for_each_thread with pid filtering.

gdb/gdbserver/ChangeLog:

	* linux-low.c (linux_detach_lwp_callback): Return void, remove
	args parameter, don't check for pid.
	(linux_detach): Use for_each_thread.
---
 gdb/gdbserver/linux-low.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 333d87d..a4e19ba 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -1580,28 +1580,20 @@ linux_detach_one_lwp (struct lwp_info *lwp)
   delete_lwp (lwp);
 }
 
-/* Callback for find_inferior.  Detaches from non-leader threads of a
+/* Callback for for_each_thread.  Detaches from non-leader threads of a
    given process.  */
 
-static int
-linux_detach_lwp_callback (thread_info *thread, void *args)
+static void
+linux_detach_lwp_callback (thread_info *thread)
 {
-  struct lwp_info *lwp = get_thread_lwp (thread);
-  int pid = *(int *) args;
-  int lwpid = lwpid_of (thread);
-
-  /* Skip other processes.  */
-  if (thread->id.pid () != pid)
-    return 0;
-
   /* We don't actually detach from the thread group leader just yet.
      If the thread group exits, we must reap the zombie clone lwps
      before we're able to reap the leader.  */
-  if (thread->id.pid () == lwpid)
-    return 0;
+  if (thread->id.pid () == thread->id.lwp ())
+    return;
 
+  lwp_info *lwp = get_thread_lwp (thread);
   linux_detach_one_lwp (lwp);
-  return 0;
 }
 
 static int
@@ -1635,7 +1627,7 @@ linux_detach (int pid)
   /* 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.  */
-  find_inferior (&all_threads, linux_detach_lwp_callback, &pid);
+  for_each_thread (pid, linux_detach_lwp_callback);
 
   main_lwp = find_lwp_pid (pid_to_ptid (pid));
   linux_detach_one_lwp (main_lwp);
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 01/19] Remove usage of find_inferior in regcache_invalidate_pid
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
                   ` (3 preceding siblings ...)
  2017-11-20 16:35 ` [PATCH 13/19] Remove usages of find_inferior in stop_all_lwps Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-11-20 16:35 ` [PATCH 16/19] Update comments Simon Marchi
                   ` (14 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace with for_each_thread with pid filtering.
regcache_invalidate_one is not longer needed, as it was only used to
filter the pid.  We can call regcache_invalidate_thread directly.

gdb/gdbserver/ChangeLog:

	* regcache.c (regcache_invalidate_one): Remove.
	(regcache_invalidate_pid): use for_each_thread.
---
 gdb/gdbserver/regcache.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/gdb/gdbserver/regcache.c b/gdb/gdbserver/regcache.c
index e45e60e..5f71523 100644
--- a/gdb/gdbserver/regcache.c
+++ b/gdb/gdbserver/regcache.c
@@ -93,24 +93,13 @@ regcache_invalidate_thread (struct thread_info *thread)
   regcache->registers_valid = 0;
 }
 
-static int
-regcache_invalidate_one (thread_info *thread, void *pid_p)
-{
-  int pid = *(int *) pid_p;
-
-  /* Only invalidate the regcaches of threads of this process.  */
-  if (thread->id.pid () == pid)
-    regcache_invalidate_thread (thread);
-
-  return 0;
-}
-
 /* See regcache.h.  */
 
 void
 regcache_invalidate_pid (int pid)
 {
-  find_inferior (&all_threads, regcache_invalidate_one, &pid);
+  /* Only invalidate the regcaches of threads of this process.  */
+  for_each_thread (pid, regcache_invalidate_thread);
 }
 
 /* See regcache.h.  */
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 10/19] Remove usages of find_inferior calling not_stopped_callback
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
                   ` (7 preceding siblings ...)
  2017-11-20 16:35 ` [PATCH 19/19] Remove for_each_inferior_with_data Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-11-20 16:35 ` [PATCH 12/19] Remove usage of find_inferior in linux_stabilize_threads Simon Marchi
                   ` (10 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace with find_thread.  Writing a lambda inline in directly in the if
conditions would be a bit messy, so I chose to assign them to variables
instead.

gdb/gdbserver/ChangeLog:

	* linux-low.c (not_stopped_callback): Return bool, take filter
	argument directly.
	(linux_wait_for_event_filtered): Use find_thread.
	(linux_wait_1): Likewise.
---
 gdb/gdbserver/linux-low.c | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 08f7f90..85d5572 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -1919,23 +1919,18 @@ check_zombie_leaders (void)
     });
 }
 
-/* Callback for `find_inferior'.  Returns the first LWP that is not
-   stopped.  ARG is a PTID filter.  */
+/* Callback for `find_thread'.  Returns the first LWP that is not
+   stopped.  */
 
-static int
-not_stopped_callback (thread_info *thread, void *arg)
+static bool
+not_stopped_callback (thread_info *thread, ptid_t filter)
 {
-  struct lwp_info *lwp;
-  ptid_t filter = *(ptid_t *) arg;
-
-  if (!ptid_match (ptid_of (thread), filter))
-    return 0;
+  if (!thread->id.matches (filter))
+    return false;
 
-  lwp = get_thread_lwp (thread);
-  if (!lwp->stopped)
-    return 1;
+  lwp_info *lwp = get_thread_lwp (thread);
 
-  return 0;
+  return !lwp->stopped;
 }
 
 /* Increment LWP's suspend count.  */
@@ -2762,6 +2757,11 @@ linux_wait_for_event_filtered (ptid_t wait_ptid, ptid_t filter_ptid,
 	 until all other threads in the thread group are.  */
       check_zombie_leaders ();
 
+      auto not_stopped = [&] (thread_info *thread)
+	{
+	  return not_stopped_callback (thread, wait_ptid);
+	};
+
       /* If there are no resumed children left in the set of LWPs we
 	 want to wait for, bail.  We can't just block in
 	 waitpid/sigsuspend, because lwps might have been left stopped
@@ -2769,9 +2769,7 @@ linux_wait_for_event_filtered (ptid_t wait_ptid, ptid_t filter_ptid,
 	 their status to change (which would only happen if we resumed
 	 them).  Even if WNOHANG is set, this return code is preferred
 	 over 0 (below), as it is more detailed.  */
-      if ((find_inferior (&all_threads,
-			  not_stopped_callback,
-			  &wait_ptid) == NULL))
+      if (find_thread (not_stopped) == NULL)
 	{
 	  if (debug_threads)
 	    debug_printf ("LLW: exit (no unwaited-for LWP)\n");
@@ -3164,12 +3162,15 @@ linux_wait_1 (ptid_t ptid,
       return status_pending_p_callback (thread, minus_one_ptid);
     };
 
+  auto not_stopped = [&] (thread_info *thread)
+    {
+      return not_stopped_callback (thread, minus_one_ptid);
+    };
+
   /* Find a resumed LWP, if any.  */
   if (find_thread (status_pending_p_any) != NULL)
     any_resumed = 1;
-  else if ((find_inferior (&all_threads,
-			   not_stopped_callback,
-			   &minus_one_ptid) != NULL))
+  else if (find_thread (not_stopped) != NULL)
     any_resumed = 1;
   else
     any_resumed = 0;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 14/19] Remove usage of find_inferior in linux_resume
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
  2017-11-20 16:35 ` [PATCH 09/19] Remove usage of find_inferior in find_lwp_pid Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-11-20 16:35 ` [PATCH 05/19] Remove find_inferior_in_random Simon Marchi
                   ` (17 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace with for_each_thread.

gdb/gdbserver/ChangeLog:

	* linux-low.c (linux_resume_one_thread): Return void, take
	parameter directly.
	(linux_resume): Use for_each_thread.
---
 gdb/gdbserver/linux-low.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 76a88c1..740a98b 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -4922,15 +4922,14 @@ complete_ongoing_step_over (void)
    event to report, so we don't need to preserve any step requests;
    they should be re-issued if necessary.  */
 
-static int
-linux_resume_one_thread (thread_info *thread, void *arg)
+static void
+linux_resume_one_thread (thread_info *thread, bool leave_all_stopped)
 {
   struct lwp_info *lwp = get_thread_lwp (thread);
-  int leave_all_stopped = * (int *) arg;
   int leave_pending;
 
   if (lwp->resume == NULL)
-    return 0;
+    return;
 
   if (lwp->resume->kind == resume_stop)
     {
@@ -4977,7 +4976,7 @@ linux_resume_one_thread (thread_info *thread, void *arg)
       /* For stop requests, we're done.  */
       lwp->resume = NULL;
       thread->last_status.kind = TARGET_WAITKIND_IGNORE;
-      return 0;
+      return;
     }
 
   /* If this thread which is about to be resumed has a pending status,
@@ -5025,14 +5024,12 @@ linux_resume_one_thread (thread_info *thread, void *arg)
 
   thread->last_status.kind = TARGET_WAITKIND_IGNORE;
   lwp->resume = NULL;
-  return 0;
 }
 
 static void
 linux_resume (struct thread_resume *resume_info, size_t n)
 {
   struct thread_info *need_step_over = NULL;
-  int leave_all_stopped;
 
   if (debug_threads)
     {
@@ -5064,7 +5061,7 @@ linux_resume (struct thread_resume *resume_info, size_t n)
   if (!any_pending && supports_breakpoints ())
     need_step_over = find_thread (need_step_over_p);
 
-  leave_all_stopped = (need_step_over != NULL || any_pending);
+  bool leave_all_stopped = (need_step_over != NULL || any_pending);
 
   if (debug_threads)
     {
@@ -5079,7 +5076,10 @@ linux_resume (struct thread_resume *resume_info, size_t n)
 
   /* Even if we're leaving threads stopped, queue all signals we'd
      otherwise deliver.  */
-  find_inferior (&all_threads, linux_resume_one_thread, &leave_all_stopped);
+  for_each_thread ([&] (thread_info *thread)
+    {
+      linux_resume_one_thread (thread, leave_all_stopped);
+    });
 
   if (need_step_over)
     start_step_over (get_thread_lwp (need_step_over));
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 06/19] Remove usage of find_inferior in last_thread_of_process_p
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
                   ` (16 preceding siblings ...)
  2017-11-20 16:35 ` [PATCH 03/19] Remove usages of find_inferior in linux-mips-low.c Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-11-20 16:35 ` [PATCH 15/19] Remove usages of find_inferior that call proceed_one_lwp Simon Marchi
  2017-12-03  1:48 ` [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace it with find_thread.  I also modified the code a bit to use a
lambda and a boolean.

gdb/gdbserver/ChangeLog:

	* linux-low.c (struct counter): Remove.
	(second_thread_of_pid_p): Remove.
	(last_thread_of_process_p): Use find_thread.
---
 gdb/gdbserver/linux-low.c | 38 ++++++++++++++++----------------------
 1 file changed, 16 insertions(+), 22 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 60f049d..333d87d 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -1240,33 +1240,27 @@ linux_attach (unsigned long pid)
   return 0;
 }
 
-struct counter
-{
-  int pid;
-  int count;
-};
-
 static int
-second_thread_of_pid_p (thread_info *thread, void *args)
+last_thread_of_process_p (int pid)
 {
-  struct counter *counter = (struct counter *) args;
+  bool seen_one = false;
 
-  if (thread->id.pid () == counter->pid)
+  thread_info *thread = find_thread (pid, [&] (thread_info *thread)
     {
-      if (++counter->count > 1)
-	return 1;
-    }
-
-  return 0;
-}
-
-static int
-last_thread_of_process_p (int pid)
-{
-  struct counter counter = { pid , 0 };
+      if (!seen_one)
+	{
+	  /* This is the first thread of this process we see.  */
+	  seen_one = true;
+	  return false;
+	}
+      else
+	{
+	  /* This is the second thread of this process we see.  */
+	  return true;
+	}
+    });
 
-  return (find_inferior (&all_threads,
-			 second_thread_of_pid_p, &counter) == NULL);
+  return thread == NULL;
 }
 
 /* Kill LWP.  */
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 08/19] Remove usage of find_inferior in linux_mourn
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
                   ` (14 preceding siblings ...)
  2017-11-20 16:35 ` [PATCH 07/19] Remove usage of find_inferior in linux_detach Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-11-20 16:35 ` [PATCH 03/19] Remove usages of find_inferior in linux-mips-low.c Simon Marchi
                   ` (3 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace with for_each_thread with pid filtering.  The callback becomes
trivial enough that it's better to inline it.

gdb/gdbserver/ChangeLog:

	* linux-low.c (delete_lwp_callback): Remove.
	(linux_mourn): Use for_each_thread.
---
 gdb/gdbserver/linux-low.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index a4e19ba..6ec9a16 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -1642,18 +1642,6 @@ linux_detach (int pid)
 
 /* Remove all LWPs that belong to process PROC from the lwp list.  */
 
-static int
-delete_lwp_callback (thread_info *thread, void *proc)
-{
-  struct lwp_info *lwp = get_thread_lwp (thread);
-  struct process_info *process = (struct process_info *) proc;
-
-  if (pid_of (thread) == pid_of (process))
-    delete_lwp (lwp);
-
-  return 0;
-}
-
 static void
 linux_mourn (struct process_info *process)
 {
@@ -1663,7 +1651,10 @@ linux_mourn (struct process_info *process)
   thread_db_mourn (process);
 #endif
 
-  find_inferior (&all_threads, delete_lwp_callback, process);
+  for_each_thread (process->pid, [] (thread_info *thread)
+    {
+      delete_lwp (get_thread_lwp (thread));
+    });
 
   /* Freeing all private data.  */
   priv = process->priv;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 13/19] Remove usages of find_inferior in stop_all_lwps
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
                   ` (2 preceding siblings ...)
  2017-11-20 16:35 ` [PATCH 05/19] Remove find_inferior_in_random Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-11-20 16:35 ` [PATCH 01/19] Remove usage of find_inferior in regcache_invalidate_pid Simon Marchi
                   ` (15 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace with for_each_thread.

gdb/gdbserver/ChangeLog:

	* linux-low.c (send_sigstop_callback): Return void, change
	parameter type.  Rename to...
	(send_sigstop): ... this.
	(suspend_and_send_sigstop_callback): Return void, change parameter
	type.  Rename to...
	(suspend_and_send_sigstop): ... this.
	(stop_all_lwps): Use for_each_thread.
---
 gdb/gdbserver/linux-low.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 63a187e..76a88c1 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -3932,36 +3932,35 @@ send_sigstop (struct lwp_info *lwp)
   kill_lwp (pid, SIGSTOP);
 }
 
-static int
-send_sigstop_callback (thread_info *thread, void *except)
+static void
+send_sigstop (thread_info *thread, lwp_info *except)
 {
   struct lwp_info *lwp = get_thread_lwp (thread);
 
   /* Ignore EXCEPT.  */
   if (lwp == except)
-    return 0;
+    return;
 
   if (lwp->stopped)
-    return 0;
+    return;
 
   send_sigstop (lwp);
-  return 0;
 }
 
 /* Increment the suspend count of an LWP, and stop it, if not stopped
    yet.  */
-static int
-suspend_and_send_sigstop_callback (thread_info *thread, void *except)
+static void
+suspend_and_send_sigstop (thread_info *thread, lwp_info *except)
 {
   struct lwp_info *lwp = get_thread_lwp (thread);
 
   /* Ignore EXCEPT.  */
   if (lwp == except)
-    return 0;
+    return;
 
   lwp_suspended_inc (lwp);
 
-  return send_sigstop_callback (thread, except);
+  send_sigstop (thread, except);
 }
 
 static void
@@ -4156,9 +4155,16 @@ stop_all_lwps (int suspend, struct lwp_info *except)
 		      : STOPPING_THREADS);
 
   if (suspend)
-    find_inferior (&all_threads, suspend_and_send_sigstop_callback, except);
+    for_each_thread ([&] (thread_info *thread)
+      {
+	suspend_and_send_sigstop (thread, except);
+      });
   else
-    find_inferior (&all_threads, send_sigstop_callback, except);
+    for_each_thread ([&] (thread_info *thread)
+      {
+	 send_sigstop (thread, except);
+      });
+
   wait_for_sigstop ();
   stopping_threads = NOT_STOPPING_THREADS;
 
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 18/19] Remove for_each_inferior
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
                   ` (10 preceding siblings ...)
  2017-11-20 16:35 ` [PATCH 02/19] Remove usage of find_inferior in lynx_mourn Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-11-20 16:35 ` [PATCH 17/19] Remove find_inferior Simon Marchi
                   ` (7 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

This patch removes for_each_inferior, replacing all its usages with
for_each_thread.

	* inferiors.c (for_each_inferior): Remove.
	(clear_inferiors): Use for_each_thread.
	* inferiors.h (for_each_inferior): Remove.
	* linux-low.c (linux_wait_for_event_filtered): Use
	for_each_thread.
	(linux_stabilize_threads): Likewise.
	* regcache.c (regcache_release): Likewise.
	* server.c (gdb_wants_all_threads_stopped): Likewise.
	(clear_pending_status_callback): Remove.
	(handle_status): Use for_each_thread.
	(captured_main): Likewise.
	* win32-low.c (child_init_thread_list): Likewise.
	(win32_clear_inferiors): Likewise.
	(fake_breakpoint_event): Likewise.
---
 gdb/gdbserver/inferiors.c | 13 +------------
 gdb/gdbserver/inferiors.h |  2 --
 gdb/gdbserver/linux-low.c |  4 ++--
 gdb/gdbserver/regcache.c  |  2 +-
 gdb/gdbserver/server.c    | 23 ++++++++---------------
 gdb/gdbserver/win32-low.c |  6 +++---
 6 files changed, 15 insertions(+), 35 deletions(-)

diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c
index 47cc13a..093080d 100644
--- a/gdb/gdbserver/inferiors.c
+++ b/gdb/gdbserver/inferiors.c
@@ -31,17 +31,6 @@ struct thread_info *current_thread;
 static const char *current_inferior_cwd = NULL;
 
 void
-for_each_inferior (std::list<thread_info *> *thread_list,
-		   void (*action) (thread_info *))
-{
-  gdb_assert (thread_list == &all_threads);
-
-  for_each_thread ([&] (thread_info *thread) {
-    action (thread);
-  });
-}
-
-void
 for_each_inferior_with_data (std::list<thread_info *> *thread_list,
 			     void (*action) (thread_info *, void *),
 			     void *data)
@@ -151,7 +140,7 @@ set_thread_regcache_data (struct thread_info *thread, struct regcache *data)
 void
 clear_inferiors (void)
 {
-  for_each_inferior (&all_threads, free_one_thread);
+  for_each_thread (free_one_thread);
   all_threads.clear ();
 
   clear_dlls ();
diff --git a/gdb/gdbserver/inferiors.h b/gdb/gdbserver/inferiors.h
index 2aab846..030d9c3 100644
--- a/gdb/gdbserver/inferiors.h
+++ b/gdb/gdbserver/inferiors.h
@@ -140,8 +140,6 @@ int have_attached_inferiors_p (void);
 
 void clear_inferiors (void);
 
-void for_each_inferior (std::list<thread_info *> *thread_list,
-			void (*action) (thread_info *));
 void for_each_inferior_with_data (std::list<thread_info *> *thread_list,
 				  void (*action) (thread_info *, void *),
 				  void *data);
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 630340f..2ff14d1 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -2735,7 +2735,7 @@ linux_wait_for_event_filtered (ptid_t wait_ptid, ptid_t filter_ptid,
       /* Now that we've pulled all events out of the kernel, resume
 	 LWPs that don't have an interesting event to report.  */
       if (stopping_threads == NOT_STOPPING_THREADS)
-	for_each_inferior (&all_threads, resume_stopped_resumed_lwps);
+	for_each_thread (resume_stopped_resumed_lwps);
 
       /* ... and find an LWP with a status to report to the core, if
 	 any.  */
@@ -2971,7 +2971,7 @@ linux_stabilize_threads (void)
   stabilizing_threads = 1;
 
   /* Kick 'em all.  */
-  for_each_inferior (&all_threads, move_out_of_jump_pad_callback);
+  for_each_thread (move_out_of_jump_pad_callback);
 
   /* Loop until all are stopped out of the jump pads.  */
   while (find_thread (lwp_running) != NULL)
diff --git a/gdb/gdbserver/regcache.c b/gdb/gdbserver/regcache.c
index 5f71523..6a27042 100644
--- a/gdb/gdbserver/regcache.c
+++ b/gdb/gdbserver/regcache.c
@@ -281,7 +281,7 @@ void
 regcache_release (void)
 {
   /* Flush and release all pre-existing register caches.  */
-  for_each_inferior (&all_threads, free_register_cache_thread);
+  for_each_thread (free_register_cache_thread);
 }
 #endif
 
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 26c4a01..cfc4a12 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -3216,7 +3216,7 @@ myresume (char *own_buf, int step, int sig)
   resume (resume_info, n);
 }
 
-/* Callback for for_each_inferior.  Make a new stop reply for each
+/* Callback for for_each_thread.  Make a new stop reply for each
    stopped thread.  */
 
 static void
@@ -3281,19 +3281,10 @@ gdb_wants_thread_stopped (thread_info *thread)
 static void
 gdb_wants_all_threads_stopped (void)
 {
-  for_each_inferior (&all_threads, gdb_wants_thread_stopped);
+  for_each_thread (gdb_wants_thread_stopped);
 }
 
-/* Callback for for_each_inferior.  Clear the thread's pending status
-   flag.  */
-
-static void
-clear_pending_status_callback (thread_info *thread)
-{
-  thread->status_pending_p = 0;
-}
-
-/* Callback for for_each_inferior.  If the thread is stopped with an
+/* Callback for for_each_thread.  If the thread is stopped with an
    interesting event, mark it as having a pending event.  */
 
 static void
@@ -3348,7 +3339,7 @@ handle_status (char *own_buf)
 	 reporting now pending.  They'll be reported the next time the
 	 threads are resumed.  Start by marking all interesting events
 	 as pending.  */
-      for_each_inferior (&all_threads, set_pending_status_callback);
+      for_each_thread (set_pending_status_callback);
 
       /* Prefer the last thread that reported an event to GDB (even if
 	 that was a GDB_SIGNAL_TRAP).  */
@@ -3869,8 +3860,10 @@ captured_main (int argc, char *argv[])
 	     (by the same GDB instance or another) will refresh all its
 	     state from scratch.  */
 	  discard_queued_stop_replies (minus_one_ptid);
-	  for_each_inferior (&all_threads,
-			     clear_pending_status_callback);
+	  for_each_thread ([] (thread_info *thread)
+	    {
+	      thread->status_pending_p = 0;
+	    });
 
 	  if (tracing)
 	    {
diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c
index fecab84..be671a6 100644
--- a/gdb/gdbserver/win32-low.c
+++ b/gdb/gdbserver/win32-low.c
@@ -339,7 +339,7 @@ child_xfer_memory (CORE_ADDR memaddr, char *our, int len,
 static void
 child_init_thread_list (void)
 {
-  for_each_inferior (&all_threads, delete_thread_info);
+  for_each_thread (delete_thread_info);
 }
 
 /* Zero during the child initialization phase, and nonzero otherwise.  */
@@ -793,7 +793,7 @@ win32_clear_inferiors (void)
   if (current_process_handle != NULL)
     CloseHandle (current_process_handle);
 
-  for_each_inferior (&all_threads, delete_thread_info);
+  for_each_thread (delete_thread_info);
   clear_inferiors ();
 }
 
@@ -1362,7 +1362,7 @@ fake_breakpoint_event (void)
   current_event.u.Exception.ExceptionRecord.ExceptionCode
     = EXCEPTION_BREAKPOINT;
 
-  for_each_inferior (&all_threads, suspend_one_thread);
+  for_each_thread (suspend_one_thread);
 }
 
 #ifdef _WIN32_WCE
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 00/19] Remove find_inferior* and for_each_inferior*
@ 2017-11-20 16:35 Simon Marchi
  2017-11-20 16:35 ` [PATCH 09/19] Remove usage of find_inferior in find_lwp_pid Simon Marchi
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

This patch series removes the last usages the the find_inferior and
for_each_inferior family of functions in gdbserver, replacing their uses with
the equivalent find_thread or for_each_thread.  The series as a whole has been
regression tested on the Buildbot.

Simon Marchi (19):
  Remove usage of find_inferior in regcache_invalidate_pid
  Remove usage of find_inferior in lynx_mourn
  Remove usages of find_inferior in linux-mips-low.c
  Remove find_inferior_id
  Remove find_inferior_in_random
  Remove usage of find_inferior in last_thread_of_process_p
  Remove usage of find_inferior in linux_detach
  Remove usage of find_inferior in linux_mourn
  Remove usage of find_inferior in find_lwp_pid
  Remove usages of find_inferior calling not_stopped_callback
  Remove usages of find_inferior in select_event_lwp
  Remove usage of find_inferior in linux_stabilize_threads
  Remove usages of find_inferior in stop_all_lwps
  Remove usage of find_inferior in linux_resume
  Remove usages of find_inferior that call proceed_one_lwp
  Update comments
  Remove find_inferior
  Remove for_each_inferior
  Remove for_each_inferior_with_data

 gdb/gdbserver/inferiors.c      |  63 +------
 gdb/gdbserver/inferiors.h      |  13 --
 gdb/gdbserver/linux-low.c      | 377 ++++++++++++++++++-----------------------
 gdb/gdbserver/linux-mips-low.c |  37 ++--
 gdb/gdbserver/lynx-low.c       |  16 +-
 gdb/gdbserver/regcache.c       |  17 +-
 gdb/gdbserver/server.c         |  38 ++---
 gdb/gdbserver/thread-db.c      |   8 +-
 gdb/gdbserver/win32-low.c      |  29 +---
 9 files changed, 212 insertions(+), 386 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 11/19] Remove usages of find_inferior in select_event_lwp
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
                   ` (12 preceding siblings ...)
  2017-11-20 16:35 ` [PATCH 17/19] Remove find_inferior Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-11-20 16:35 ` [PATCH 07/19] Remove usage of find_inferior in linux_detach Simon Marchi
                   ` (5 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace with find_thread/for_each_thread.  I inlined the callbacks,
because they are relatively simple.

gdb/gdbserver/ChangeLog:

	* linux-low.c (select_singlestep_lwp_callback): Remove.
	(count_events_callback): Remove.
	(select_event_lwp_callback): Remove.
	(select_event_lwp): Use find_thread/for_each_thread.
---
 gdb/gdbserver/linux-low.c | 93 ++++++++++++++++-------------------------------
 1 file changed, 31 insertions(+), 62 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 85d5572..bffbc53 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -2817,64 +2817,11 @@ linux_wait_for_event (ptid_t ptid, int *wstatp, int options)
   return linux_wait_for_event_filtered (ptid, ptid, wstatp, options);
 }
 
-/* Count the LWP's that have had events.  */
-
-static int
-count_events_callback (thread_info *thread, void *data)
-{
-  struct lwp_info *lp = get_thread_lwp (thread);
-  int *count = (int *) data;
-
-  gdb_assert (count != NULL);
-
-  /* Count only resumed LWPs that have an event pending. */
-  if (thread->last_status.kind == TARGET_WAITKIND_IGNORE
-      && lp->status_pending_p)
-    (*count)++;
-
-  return 0;
-}
-
-/* Select the LWP (if any) that is currently being single-stepped.  */
-
-static int
-select_singlestep_lwp_callback (thread_info *thread, void *data)
-{
-  struct lwp_info *lp = get_thread_lwp (thread);
-
-  if (thread->last_status.kind == TARGET_WAITKIND_IGNORE
-      && thread->last_resume_kind == resume_step
-      && lp->status_pending_p)
-    return 1;
-  else
-    return 0;
-}
-
-/* Select the Nth LWP that has had an event.  */
-
-static int
-select_event_lwp_callback (thread_info *thread, void *data)
-{
-  struct lwp_info *lp = get_thread_lwp (thread);
-  int *selector = (int *) data;
-
-  gdb_assert (selector != NULL);
-
-  /* Select only resumed LWPs that have an event pending. */
-  if (thread->last_status.kind == TARGET_WAITKIND_IGNORE
-      && lp->status_pending_p)
-    if ((*selector)-- == 0)
-      return 1;
-
-  return 0;
-}
-
 /* Select one LWP out of those that have events pending.  */
 
 static void
 select_event_lwp (struct lwp_info **orig_lp)
 {
-  int num_events = 0;
   int random_selector;
   struct thread_info *event_thread = NULL;
 
@@ -2888,10 +2835,15 @@ select_event_lwp (struct lwp_info **orig_lp)
      would report it to the user as a random signal.  */
   if (!non_stop)
     {
-      event_thread
-	= (struct thread_info *) find_inferior (&all_threads,
-						select_singlestep_lwp_callback,
-						NULL);
+      event_thread = find_thread ([] (thread_info *thread)
+	{
+	  lwp_info *lp = get_thread_lwp (thread);
+
+	  return (thread->last_status.kind == TARGET_WAITKIND_IGNORE
+		  && thread->last_resume_kind == resume_step
+		  && lp->status_pending_p);
+	});
+
       if (event_thread != NULL)
 	{
 	  if (debug_threads)
@@ -2905,7 +2857,16 @@ select_event_lwp (struct lwp_info **orig_lp)
          which have had events.  */
 
       /* First see how many events we have.  */
-      find_inferior (&all_threads, count_events_callback, &num_events);
+      int num_events = 0;
+      for_each_thread ([&] (thread_info *thread)
+	{
+	  lwp_info *lp = get_thread_lwp (thread);
+
+	  /* Count only resumed LWPs that have an event pending. */
+	  if (thread->last_status.kind == TARGET_WAITKIND_IGNORE
+	      && lp->status_pending_p)
+	    num_events++;
+	});
       gdb_assert (num_events > 0);
 
       /* Now randomly pick a LWP out of those that have had
@@ -2917,10 +2878,18 @@ select_event_lwp (struct lwp_info **orig_lp)
 	debug_printf ("SEL: Found %d SIGTRAP events, selecting #%d\n",
 		      num_events, random_selector);
 
-      event_thread
-	= (struct thread_info *) find_inferior (&all_threads,
-						select_event_lwp_callback,
-						&random_selector);
+      event_thread = find_thread ([&] (thread_info *thread)
+	{
+	  lwp_info *lp = get_thread_lwp (thread);
+
+	  /* Select only resumed LWPs that have an event pending.  */
+	  if (thread->last_status.kind == TARGET_WAITKIND_IGNORE
+	      && lp->status_pending_p)
+	    if (random_selector-- == 0)
+	      return true;
+
+	  return false;
+	});
     }
 
   if (event_thread != NULL)
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 15/19] Remove usages of find_inferior that call proceed_one_lwp
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
                   ` (17 preceding siblings ...)
  2017-11-20 16:35 ` [PATCH 06/19] Remove usage of find_inferior in last_thread_of_process_p Simon Marchi
@ 2017-11-20 16:35 ` Simon Marchi
  2017-12-03  1:48 ` [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-11-20 16:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace with for_each_thread.

gdb/gdbserver/ChangeLog:

	* linux-low.c (proceed_one_lwp): Return void, change parameter
	type.
	(unsuspend_and_proceed_one_lwp): Likewise.
	(proceed_all_lwps): Use for_each_thread.
	(unstop_all_lwps): Likewise.
---
 gdb/gdbserver/linux-low.c | 40 ++++++++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 740a98b..58145a5 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -279,7 +279,7 @@ static void enqueue_pending_signal (struct lwp_info *lwp, int signal, siginfo_t
 static void complete_ongoing_step_over (void);
 static int linux_low_ptrace_options (int attached);
 static int check_ptrace_stopped_lwp_gone (struct lwp_info *lp);
-static int proceed_one_lwp (thread_info *thread, void *except);
+static void proceed_one_lwp (thread_info *thread, lwp_info *except);
 
 /* When the event-loop is doing a step-over, this points at the thread
    being stepped.  */
@@ -5105,14 +5105,14 @@ linux_resume (struct thread_resume *resume_info, size_t n)
    breakpoint that needs stepping over, we start a step-over operation
    on that particular thread, and leave all others stopped.  */
 
-static int
-proceed_one_lwp (thread_info *thread, void *except)
+static void
+proceed_one_lwp (thread_info *thread, lwp_info *except)
 {
   struct lwp_info *lwp = get_thread_lwp (thread);
   int step;
 
   if (lwp == except)
-    return 0;
+    return;
 
   if (debug_threads)
     debug_printf ("proceed_one_lwp: lwp %ld\n", lwpid_of (thread));
@@ -5121,7 +5121,7 @@ proceed_one_lwp (thread_info *thread, void *except)
     {
       if (debug_threads)
 	debug_printf ("   LWP %ld already running\n", lwpid_of (thread));
-      return 0;
+      return;
     }
 
   if (thread->last_resume_kind == resume_stop
@@ -5130,7 +5130,7 @@ proceed_one_lwp (thread_info *thread, void *except)
       if (debug_threads)
 	debug_printf ("   client wants LWP to remain %ld stopped\n",
 		      lwpid_of (thread));
-      return 0;
+      return;
     }
 
   if (lwp->status_pending_p)
@@ -5138,7 +5138,7 @@ proceed_one_lwp (thread_info *thread, void *except)
       if (debug_threads)
 	debug_printf ("   LWP %ld has pending status, leaving stopped\n",
 		      lwpid_of (thread));
-      return 0;
+      return;
     }
 
   gdb_assert (lwp->suspended >= 0);
@@ -5147,7 +5147,7 @@ proceed_one_lwp (thread_info *thread, void *except)
     {
       if (debug_threads)
 	debug_printf ("   LWP %ld is suspended\n", lwpid_of (thread));
-      return 0;
+      return;
     }
 
   if (thread->last_resume_kind == resume_stop
@@ -5200,20 +5200,19 @@ proceed_one_lwp (thread_info *thread, void *except)
     step = 0;
 
   linux_resume_one_lwp (lwp, step, 0, NULL);
-  return 0;
 }
 
-static int
-unsuspend_and_proceed_one_lwp (thread_info *thread, void *except)
+static void
+unsuspend_and_proceed_one_lwp (thread_info *thread, lwp_info *except)
 {
   struct lwp_info *lwp = get_thread_lwp (thread);
 
   if (lwp == except)
-    return 0;
+    return;
 
   lwp_suspended_decr (lwp);
 
-  return proceed_one_lwp (thread, except);
+  proceed_one_lwp (thread, except);
 }
 
 /* When we finish a step-over, set threads running again.  If there's
@@ -5249,7 +5248,10 @@ proceed_all_lwps (void)
   if (debug_threads)
     debug_printf ("Proceeding, no step-over needed\n");
 
-  find_inferior (&all_threads, proceed_one_lwp, NULL);
+  for_each_thread ([] (thread_info *thread)
+    {
+      proceed_one_lwp (thread, NULL);
+    });
 }
 
 /* Stopped LWPs that the client wanted to be running, that don't have
@@ -5270,9 +5272,15 @@ unstop_all_lwps (int unsuspend, struct lwp_info *except)
     }
 
   if (unsuspend)
-    find_inferior (&all_threads, unsuspend_and_proceed_one_lwp, except);
+    for_each_thread ([&] (thread_info *thread)
+      {
+	unsuspend_and_proceed_one_lwp (thread, except);
+      });
   else
-    find_inferior (&all_threads, proceed_one_lwp, except);
+    for_each_thread ([&] (thread_info *thread)
+      {
+	proceed_one_lwp (thread, except);
+      });
 
   if (debug_threads)
     {
-- 
2.7.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 00/19] Remove find_inferior* and for_each_inferior*
  2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
                   ` (18 preceding siblings ...)
  2017-11-20 16:35 ` [PATCH 15/19] Remove usages of find_inferior that call proceed_one_lwp Simon Marchi
@ 2017-12-03  1:48 ` Simon Marchi
  19 siblings, 0 replies; 21+ messages in thread
From: Simon Marchi @ 2017-12-03  1:48 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 2017-11-20 11:34 AM, Simon Marchi wrote:
> This patch series removes the last usages the the find_inferior and
> for_each_inferior family of functions in gdbserver, replacing their uses with
> the equivalent find_thread or for_each_thread.  The series as a whole has been
> regression tested on the Buildbot.
> 
> Simon Marchi (19):
>   Remove usage of find_inferior in regcache_invalidate_pid
>   Remove usage of find_inferior in lynx_mourn
>   Remove usages of find_inferior in linux-mips-low.c
>   Remove find_inferior_id
>   Remove find_inferior_in_random
>   Remove usage of find_inferior in last_thread_of_process_p
>   Remove usage of find_inferior in linux_detach
>   Remove usage of find_inferior in linux_mourn
>   Remove usage of find_inferior in find_lwp_pid
>   Remove usages of find_inferior calling not_stopped_callback
>   Remove usages of find_inferior in select_event_lwp
>   Remove usage of find_inferior in linux_stabilize_threads
>   Remove usages of find_inferior in stop_all_lwps
>   Remove usage of find_inferior in linux_resume
>   Remove usages of find_inferior that call proceed_one_lwp
>   Update comments
>   Remove find_inferior
>   Remove for_each_inferior
>   Remove for_each_inferior_with_data
> 
>  gdb/gdbserver/inferiors.c      |  63 +------
>  gdb/gdbserver/inferiors.h      |  13 --
>  gdb/gdbserver/linux-low.c      | 377 ++++++++++++++++++-----------------------
>  gdb/gdbserver/linux-mips-low.c |  37 ++--
>  gdb/gdbserver/lynx-low.c       |  16 +-
>  gdb/gdbserver/regcache.c       |  17 +-
>  gdb/gdbserver/server.c         |  38 ++---
>  gdb/gdbserver/thread-db.c      |   8 +-
>  gdb/gdbserver/win32-low.c      |  29 +---
>  9 files changed, 212 insertions(+), 386 deletions(-)
> 

I pushed this series in.

Simon

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2017-12-03  1:48 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
2017-11-20 16:35 ` [PATCH 09/19] Remove usage of find_inferior in find_lwp_pid Simon Marchi
2017-11-20 16:35 ` [PATCH 14/19] Remove usage of find_inferior in linux_resume Simon Marchi
2017-11-20 16:35 ` [PATCH 05/19] Remove find_inferior_in_random Simon Marchi
2017-11-20 16:35 ` [PATCH 13/19] Remove usages of find_inferior in stop_all_lwps Simon Marchi
2017-11-20 16:35 ` [PATCH 01/19] Remove usage of find_inferior in regcache_invalidate_pid Simon Marchi
2017-11-20 16:35 ` [PATCH 16/19] Update comments Simon Marchi
2017-11-20 16:35 ` [PATCH 04/19] Remove find_inferior_id Simon Marchi
2017-11-20 16:35 ` [PATCH 19/19] Remove for_each_inferior_with_data Simon Marchi
2017-11-20 16:35 ` [PATCH 10/19] Remove usages of find_inferior calling not_stopped_callback Simon Marchi
2017-11-20 16:35 ` [PATCH 12/19] Remove usage of find_inferior in linux_stabilize_threads Simon Marchi
2017-11-20 16:35 ` [PATCH 02/19] Remove usage of find_inferior in lynx_mourn Simon Marchi
2017-11-20 16:35 ` [PATCH 18/19] Remove for_each_inferior Simon Marchi
2017-11-20 16:35 ` [PATCH 17/19] Remove find_inferior Simon Marchi
2017-11-20 16:35 ` [PATCH 11/19] Remove usages of find_inferior in select_event_lwp Simon Marchi
2017-11-20 16:35 ` [PATCH 07/19] Remove usage of find_inferior in linux_detach Simon Marchi
2017-11-20 16:35 ` [PATCH 08/19] Remove usage of find_inferior in linux_mourn Simon Marchi
2017-11-20 16:35 ` [PATCH 03/19] Remove usages of find_inferior in linux-mips-low.c Simon Marchi
2017-11-20 16:35 ` [PATCH 06/19] Remove usage of find_inferior in last_thread_of_process_p Simon Marchi
2017-11-20 16:35 ` [PATCH 15/19] Remove usages of find_inferior that call proceed_one_lwp Simon Marchi
2017-12-03  1:48 ` [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).