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.
This commit is contained in:
parent
ef2ddb33bd
commit
a780ef4f27
9 changed files with 43 additions and 40 deletions
|
@ -1,3 +1,20 @@
|
||||||
|
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>
|
2018-07-13 Pedro Alves <palves@redhat.com>
|
||||||
|
|
||||||
* linux-low.c (linux_detach, linux_join): Change parameter to
|
* linux-low.c (linux_detach, linux_join): Change parameter to
|
||||||
|
|
|
@ -1385,14 +1385,9 @@ kill_one_lwp_callback (thread_info *thread, int pid)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
linux_kill (int pid)
|
linux_kill (process_info *process)
|
||||||
{
|
{
|
||||||
struct process_info *process;
|
int pid = process->pid;
|
||||||
struct lwp_info *lwp;
|
|
||||||
|
|
||||||
process = find_process_pid (pid);
|
|
||||||
if (process == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
/* If we're killing a running inferior, make sure it is stopped
|
/* If we're killing a running inferior, make sure it is stopped
|
||||||
first, as PTRACE_KILL will not work otherwise. */
|
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
|
/* See the comment in linux_kill_one_lwp. We did not kill the first
|
||||||
thread in the list, so do so now. */
|
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)
|
if (lwp == NULL)
|
||||||
{
|
{
|
||||||
|
|
|
@ -522,15 +522,10 @@ lynx_wait (ptid_t ptid, struct target_waitstatus *status, int options)
|
||||||
/* Implement the kill target_ops method. */
|
/* Implement the kill target_ops method. */
|
||||||
|
|
||||||
static int
|
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 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_ptrace (PTRACE_KILL, ptid, 0, 0, 0);
|
||||||
lynx_wait (ptid, &status, 0);
|
lynx_wait (ptid, &status, 0);
|
||||||
|
|
|
@ -397,8 +397,10 @@ nto_attach (unsigned long pid)
|
||||||
/* Send signal to process PID. */
|
/* Send signal to process PID. */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
nto_kill (int pid)
|
nto_kill (process_info *proc)
|
||||||
{
|
{
|
||||||
|
int pid = proc->pid;
|
||||||
|
|
||||||
TRACE ("%s %d\n", __func__, pid);
|
TRACE ("%s %d\n", __func__, pid);
|
||||||
kill (pid, SIGKILL);
|
kill (pid, SIGKILL);
|
||||||
do_detach ();
|
do_detach ();
|
||||||
|
|
|
@ -3080,7 +3080,10 @@ handle_v_kill (char *own_buf)
|
||||||
pid = strtol (p, NULL, 16);
|
pid = strtol (p, NULL, 16);
|
||||||
else
|
else
|
||||||
pid = signal_pid;
|
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.kind = TARGET_WAITKIND_SIGNALLED;
|
||||||
cs.last_status.value.sig = GDB_SIGNAL_KILL;
|
cs.last_status.value.sig = GDB_SIGNAL_KILL;
|
||||||
|
@ -3481,10 +3484,8 @@ gdbserver_show_disableable (FILE *stream)
|
||||||
static void
|
static void
|
||||||
kill_inferior_callback (process_info *process)
|
kill_inferior_callback (process_info *process)
|
||||||
{
|
{
|
||||||
int pid = process->pid;
|
kill_inferior (process);
|
||||||
|
discard_queued_stop_replies (ptid_t (process->pid));
|
||||||
kill_inferior (pid);
|
|
||||||
discard_queued_stop_replies (ptid_t (pid));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Call this when exiting gdbserver with possible inferiors that need
|
/* Call this when exiting gdbserver with possible inferiors that need
|
||||||
|
@ -3528,7 +3529,7 @@ detach_or_kill_for_exit (void)
|
||||||
if (process->attached)
|
if (process->attached)
|
||||||
detach_inferior (process);
|
detach_inferior (process);
|
||||||
else
|
else
|
||||||
kill_inferior (pid);
|
kill_inferior (process);
|
||||||
|
|
||||||
discard_queued_stop_replies (ptid_t (pid));
|
discard_queued_stop_replies (ptid_t (pid));
|
||||||
});
|
});
|
||||||
|
|
|
@ -326,12 +326,10 @@ spu_attach (unsigned long pid)
|
||||||
|
|
||||||
/* Kill the inferior process. */
|
/* Kill the inferior process. */
|
||||||
static int
|
static int
|
||||||
spu_kill (int pid)
|
spu_kill (process_info *process)
|
||||||
{
|
{
|
||||||
int status, ret;
|
int status, ret;
|
||||||
struct process_info *process = find_process_pid (pid);
|
int pid = process->pid;
|
||||||
if (process == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
ptrace (PTRACE_KILL, pid, 0, 0);
|
ptrace (PTRACE_KILL, pid, 0, 0);
|
||||||
|
|
||||||
|
|
|
@ -332,11 +332,11 @@ target_pid_to_str (ptid_t ptid)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
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. */
|
/* Target can do hardware single step. */
|
||||||
|
|
|
@ -90,9 +90,9 @@ struct target_ops
|
||||||
|
|
||||||
int (*attach) (unsigned long pid);
|
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
|
/* Detach from process PROC. Return -1 on failure, and 0 on
|
||||||
success. */
|
success. */
|
||||||
|
@ -497,7 +497,7 @@ void set_target_ops (struct target_ops *);
|
||||||
#define myattach(pid) \
|
#define myattach(pid) \
|
||||||
(*the_target->attach) (pid)
|
(*the_target->attach) (pid)
|
||||||
|
|
||||||
int kill_inferior (int);
|
int kill_inferior (process_info *proc);
|
||||||
|
|
||||||
#define target_supports_fork_events() \
|
#define target_supports_fork_events() \
|
||||||
(the_target->supports_fork_events ? \
|
(the_target->supports_fork_events ? \
|
||||||
|
|
|
@ -805,15 +805,11 @@ win32_clear_inferiors (void)
|
||||||
clear_inferiors ();
|
clear_inferiors ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Kill all inferiors. */
|
/* Implementation of target_ops::kill. */
|
||||||
|
|
||||||
static int
|
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);
|
TerminateProcess (current_process_handle, 0);
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
@ -829,7 +825,6 @@ win32_kill (int pid)
|
||||||
|
|
||||||
win32_clear_inferiors ();
|
win32_clear_inferiors ();
|
||||||
|
|
||||||
process = find_process_pid (pid);
|
|
||||||
remove_process (process);
|
remove_process (process);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue