aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2018-07-13 10:28:47 +0100
committerPedro Alves <palves@redhat.com>2018-07-13 10:58:17 +0100
commita780ef4f27f8bc44082be81fdbee44bb11f1049c (patch)
treeb71879dc14a53dc2bdb35604e7d52bc8b3fccaa8
parentef2ddb33bd29a7c4f7027b9e37e55c74c15af825 (diff)
downloadgdb-a780ef4f27f8bc44082be81fdbee44bb11f1049c.zip
gdb-a780ef4f27f8bc44082be81fdbee44bb11f1049c.tar.gz
gdb-a780ef4f27f8bc44082be81fdbee44bb11f1049c.tar.bz2
GDBserver: Pass process_info pointer to target_kill
We start from a process_info pointer, pass down process->pid, and then the target_kill implementations need to find the process from the pid again. Pass the process_info pointer down directly instead. gdb/gdbserver/ChangeLog: 2018-07-13 Pedro Alves <palves@redhat.com> * linux-low.c (linux_kill): Change parameter to process_info pointer instead of pid. Adjust. * lynx-low.c (lynx_kill): Likewise. * nto-low.c (nto_kill): Likewise. * spu-low.c (spu_kill): Likewise. * win32-low.c (win32_kill): Likewise. * server.c (handle_v_kill, kill_inferior_callback) (detach_or_kill_for_exit): Adjust. * target.c (kill_inferior): Change parameter to process_info pointer instead of pid. Adjust. * target.h (struct target_ops) <kill>: Change parameter to process_info pointer instead of pid. Adjust all implementations and callers. (kill_inferior): Likewise.
-rw-r--r--gdb/gdbserver/ChangeLog17
-rw-r--r--gdb/gdbserver/linux-low.c11
-rw-r--r--gdb/gdbserver/lynx-low.c9
-rw-r--r--gdb/gdbserver/nto-low.c4
-rw-r--r--gdb/gdbserver/server.c13
-rw-r--r--gdb/gdbserver/spu-low.c6
-rw-r--r--gdb/gdbserver/target.c6
-rw-r--r--gdb/gdbserver/target.h6
-rw-r--r--gdb/gdbserver/win32-low.c11
9 files changed, 43 insertions, 40 deletions
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index a5cf8cf..be26645 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,5 +1,22 @@
2018-07-13 Pedro Alves <palves@redhat.com>
+ * linux-low.c (linux_kill): Change parameter to process_info
+ pointer instead of pid. Adjust.
+ * lynx-low.c (lynx_kill): Likewise.
+ * nto-low.c (nto_kill): Likewise.
+ * spu-low.c (spu_kill): Likewise.
+ * win32-low.c (win32_kill): Likewise.
+ * server.c (handle_v_kill, kill_inferior_callback)
+ (detach_or_kill_for_exit): Adjust.
+ * target.c (kill_inferior): Change parameter to process_info
+ pointer instead of pid. Adjust.
+ * target.h (struct target_ops) <kill>: Change parameter to
+ process_info pointer instead of pid. Adjust all implementations
+ and callers.
+ (kill_inferior): Likewise.
+
+2018-07-13 Pedro Alves <palves@redhat.com>
+
* linux-low.c (linux_detach, linux_join): Change parameter to
process_info pointer instead of pid. Adjust.
* lynx-low.c (lynx_detach, lynx_join): Likewise.
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index dfa7fba..984464f 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -1385,14 +1385,9 @@ kill_one_lwp_callback (thread_info *thread, int pid)
}
static int
-linux_kill (int pid)
+linux_kill (process_info *process)
{
- struct process_info *process;
- struct lwp_info *lwp;
-
- process = find_process_pid (pid);
- if (process == NULL)
- return -1;
+ int pid = process->pid;
/* If we're killing a running inferior, make sure it is stopped
first, as PTRACE_KILL will not work otherwise. */
@@ -1405,7 +1400,7 @@ linux_kill (int pid)
/* See the comment in linux_kill_one_lwp. We did not kill the first
thread in the list, so do so now. */
- lwp = find_lwp_pid (ptid_t (pid));
+ lwp_info *lwp = find_lwp_pid (ptid_t (pid));
if (lwp == NULL)
{
diff --git a/gdb/gdbserver/lynx-low.c b/gdb/gdbserver/lynx-low.c
index 902a703..6c5933b 100644
--- a/gdb/gdbserver/lynx-low.c
+++ b/gdb/gdbserver/lynx-low.c
@@ -522,15 +522,10 @@ lynx_wait (ptid_t ptid, struct target_waitstatus *status, int options)
/* Implement the kill target_ops method. */
static int
-lynx_kill (int pid)
+lynx_kill (process_info *process)
{
- ptid_t ptid = lynx_ptid_t (pid, 0);
+ ptid_t ptid = lynx_ptid_t (process->pid, 0);
struct target_waitstatus status;
- struct process_info *process;
-
- process = find_process_pid (pid);
- if (process == NULL)
- return -1;
lynx_ptrace (PTRACE_KILL, ptid, 0, 0, 0);
lynx_wait (ptid, &status, 0);
diff --git a/gdb/gdbserver/nto-low.c b/gdb/gdbserver/nto-low.c
index 05ab6fc..0f76367 100644
--- a/gdb/gdbserver/nto-low.c
+++ b/gdb/gdbserver/nto-low.c
@@ -397,8 +397,10 @@ nto_attach (unsigned long pid)
/* Send signal to process PID. */
static int
-nto_kill (int pid)
+nto_kill (process_info *proc)
{
+ int pid = proc->pid;
+
TRACE ("%s %d\n", __func__, pid);
kill (pid, SIGKILL);
do_detach ();
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index b35015b..a491ae0 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -3080,7 +3080,10 @@ handle_v_kill (char *own_buf)
pid = strtol (p, NULL, 16);
else
pid = signal_pid;
- if (pid != 0 && kill_inferior (pid) == 0)
+
+ process_info *proc = find_process_pid (pid);
+
+ if (proc != nullptr && kill_inferior (proc) == 0)
{
cs.last_status.kind = TARGET_WAITKIND_SIGNALLED;
cs.last_status.value.sig = GDB_SIGNAL_KILL;
@@ -3481,10 +3484,8 @@ gdbserver_show_disableable (FILE *stream)
static void
kill_inferior_callback (process_info *process)
{
- int pid = process->pid;
-
- kill_inferior (pid);
- discard_queued_stop_replies (ptid_t (pid));
+ kill_inferior (process);
+ discard_queued_stop_replies (ptid_t (process->pid));
}
/* Call this when exiting gdbserver with possible inferiors that need
@@ -3528,7 +3529,7 @@ detach_or_kill_for_exit (void)
if (process->attached)
detach_inferior (process);
else
- kill_inferior (pid);
+ kill_inferior (process);
discard_queued_stop_replies (ptid_t (pid));
});
diff --git a/gdb/gdbserver/spu-low.c b/gdb/gdbserver/spu-low.c
index c2a8734..83a31a2 100644
--- a/gdb/gdbserver/spu-low.c
+++ b/gdb/gdbserver/spu-low.c
@@ -326,12 +326,10 @@ spu_attach (unsigned long pid)
/* Kill the inferior process. */
static int
-spu_kill (int pid)
+spu_kill (process_info *process)
{
int status, ret;
- struct process_info *process = find_process_pid (pid);
- if (process == NULL)
- return -1;
+ int pid = process->pid;
ptrace (PTRACE_KILL, pid, 0, 0);
diff --git a/gdb/gdbserver/target.c b/gdb/gdbserver/target.c
index 00379bf..886e6cf 100644
--- a/gdb/gdbserver/target.c
+++ b/gdb/gdbserver/target.c
@@ -332,11 +332,11 @@ target_pid_to_str (ptid_t ptid)
}
int
-kill_inferior (int pid)
+kill_inferior (process_info *proc)
{
- gdb_agent_about_to_close (pid);
+ gdb_agent_about_to_close (proc->pid);
- return (*the_target->kill) (pid);
+ return (*the_target->kill) (proc);
}
/* Target can do hardware single step. */
diff --git a/gdb/gdbserver/target.h b/gdb/gdbserver/target.h
index 7f59485..fce54e0 100644
--- a/gdb/gdbserver/target.h
+++ b/gdb/gdbserver/target.h
@@ -90,9 +90,9 @@ struct target_ops
int (*attach) (unsigned long pid);
- /* Kill inferior PID. Return -1 on failure, and 0 on success. */
+ /* Kill process PROC. Return -1 on failure, and 0 on success. */
- int (*kill) (int pid);
+ int (*kill) (process_info *proc);
/* Detach from process PROC. Return -1 on failure, and 0 on
success. */
@@ -497,7 +497,7 @@ void set_target_ops (struct target_ops *);
#define myattach(pid) \
(*the_target->attach) (pid)
-int kill_inferior (int);
+int kill_inferior (process_info *proc);
#define target_supports_fork_events() \
(the_target->supports_fork_events ? \
diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c
index 17729a8..765391d 100644
--- a/gdb/gdbserver/win32-low.c
+++ b/gdb/gdbserver/win32-low.c
@@ -805,15 +805,11 @@ win32_clear_inferiors (void)
clear_inferiors ();
}
-/* Kill all inferiors. */
+/* Implementation of target_ops::kill. */
+
static int
-win32_kill (int pid)
+win32_kill (process_info *process)
{
- struct process_info *process;
-
- if (current_process_handle == NULL)
- return -1;
-
TerminateProcess (current_process_handle, 0);
for (;;)
{
@@ -829,7 +825,6 @@ win32_kill (int pid)
win32_clear_inferiors ();
- process = find_process_pid (pid);
remove_process (process);
return 0;
}