]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Factor out "Detaching from program" message printing
authorPedro Alves <palves@redhat.com>
Fri, 1 Jul 2016 10:16:32 +0000 (11:16 +0100)
committerPedro Alves <palves@redhat.com>
Fri, 1 Jul 2016 10:25:50 +0000 (11:25 +0100)
Several targets have a copy of the same code that prints

 "Detaching from program ..."

in their target_detach implementation.  Factor that out to a common
function.

(For now, I left the couple targets that print this a bit differently
alone.  Maybe this could be further pulled out into infcmd.c.  If we
did that, and those targets want to continue printing differently,
this new function could be converted to a target method.)

gdb/ChangeLog:
2016-07-01  Pedro Alves  <palves@redhat.com>

* darwin-nat.c (darwin_detach): Use target_announce_detach.
* inf-ptrace.c (inf_ptrace_detach): Likewise.
* nto-procfs.c (procfs_detach): Likewise.
* remote.c (remote_detach_1): Likewise.
* target.c (target_announce_detach): New function.
* target.h (target_announce_detach): New declaration.

gdb/ChangeLog
gdb/darwin-nat.c
gdb/inf-ptrace.c
gdb/nto-procfs.c
gdb/remote.c
gdb/target.c
gdb/target.h

index 3f88f7b1ef166ea0b2df2bbaa89219cb4f10727c..53e3951afe6e44b8bfa4a73cd41628fcb1aa333f 100644 (file)
@@ -1,3 +1,12 @@
+2016-07-01  Pedro Alves  <palves@redhat.com>
+
+       * darwin-nat.c (darwin_detach): Use target_announce_detach.
+       * inf-ptrace.c (inf_ptrace_detach): Likewise.
+       * nto-procfs.c (procfs_detach): Likewise.
+       * remote.c (remote_detach_1): Likewise.
+       * target.c (target_announce_detach): New function.
+       * target.h (target_announce_detach): New declaration.
+
 2016-06-29  Tom Tromey  <tom@tromey.com>
 
        PR python/20129:
index 54c430f76b773984c35c7cb591ee782d3a18e87a..590c2ad04f12ed085d8e141d6027e79c1139ad99 100644 (file)
@@ -1739,15 +1739,7 @@ darwin_detach (struct target_ops *ops, const char *args, int from_tty)
   int res;
 
   /* Display message.  */
-  if (from_tty)
-    {
-      char *exec_file = get_exec_file (0);
-      if (exec_file == 0)
-       exec_file = "";
-      printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file,
-                        target_pid_to_str (pid_to_ptid (pid)));
-      gdb_flush (gdb_stdout);
-    }
+  target_announce_detach (from_tty);
 
   /* If ptrace() is in use, stop the process.  */
   if (!inf->priv->no_ptrace)
index 329d8fb2d8c560c8d025c73ba90f138d27fa972d..dd11043a968ffc2a0f4564e3f09cebee6c584285 100644 (file)
@@ -240,15 +240,7 @@ inf_ptrace_detach (struct target_ops *ops, const char *args, int from_tty)
   pid_t pid = ptid_get_pid (inferior_ptid);
   int sig = 0;
 
-  if (from_tty)
-    {
-      char *exec_file = get_exec_file (0);
-      if (exec_file == 0)
-       exec_file = "";
-      printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file,
-                        target_pid_to_str (pid_to_ptid (pid)));
-      gdb_flush (gdb_stdout);
-    }
+  target_announce_detach (from_tty);
   if (args)
     sig = atoi (args);
 
index eb7dcfeb089abde9b59aee30fb50896387978765..f49453d733b27bbfd49315889825d7a7d7f7482e 100644 (file)
@@ -962,15 +962,8 @@ procfs_detach (struct target_ops *ops, const char *args, int from_tty)
   int siggnal = 0;
   int pid;
 
-  if (from_tty)
-    {
-      char *exec_file = get_exec_file (0);
-      if (exec_file == 0)
-       exec_file = "";
-      printf_unfiltered ("Detaching from program: %s %s\n",
-                        exec_file, target_pid_to_str (inferior_ptid));
-      gdb_flush (gdb_stdout);
-    }
+  target_announce_detach ();
+
   if (args)
     siggnal = atoi (args);
 
index 501f3c63bd44ba8f5ac5cef45205732c590e508a..e4b2095a40dced437613bdf22549ad58ffad6f23 100644 (file)
@@ -5134,15 +5134,7 @@ remote_detach_1 (const char *args, int from_tty)
   if (!target_has_execution)
     error (_("No process to detach from."));
 
-  if (from_tty)
-    {
-      char *exec_file = get_exec_file (0);
-      if (exec_file == NULL)
-       exec_file = "";
-      printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file,
-                        target_pid_to_str (pid_to_ptid (pid)));
-      gdb_flush (gdb_stdout);
-    }
+  target_announce_detach (from_tty);
 
   /* Tell the remote target to detach.  */
   remote_detach_pid (pid);
index bb86adf9b702313f999379198c9096adc967218f..d3fc35ba14571eccc0b8fb1d31d12a1db69f1e22 100644 (file)
@@ -3251,6 +3251,28 @@ find_target_at (enum strata stratum)
 }
 
 \f
+
+/* See target.h  */
+
+void
+target_announce_detach (int from_tty)
+{
+  pid_t pid;
+  char *exec_file;
+
+  if (!from_tty)
+    return;
+
+  exec_file = get_exec_file (0);
+  if (exec_file == NULL)
+    exec_file = "";
+
+  pid = ptid_get_pid (inferior_ptid);
+  printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file,
+                    target_pid_to_str (pid_to_ptid (pid)));
+  gdb_flush (gdb_stdout);
+}
+
 /* The inferior process has died.  Long live the inferior!  */
 
 void
index 6b5b6e0c1c671a1846008cc9d702d309f191d4c0..fc317e37d51146880d2ba303f23c978c727752d2 100644 (file)
@@ -1302,6 +1302,11 @@ extern struct target_ops *find_run_target (void);
 #define target_post_attach(pid) \
      (*current_target.to_post_attach) (&current_target, pid)
 
+/* Display a message indicating we're about to detach from the current
+   inferior process.  */
+
+extern void target_announce_detach (int from_tty);
+
 /* Takes a program previously attached to and detaches it.
    The program may resume execution (some targets do, some don't) and will
    no longer stop on signals, etc.  We better not have left any breakpoints