From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 113922 invoked by alias); 16 Jun 2016 23:32:54 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 113910 invoked by uid 89); 16 Jun 2016 23:32:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=*ops, inferior_ptid, pid_t, ptid_get_pid X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 16 Jun 2016 23:32:52 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 22D641555A for ; Thu, 16 Jun 2016 23:32:51 +0000 (UTC) Received: from cascais.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5GNWmPX025383 for ; Thu, 16 Jun 2016 19:32:50 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v4 1/3] Factor out "Detaching from program" message printing Date: Thu, 16 Jun 2016 23:32:00 -0000 Message-Id: <1466119968-15171-2-git-send-email-palves@redhat.com> In-Reply-To: <1466119968-15171-1-git-send-email-palves@redhat.com> References: <1466119968-15171-1-git-send-email-palves@redhat.com> X-SW-Source: 2016-06/txt/msg00279.txt.bz2 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: yyyy-mm-dd 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. --- gdb/darwin-nat.c | 10 +--------- gdb/inf-ptrace.c | 10 +--------- gdb/nto-procfs.c | 11 ++--------- gdb/remote.c | 10 +--------- gdb/target.c | 22 ++++++++++++++++++++++ gdb/target.h | 5 +++++ 6 files changed, 32 insertions(+), 36 deletions(-) diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index 54c430f..590c2ad 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 329d8fb..dd11043 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 eb7dcfe..f49453d 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 1f0d67c..48d914e 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 c0ce46d..3aa9500 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -3212,6 +3212,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 6b5b6e0..fc317e3 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 -- 2.5.5