GDBserver: Pass process_info pointer to target_kill
authorPedro Alves <palves@redhat.com>
Fri, 13 Jul 2018 09:28:47 +0000 (10:28 +0100)
committerPedro Alves <palves@redhat.com>
Fri, 13 Jul 2018 09:58:17 +0000 (10:58 +0100)
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.

gdb/gdbserver/ChangeLog
gdb/gdbserver/linux-low.c
gdb/gdbserver/lynx-low.c
gdb/gdbserver/nto-low.c
gdb/gdbserver/server.c
gdb/gdbserver/spu-low.c
gdb/gdbserver/target.c
gdb/gdbserver/target.h
gdb/gdbserver/win32-low.c

index a5cf8cff8ddd21374c75c2dd0574627205294758..be26645bb48ed88d7221b1f9c0a63f28c609f33b 100644 (file)
@@ -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>
 
        * linux-low.c (linux_detach, linux_join): Change parameter to
index dfa7fbaa494d84d7548acb6f6dc3a2a24581e999..984464fcc217f98b9b35868e410c164ec1cbb84a 100644 (file)
@@ -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)
     {
index 902a70386b71d213f3975cd62c86edc64da83d66..6c5933bc4705022c4d3b6a8714ea34851bd5ab6d 100644 (file)
@@ -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);
index 05ab6fc4edf9d44b667cd1a896586bc4d8e99deb..0f763679d001b97e08868984ea203e2c7eccd466 100644 (file)
@@ -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 ();
index b35015b7bfd3e0ed1536eddcf642611abdd6e9c9..a491ae025744458cd1ead895c4fb03e637a763df 100644 (file)
@@ -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));
   });
index c2a8734f680d849b6f3de1b67dec796988082159..83a31a203d48b1fe1ce0ed834c97682775530854 100644 (file)
@@ -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);
 
index 00379bfdc0062ce0c31b70b6ec7c3410c5ced281..886e6cfb5c25e2787d5835d8d9dde11f350ba0d4 100644 (file)
@@ -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.  */
index 7f594855803ad10f38970f0fe695450bd9c55f63..fce54e05adbc3b6509cb2c891a067154cc72cd4f 100644 (file)
@@ -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 ? \
index 17729a83cc63345d1faefb54b78fda635ae9cc0b..765391dd4778e81df6c870a172326e50cc21c97d 100644 (file)
@@ -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;
 }
This page took 0.037391 seconds and 4 git commands to generate.