aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbserver
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/gdbserver')
-rw-r--r--gdb/gdbserver/ChangeLog6
-rw-r--r--gdb/gdbserver/linux-low.c68
2 files changed, 48 insertions, 26 deletions
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index cd5aa0f..e6b0a84 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,3 +1,9 @@
+2014-07-11 Pedro Alves <palves@redhat.com>
+
+ * linux-low.c (kill_wait_lwp): New function, based on
+ kill_one_lwp_callback, but use my_waitpid directly.
+ (kill_one_lwp_callback, linux_kill): Use it.
+
2014-06-23 Pedro Alves <palves@redhat.com>
* linux-x86-low.c (x86_linux_prepare_to_resume): Clear DR_CONTROL
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 61552f4..215a80c 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -909,6 +909,46 @@ linux_kill_one_lwp (struct lwp_info *lwp)
errno ? strerror (errno) : "OK");
}
+/* Kill LWP and wait for it to die. */
+
+static void
+kill_wait_lwp (struct lwp_info *lwp)
+{
+ struct thread_info *thr = get_lwp_thread (lwp);
+ int pid = ptid_get_pid (ptid_of (thr));
+ int lwpid = ptid_get_lwp (ptid_of (thr));
+ int wstat;
+ int res;
+
+ if (debug_threads)
+ debug_printf ("kwl: killing lwp %d, for pid: %d\n", lwpid, pid);
+
+ do
+ {
+ linux_kill_one_lwp (lwp);
+
+ /* Make sure it died. Notes:
+
+ - The loop is most likely unnecessary.
+
+ - We don't use linux_wait_for_event as that could delete lwps
+ while we're iterating over them. We're not interested in
+ any pending status at this point, only in making sure all
+ wait status on the kernel side are collected until the
+ process is reaped.
+
+ - We don't use __WALL here as the __WALL emulation relies on
+ SIGCHLD, and killing a stopped process doesn't generate
+ one, nor an exit status.
+ */
+ res = my_waitpid (lwpid, &wstat, 0);
+ if (res == -1 && errno == ECHILD)
+ res = my_waitpid (lwpid, &wstat, __WCLONE);
+ } while (res > 0 && WIFSTOPPED (wstat));
+
+ gdb_assert (res > 0);
+}
+
/* Callback for `find_inferior'. Kills an lwp of a given process,
except the leader. */
@@ -917,7 +957,6 @@ kill_one_lwp_callback (struct inferior_list_entry *entry, void *args)
{
struct thread_info *thread = (struct thread_info *) entry;
struct lwp_info *lwp = get_thread_lwp (thread);
- int wstat;
int pid = * (int *) args;
if (ptid_get_pid (entry->id) != pid)
@@ -936,14 +975,7 @@ kill_one_lwp_callback (struct inferior_list_entry *entry, void *args)
return 0;
}
- do
- {
- linux_kill_one_lwp (lwp);
-
- /* Make sure it died. The loop is most likely unnecessary. */
- pid = linux_wait_for_event (thread->entry.id, &wstat, __WALL);
- } while (pid > 0 && WIFSTOPPED (wstat));
-
+ kill_wait_lwp (lwp);
return 0;
}
@@ -952,8 +984,6 @@ linux_kill (int pid)
{
struct process_info *process;
struct lwp_info *lwp;
- int wstat;
- int lwpid;
process = find_process_pid (pid);
if (process == NULL)
@@ -976,21 +1006,7 @@ linux_kill (int pid)
pid);
}
else
- {
- struct thread_info *thr = get_lwp_thread (lwp);
-
- if (debug_threads)
- debug_printf ("lk_1: killing lwp %ld, for pid: %d\n",
- lwpid_of (thr), pid);
-
- do
- {
- linux_kill_one_lwp (lwp);
-
- /* Make sure it died. The loop is most likely unnecessary. */
- lwpid = linux_wait_for_event (thr->entry.id, &wstat, __WALL);
- } while (lwpid > 0 && WIFSTOPPED (wstat));
- }
+ kill_wait_lwp (lwp);
the_target->mourn (process);