This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 07/19] Remove usage of find_inferior in linux_detach
- From: Simon Marchi <simon dot marchi at ericsson dot com>
- To: <gdb-patches at sourceware dot org>
- Cc: Simon Marchi <simon dot marchi at polymtl dot ca>
- Date: Mon, 20 Nov 2017 11:34:31 -0500
- Subject: [PATCH 07/19] Remove usage of find_inferior in linux_detach
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp.mailfrom=simon dot marchi at ericsson dot com;
- References: <1511195683-2055-1-git-send-email-simon.marchi@ericsson.com>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
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