From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 942723858408; Thu, 6 Jan 2022 15:57:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 942723858408 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Introduce target_announce_attach X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 10a85f29c74ab562db622cfc4f58997e859c6ed6 X-Git-Newrev: bc521517b7058a231a08bf8f3deae7cd41cd62d7 Message-Id: <20220106155758.942723858408@sourceware.org> Date: Thu, 6 Jan 2022 15:57:58 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Jan 2022 15:57:58 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dbc521517b705= 8a231a08bf8f3deae7cd41cd62d7 commit bc521517b7058a231a08bf8f3deae7cd41cd62d7 Author: Tom Tromey Date: Sun Dec 26 21:49:48 2021 -0700 Introduce target_announce_attach =20 This introduces target_announce_attach, by analog with target_announce_detach. Then it converts existing targets to use this, rather than emitting their own output by hand. Diff: --- gdb/darwin-nat.c | 12 +----------- gdb/gnu-nat.c | 11 +---------- gdb/inf-ptrace.c | 12 +----------- gdb/nto-procfs.c | 11 +---------- gdb/procfs.c | 14 +------------- gdb/remote.c | 12 +----------- gdb/target.c | 18 ++++++++++++++++++ gdb/target.h | 5 +++++ gdb/windows-nat.c | 12 +----------- 9 files changed, 30 insertions(+), 77 deletions(-) diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index 98720b330aa..e9c24dcc5dc 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -2002,17 +2002,7 @@ darwin_nat_target::attach (const char *args, int fro= m_tty) if (pid =3D=3D getpid ()) /* Trying to masturbate? */ error (_("I refuse to debug myself!")); =20 - if (from_tty) - { - const char *exec_file =3D get_exec_file (0); - - if (exec_file) - printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file, - target_pid_to_str (ptid_t (pid)).c_str ()); - else - printf_unfiltered (_("Attaching to %s\n"), - target_pid_to_str (ptid_t (pid)).c_str ()); - } + target_announce_attach (from_tty, pid); =20 if (pid =3D=3D 0 || ::kill (pid, 0) < 0) error (_("Can't attach to process %d: %s (%d)"), diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c index b39dfaf009c..f99aeb19347 100644 --- a/gdb/gnu-nat.c +++ b/gdb/gnu-nat.c @@ -2170,16 +2170,7 @@ gnu_nat_target::attach (const char *args, int from_t= ty) if (pid =3D=3D getpid ()) /* Trying to masturbate? */ error (_("I refuse to debug myself!")); =20 - if (from_tty) - { - const char *exec_file =3D get_exec_file (0); - - if (exec_file) - printf_unfiltered ("Attaching to program `%s', pid %d\n", - exec_file, pid); - else - printf_unfiltered ("Attaching to pid %d\n", pid); - } + target_announce_attach (from_tty, pid); =20 inf_debug (inf, "attaching to pid: %d", pid); =20 diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c index 521b41c6ea6..6e4706a3d20 100644 --- a/gdb/inf-ptrace.c +++ b/gdb/inf-ptrace.c @@ -148,17 +148,7 @@ inf_ptrace_target::attach (const char *args, int from_= tty) unpusher.reset (this); } =20 - if (from_tty) - { - const char *exec_file =3D get_exec_file (0); - - if (exec_file) - printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file, - target_pid_to_str (ptid_t (pid)).c_str ()); - else - printf_unfiltered (_("Attaching to %s\n"), - target_pid_to_str (ptid_t (pid)).c_str ()); - } + target_announce_attach (from_tty, pid); =20 #ifdef PT_ATTACH errno =3D 0; diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c index bf869df1dab..da0feaedff9 100644 --- a/gdb/nto-procfs.c +++ b/gdb/nto-procfs.c @@ -701,17 +701,8 @@ nto_procfs_target::attach (const char *args, int from_= tty) if (pid =3D=3D getpid ()) error (_("Attaching GDB to itself is not a good idea...")); =20 - if (from_tty) - { - const char *exec_file =3D get_exec_file (0); + target_announce_attach (from_tty, pid); =20 - if (exec_file) - printf_unfiltered ("Attaching to program `%s', %s\n", exec_file, - target_pid_to_str (ptid_t (pid)).c_str ()); - else - printf_unfiltered ("Attaching to %s\n", - target_pid_to_str (ptid_t (pid)).c_str ()); - } ptid_t ptid =3D do_attach (ptid_t (pid)); inf =3D current_inferior (); inferior_appeared (inf, pid); diff --git a/gdb/procfs.c b/gdb/procfs.c index 201e37c3a4b..ddc8623b1e1 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -1775,19 +1775,7 @@ procfs_target::attach (const char *args, int from_tt= y) unpusher.reset (this); } =20 - if (from_tty) - { - const char *exec_file =3D get_exec_file (0); - - if (exec_file) - printf_filtered (_("Attaching to program `%s', %s\n"), - exec_file, target_pid_to_str (ptid_t (pid)).c_str ()); - else - printf_filtered (_("Attaching to %s\n"), - target_pid_to_str (ptid_t (pid)).c_str ()); - - fflush (stdout); - } + target_announce_attach (from_tty, pid); =20 do_attach (ptid_t (pid)); =20 diff --git a/gdb/remote.c b/gdb/remote.c index 98003d39918..290edd07cd1 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -6115,17 +6115,7 @@ extended_remote_target::attach (const char *args, in= t from_tty) if (packet_support (PACKET_vAttach) =3D=3D PACKET_DISABLE) error (_("This target does not support attaching to a process")); =20 - if (from_tty) - { - const char *exec_file =3D get_exec_file (0); - - if (exec_file) - printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file, - target_pid_to_str (ptid_t (pid)).c_str ()); - else - printf_unfiltered (_("Attaching to %s\n"), - target_pid_to_str (ptid_t (pid)).c_str ()); - } + target_announce_attach (from_tty, pid); =20 xsnprintf (rs->buf.data (), get_remote_packet_size (), "vAttach;%x", pid= ); putpkt (rs->buf); diff --git a/gdb/target.c b/gdb/target.c index 1a072297fa6..a48845d6add 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -3637,6 +3637,24 @@ target_announce_detach (int from_tty) target_pid_to_str (ptid_t (pid)).c_str ()); } =20 +/* See target.h */ + +void +target_announce_attach (int from_tty, int pid) +{ + if (!from_tty) + return; + + const char *exec_file =3D get_exec_file (0); + + if (exec_file) + printf_unfiltered ("Attaching to program: %s, %s\n", exec_file, + target_pid_to_str (ptid_t (pid)).c_str ()); + else + printf_unfiltered ("Attaching to %s\n", + target_pid_to_str (ptid_t (pid)).c_str ()); +} + /* The inferior process has died. Long live the inferior! */ =20 void diff --git a/gdb/target.h b/gdb/target.h index c629b9ba3fb..1ac7a4554dc 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -1448,6 +1448,11 @@ extern bool target_attach_no_wait (); =20 extern void target_post_attach (int pid); =20 +/* Display a message indicating we're about to attach to a given + process. */ + +extern void target_announce_attach (int from_tty, int pid); + /* Display a message indicating we're about to detach from the current inferior process. */ =20 diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 47760b7b8b8..c85f7c0d652 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -1929,17 +1929,7 @@ windows_nat_target::attach (const char *args, int fr= om_tty) =20 DebugSetProcessKillOnExit (FALSE); =20 - if (from_tty) - { - const char *exec_file =3D get_exec_file (0); - - if (exec_file) - printf_unfiltered ("Attaching to program `%s', %s\n", exec_file, - target_pid_to_str (ptid_t (pid)).c_str ()); - else - printf_unfiltered ("Attaching to %s\n", - target_pid_to_str (ptid_t (pid)).c_str ()); - } + target_announce_attach (from_tty, pid); =20 #ifdef __x86_64__ HANDLE h =3D OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, pid);