From: Pedro Alves Date: Fri, 1 Jul 2016 10:16:32 +0000 (+0100) Subject: Factor out "Detaching from program" message printing X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0f48b757071509040d800ff9f7c8726e5828bd1a;p=binutils-gdb.git Factor out "Detaching from program" message printing 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 * 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. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 3f88f7b1ef1..53e3951afe6 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2016-07-01 Pedro Alves + + * 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 PR python/20129: diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index 54c430f76b7..590c2ad04f1 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -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) diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c index 329d8fb2d8c..dd11043a968 100644 --- a/gdb/inf-ptrace.c +++ b/gdb/inf-ptrace.c @@ -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); diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c index eb7dcfeb089..f49453d733b 100644 --- a/gdb/nto-procfs.c +++ b/gdb/nto-procfs.c @@ -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); diff --git a/gdb/remote.c b/gdb/remote.c index 501f3c63bd4..e4b2095a40d 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -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); diff --git a/gdb/target.c b/gdb/target.c index bb86adf9b70..d3fc35ba145 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -3251,6 +3251,28 @@ find_target_at (enum strata stratum) } + +/* 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 diff --git a/gdb/target.h b/gdb/target.h index 6b5b6e0c1c6..fc317e37d51 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -1302,6 +1302,11 @@ extern struct target_ops *find_run_target (void); #define target_post_attach(pid) \ (*current_target.to_post_attach) (¤t_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