]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
GDBserver: Pass process_info pointer to target_detach and target_join
authorPedro Alves <palves@redhat.com>
Fri, 13 Jul 2018 09:28:46 +0000 (10:28 +0100)
committerPedro Alves <palves@redhat.com>
Fri, 13 Jul 2018 09:28:46 +0000 (10:28 +0100)
We start from a process_info pointer, pass down process->pid, and then
the target_detach and target_join 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_detach, linux_join): Change parameter to
process_info pointer instead of pid.  Adjust.
* lynx-low.c (lynx_detach, lynx_join): Likewise.
* nto-low.c (nto_detach): Likewise.
* spu-low.c (spu_detach, spu_join): Likewise.
* win32-low.c (win32_detach, win32_join): Likewise.
* server.c (handle_detach, detach_or_kill_for_exit): Adjust.
* target.h (struct target_ops) <detach, join>: Change parameter to
process_info pointer instead of pid.  Adjust all implementations
and callers.
(detach_inferior, join_inferior): Rename 'pid' parameter to
'proc'.

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.h
gdb/gdbserver/win32-low.c

index 38bf0c4a42d5565a805ce8768e507f014eb87417..a5cf8cff8ddd21374c75c2dd0574627205294758 100644 (file)
@@ -1,3 +1,18 @@
+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.
+       * nto-low.c (nto_detach): Likewise.
+       * spu-low.c (spu_detach, spu_join): Likewise.
+       * win32-low.c (win32_detach, win32_join): Likewise.
+       * server.c (handle_detach, detach_or_kill_for_exit): Adjust.
+       * target.h (struct target_ops) <detach, join>: Change parameter to
+       process_info pointer instead of pid.  Adjust all implementations
+       and callers.
+       (detach_inferior, join_inferior): Rename 'pid' parameter to
+       'proc'.
+
 2018-07-11  Sergio Durigan Junior  <sergiodj@redhat.com>
            Jan Kratochvil  <jan.kratochvil@redhat.com>
            Paul Fertser  <fercerpav@gmail.com>
index 7c396ae36628bd3ea58902384bd678b3ae64edcd..dfa7fbaa494d84d7548acb6f6dc3a2a24581e999 100644 (file)
@@ -1608,15 +1608,10 @@ linux_detach_lwp_callback (thread_info *thread)
 }
 
 static int
-linux_detach (int pid)
+linux_detach (process_info *process)
 {
-  struct process_info *process;
   struct lwp_info *main_lwp;
 
-  process = find_process_pid (pid);
-  if (process == NULL)
-    return -1;
-
   /* As there's a step over already in progress, let it finish first,
      otherwise nesting a stabilize_threads operation on top gets real
      messy.  */
@@ -1638,9 +1633,9 @@ 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.  */
-  for_each_thread (pid, linux_detach_lwp_callback);
+  for_each_thread (process->pid, linux_detach_lwp_callback);
 
-  main_lwp = find_lwp_pid (ptid_t (pid));
+  main_lwp = find_lwp_pid (ptid_t (process->pid));
   linux_detach_one_lwp (main_lwp);
 
   the_target->mourn (process);
@@ -1680,12 +1675,12 @@ linux_mourn (struct process_info *process)
 }
 
 static void
