From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 0N+HIqHc1WHtWAAAWB0awg (envelope-from ) for ; Wed, 05 Jan 2022 13:00:01 -0500 Received: by simark.ca (Postfix, from userid 112) id 8B2E31EE18; Wed, 5 Jan 2022 13:00:01 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id BA8671EAA4 for ; Wed, 5 Jan 2022 13:00:00 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 67C64385801B for ; Wed, 5 Jan 2022 18:00:00 +0000 (GMT) Received: from alt-proxy28.mail.unifiedlayer.com (alt-proxy28.mail.unifiedlayer.com [74.220.216.123]) by sourceware.org (Postfix) with ESMTPS id DA0903858410 for ; Wed, 5 Jan 2022 17:59:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DA0903858410 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw14.mail.unifiedlayer.com (unknown [10.0.90.129]) by progateway1.mail.pro1.eigbox.com (Postfix) with ESMTP id 7AF6010040537 for ; Wed, 5 Jan 2022 17:59:20 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id 5AZDnma8N2s5d5AZEnPaKL; Wed, 05 Jan 2022 17:59:20 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=BOh2EHcG c=1 sm=1 tr=0 ts=61d5dc78 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=DghFqjY3_ZEA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=CaFIDhoJ8zsHfYBW1UcA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=f9cDtzNo3GTLGdP1eEPRhA3sx1tYBq6VXQUF/LBdV3c=; b=sngjweVUL2Ovm2v7PTy28vlQZE ZHWZIaLyi9a/geHX8EXuh5Sf9f9Sr4/J+79ZsRglap4TT2r1dJtbIjZKwZ80JldkF+pQf1F9GapvO jUQoa9jWsD9JpSCy7W/cOKVpT; Received: from 75-166-134-30.hlrn.qwest.net ([75.166.134.30]:52060 helo=prentzel.Home) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n5AZD-002Z8v-7R; Wed, 05 Jan 2022 10:59:19 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 1/2] Introduce target_announce_attach Date: Wed, 5 Jan 2022 10:59:15 -0700 Message-Id: <20220105175916.2969966-2-tom@tromey.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220105175916.2969966-1-tom@tromey.com> References: <20220105175916.2969966-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.134.30 X-Source-L: No X-Exim-ID: 1n5AZD-002Z8v-7R X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-134-30.hlrn.qwest.net (prentzel.Home) [75.166.134.30]:52060 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Tromey Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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. --- 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 from_tty) if (pid == getpid ()) /* Trying to masturbate? */ error (_("I refuse to debug myself!")); - if (from_tty) - { - const char *exec_file = 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); if (pid == 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 4b22e21bb8e..ad870c94d63 100644 --- a/gdb/gnu-nat.c +++ b/gdb/gnu-nat.c @@ -2170,16 +2170,7 @@ gnu_nat_target::attach (const char *args, int from_tty) if (pid == getpid ()) /* Trying to masturbate? */ error (_("I refuse to debug myself!")); - if (from_tty) - { - const char *exec_file = 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); inf_debug (inf, "attaching to pid: %d", pid); 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); } - if (from_tty) - { - const char *exec_file = 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); #ifdef PT_ATTACH errno = 0; diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c index 7ae71d9d519..e27da7ca2d2 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 == getpid ()) error (_("Attaching GDB to itself is not a good idea...")); - if (from_tty) - { - const char *exec_file = get_exec_file (0); + target_announce_attach (from_tty, pid); - 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 = do_attach (ptid_t (pid)); inf = 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_tty) unpusher.reset (this); } - if (from_tty) - { - const char *exec_file = 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); do_attach (ptid_t (pid)); 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, int from_tty) if (packet_support (PACKET_vAttach) == PACKET_DISABLE) error (_("This target does not support attaching to a process")); - if (from_tty) - { - const char *exec_file = 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); 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 e10b295c797..65b98c5a9b8 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 ()); } +/* See target.h */ + +void +target_announce_attach (int from_tty, int pid) +{ + if (!from_tty) + return; + + const char *exec_file = 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! */ 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 (); extern void target_post_attach (int pid); +/* 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. */ diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 76332541f8e..89084acabaa 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -1932,17 +1932,7 @@ windows_nat_target::attach (const char *args, int from_tty) DebugSetProcessKillOnExit (FALSE); - if (from_tty) - { - const char *exec_file = 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); #ifdef __x86_64__ HANDLE h = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, pid); -- 2.31.1