From patchwork Tue May 5 11:02:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 6566 Received: (qmail 10001 invoked by alias); 5 May 2015 11:02:20 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 9925 invoked by uid 89); 5 May 2015 11:02:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 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; Tue, 05 May 2015 11:02:13 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t45B298B009988 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 5 May 2015 07:02:09 -0400 Received: from blade.nx (ovpn-116-21.ams2.redhat.com [10.36.116.21]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t45B28ni001137; Tue, 5 May 2015 07:02:09 -0400 Received: by blade.nx (Postfix, from userid 1000) id 9445E263BEC; Tue, 5 May 2015 12:02:07 +0100 (BST) Date: Tue, 5 May 2015 12:02:07 +0100 From: Gary Benson To: Philippe Waroquiers Cc: gdb-patches@sourceware.org Subject: Re: qXfer:exec-file:read and non multiprocess target Message-ID: <20150505110207.GA17684@blade.nx> References: <1430560118.11263.9.camel@soleil> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1430560118.11263.9.camel@soleil> X-IsSubscribed: yes Philippe Waroquiers wrote: > I am busy adding qXfer:exec-file:read to the Valgrind gdbserver. > > Even if Valgrind reports it supports qXfer:exec-file, GDB does > not query it. This is due to the fact that GDB does not query > the exec-file when the pid is a fake pid, which is the case for > Valgrind, as the target command to use is: > target remote | vgdb > > The following change in remote.c ensures GDB queries the > remote exec-file: > 1561,1562c1561,1562 > < if (try_open_exec && !fake_pid_p && get_exec_file (0) == NULL) > < exec_file_locate_attach (pid, 1); > --- > > if (try_open_exec && get_exec_file (0) == NULL) > > exec_file_locate_attach (fake_pid_p ? 0 : pid, 1); > > With that change, GDB can use a Valgrind target without having > to specify the exec file. The idea is that when the stub gets > a pid 0 in this request, it replies with the exec file of the > current process. The PID is fake because vgdb does not support multiprocess extensions. I don't like sending a fake/zero PID over the wire, but how about I change qXfer:exec-file:read to send a NULL annex if the remote does not have multiprocess extensions? Can you make your side work with the patch inlined below? If so I'll tidy and document it and submit it for review. Thanks, Gary diff --git a/gdb/remote.c b/gdb/remote.c index 099ddbb..42d990a 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1558,7 +1558,7 @@ /* If no main executable is currently open then attempt to open the file that was executed to create this inferior. */ - if (try_open_exec && !fake_pid_p && get_exec_file (0) == NULL) + if (try_open_exec && get_exec_file (0) == NULL) exec_file_locate_attach (pid, 1); return inf; @@ -11710,7 +11710,7 @@ remote_pid_to_exec_file (struct target_ops *self, int pid) { static char *filename = NULL; - char annex[9]; + char *annex = NULL; if (packet_support (PACKET_qXfer_exec_file) != PACKET_ENABLE) return NULL; @@ -11718,7 +11718,14 @@ if (filename != NULL) xfree (filename); - xsnprintf (annex, sizeof (annex), "%x", pid); + if (remote_multi_process_p (get_remote_state ())) + { + const int annex_size = 9; + + annex = alloca (annex_size); + xsnprintf (annex, annex_size, "%x", pid); + } + filename = target_read_stralloc (¤t_target, TARGET_OBJECT_EXEC_FILE, annex);