-linux_join (int pid)
+linux_join (process_info *proc)
 {
   int status, ret;
 
   do {
-    ret = my_waitpid (pid, &status, 0);
+    ret = my_waitpid (proc->pid, &status, 0);
     if (WIFEXITED (status) || WIFSIGNALED (status))
       break;
   } while (ret != -1 || errno != ECHILD);
index b68bbeaf20a2beda43a2b5d028efbcc1e90434f6..902a70386b71d213f3975cd62c86edc64da83d66 100644 (file)
@@ -541,14 +541,9 @@ lynx_kill (int pid)
 /* Implement the detach target_ops method.  */
 
 static int
-lynx_detach (int pid)
+lynx_detach (process_info *process)
 {
-  ptid_t ptid = lynx_ptid_t (pid, 0);
-  struct process_info *process;
-
-  process = find_process_pid (pid);
-  if (process == NULL)
-    return -1;
+  ptid_t ptid = lynx_ptid_t (process->pid, 0);
 
   lynx_ptrace (PTRACE_DETACH, ptid, 0, 0, 0);
   the_target->mourn (process);
@@ -572,7 +567,7 @@ lynx_mourn (struct process_info *proc)
 /* Implement the join target_ops method.  */
 
 static void
-lynx_join (int pid)
+lynx_join (process_info *proc)
 {
   /* The PTRACE_DETACH is sufficient to detach from the process.
      So no need to do anything extra.  */
index 236e555714e34a3bf2db6b844eb2320af6f5b741..05ab6fc4edf9d44b667cd1a896586bc4d8e99deb 100644 (file)
@@ -408,9 +408,9 @@ nto_kill (int pid)
 /* Detach from process PID.  */
 
 static int
-nto_detach (int pid)
+nto_detach (process_info *proc)
 {
-  TRACE ("%s %d\n", __func__, pid);
+  TRACE ("%s %d\n", __func__, proc->pid);
   do_detach ();
   return 0;
 }
index bf6302ba2d18f94e3276fd2539eeed2bc0154729..b35015b7bfd3e0ed1536eddcf642611abdd6e9c9 100644 (file)
@@ -1255,7 +1255,7 @@ handle_detach (char *own_buf)
 
   fprintf (stderr, "Detaching from process %d\n", process->pid);
   stop_tracing ();
-  if (detach_inferior (process->pid) != 0)
+  if (detach_inferior (process) != 0)
     write_enn (own_buf);
   else
     {
@@ -1281,7 +1281,7 @@ handle_detach (char *own_buf)
          /* If we are attached, then we can exit.  Otherwise, we
             need to hang around doing nothing, until the child is
             gone.  */
-         join_inferior (process->pid);
+         join_inferior (process);
          exit (0);
        }
     }
@@ -3526,7 +3526,7 @@ detach_or_kill_for_exit (void)
     int pid = process->pid;
 
     if (process->attached)
-      detach_inferior (pid);
+      detach_inferior (process);
     else
       kill_inferior (pid);
 
index e9fc6e7beb4489bf450a6a977a51659f4b3f3753..c2a8734f680d849b6f3de1b67dec796988082159 100644 (file)
@@ -348,13 +348,9 @@ spu_kill (int pid)
 
 /* Detach from inferior process.  */
 static int
-spu_detach (int pid)
+spu_detach (process_info *process)
 {
-  struct process_info *process = find_process_pid (pid);
-  if (process == NULL)
-    return -1;
-
-  ptrace (PTRACE_DETACH, pid, 0, 0);
+  ptrace (PTRACE_DETACH, process->pid, 0, 0);
 
   clear_inferiors ();
   remove_process (process);
@@ -368,12 +364,12 @@ spu_mourn (struct process_info *process)
 }
 
 static void
-spu_join (int pid)
+spu_join (process_info *proc)
 {
   int status, ret;
 
   do {
-    ret = waitpid (pid, &status, 0);
+    ret = waitpid (proc->pid, &status, 0);
     if (WIFEXITED (status) || WIFSIGNALED (status))
       break;
   } while (ret != -1 || errno != ECHILD);
index 25accd2207508a2527db0c7ff46bdad8ebb6dac3..7f594855803ad10f38970f0fe695450bd9c55f63 100644 (file)
@@ -94,17 +94,18 @@ struct target_ops
 
   int (*kill) (int pid);
 
-  /* Detach from inferior PID. Return -1 on failure, and 0 on
+  /* Detach from process PROC.  Return -1 on failure, and 0 on
      success.  */
 
-  int (*detach) (int pid);
+  int (*detach) (process_info *proc);
 
   /* The inferior process has died.  Do what is right.  */
 
   void (*mourn) (struct process_info *proc);
 
-  /* Wait for inferior PID to exit.  */
-  void (*join) (int pid);
+  /* Wait for process PROC to exit.  */
+
+  void (*join) (process_info *proc);
 
   /* Return 1 iff the thread with process ID PID is alive.  */
 
@@ -517,8 +518,8 @@ int kill_inferior (int);
        (*the_target->handle_new_gdb_connection) ();     \
     } while (0)
 
-#define detach_inferior(pid) \
-  (*the_target->detach) (pid)
+#define detach_inferior(proc) \
+  (*the_target->detach) (proc)
 
 #define mythread_alive(pid) \
   (*the_target->thread_alive) (pid)
@@ -529,8 +530,8 @@ int kill_inferior (int);
 #define store_inferior_registers(regcache, regno) \
   (*the_target->store_registers) (regcache, regno)
 
-#define join_inferior(pid) \
-  (*the_target->join) (pid)
+#define join_inferior(proc) \
+  (*the_target->join) (proc)
 
 #define target_supports_non_stop() \
   (the_target->supports_non_stop ? (*the_target->supports_non_stop ) () : 0)
index 8a20972bd4ecd1b49694641a9e5dc01da64ae3f0..17729a83cc63345d1faefb54b78fda635ae9cc0b 100644 (file)
@@ -834,11 +834,11 @@ win32_kill (int pid)
   return 0;
 }
 
-/* Detach from inferior PID.  */
+/* Implementation of target_ops::detach.  */
+
 static int
-win32_detach (int pid)
+win32_detach (process_info *process)
 {
-  struct process_info *process;
   winapi_DebugActiveProcessStop DebugActiveProcessStop = NULL;
   winapi_DebugSetProcessKillOnExit DebugSetProcessKillOnExit = NULL;
 #ifdef _WIN32_WCE
@@ -865,7 +865,6 @@ win32_detach (int pid)
     return -1;
 
   DebugSetProcessKillOnExit (FALSE);
-  process = find_process_pid (pid);
   remove_process (process);
 
   win32_clear_inferiors ();
@@ -878,11 +877,12 @@ win32_mourn (struct process_info *process)
   remove_process (process);
 }
 
-/* Wait for inferiors to end.  */
+/* Implementation of target_ops::join.  */
+
 static void
-win32_join (int pid)
+win32_join (process_info *proc)
 {
-  HANDLE h = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
+  HANDLE h = OpenProcess (PROCESS_ALL_ACCESS, FALSE, proc->pid);
   if (h != NULL)
     {
       WaitForSingleObject (h, INFINITE);