Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 2/2] Use target_announce_detach in more targets
Date: Wed,  5 Jan 2022 10:59:16 -0700	[thread overview]
Message-ID: <20220105175916.2969966-3-tom@tromey.com> (raw)
In-Reply-To: <20220105175916.2969966-1-tom@tromey.com>

target_announce_detach was added in commit 0f48b757 ("Factor out
"Detaching from program" message printing").  There, Pedro wrote:

    (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.)

It seems to me that the differences aren't very big, and in some cases
other targets handled the output a bit more nicely.  In particular,
some targets will print a different message when exec_file==NULL,
rather than printing the same output with an empty string as
exec_file.

This patch incorporates the nicer output into target_announce_detach,
then changes the remaining ports to use this function.
---
 gdb/gnu-nat.c     | 11 +----------
 gdb/procfs.c      | 14 +-------------
 gdb/target.c      | 13 +++++++------
 gdb/windows-nat.c | 10 ++--------
 4 files changed, 11 insertions(+), 37 deletions(-)

diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
index ad870c94d63..b6bccd8b4b7 100644
--- a/gdb/gnu-nat.c
+++ b/gdb/gnu-nat.c
@@ -2215,16 +2215,7 @@ gnu_nat_target::attach (const char *args, int from_tty)
 void
 gnu_nat_target::detach (inferior *inf, int from_tty)
 {
-  if (from_tty)
-    {
-      const char *exec_file = get_exec_file (0);
-
-      if (exec_file)
-	printf_unfiltered ("Detaching from program `%s' pid %d\n",
-			   exec_file, gnu_current_inf->pid);
-      else
-	printf_unfiltered ("Detaching from pid %d\n", gnu_current_inf->pid);
-    }
+  target_announce_detach (from_tty);
 
   inf_detach (gnu_current_inf);
 
diff --git a/gdb/procfs.c b/gdb/procfs.c
index ddc8623b1e1..840201d1897 100644
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -1786,19 +1786,7 @@ procfs_target::attach (const char *args, int from_tty)
 void
 procfs_target::detach (inferior *inf, int from_tty)
 {
-  int pid = inferior_ptid.pid ();
-
-  if (from_tty)
-    {
-      const char *exec_file;
-
-      exec_file = get_exec_file (0);
-      if (exec_file == NULL)
-	exec_file = "";
-
-      printf_filtered (_("Detaching from program: %s, %s\n"), exec_file,
-		       target_pid_to_str (ptid_t (pid)).c_str ());
-    }
+  target_announce_detach (from_tty);
 
   do_detach ();
 
diff --git a/gdb/target.c b/gdb/target.c
index 65b98c5a9b8..90a279b2902 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -3628,13 +3628,14 @@ target_announce_detach (int from_tty)
   if (!from_tty)
     return;
 
-  exec_file = get_exec_file (0);
-  if (exec_file == NULL)
-    exec_file = "";
-
   pid = inferior_ptid.pid ();
-  printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file,
-		     target_pid_to_str (ptid_t (pid)).c_str ());
+  exec_file = get_exec_file (0);
+  if (exec_file == nullptr)
+    printf_unfiltered ("Detaching from pid %s\n",
+		       target_pid_to_str (ptid_t (pid)).c_str ());
+  else
+    printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file,
+		       target_pid_to_str (ptid_t (pid)).c_str ());
 }
 
 /* See target.h  */
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 89084acabaa..0faf138c0c7 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -1965,14 +1965,8 @@ windows_nat_target::detach (inferior *inf, int from_tty)
     }
   DebugSetProcessKillOnExit (FALSE);
 
-  if (detached && from_tty)
-    {
-      const char *exec_file = get_exec_file (0);
-      if (exec_file == 0)
-	exec_file = "";
-      printf_unfiltered ("Detaching from program: %s, Pid %u\n", exec_file,
-			 (unsigned) current_event.dwProcessId);
-    }
+  if (detached)
+    target_announce_detach (from_tty);
 
   x86_cleanup_dregs ();
   switch_to_no_thread ();
-- 
2.31.1


  parent reply	other threads:[~2022-01-05 17:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-05 17:59 [PATCH 0/2] Unify target announce and detach messages Tom Tromey
2022-01-05 17:59 ` [PATCH 1/2] Introduce target_announce_attach Tom Tromey
2022-01-08 15:07   ` Lancelot SIX via Gdb-patches
2022-01-08 16:47     ` Tom Tromey
2022-01-05 17:59 ` Tom Tromey [this message]
2022-01-05 18:47 ` [PATCH 0/2] Unify target announce and detach messages John Baldwin
2022-01-08 11:16 ` Joel Brobecker via Gdb-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220105175916.2969966-3-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox