From patchwork Wed Apr 1 11:22:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 5953 Received: (qmail 114142 invoked by alias); 1 Apr 2015 11:39:25 -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 114133 invoked by uid 89); 1 Apr 2015 11:39:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham 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; Wed, 01 Apr 2015 11:39:23 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t31BMYfk004894 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 1 Apr 2015 07:22:34 -0400 Received: from blade.nx (ovpn-116-118.ams2.redhat.com [10.36.116.118]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t31BMXS9026079 for ; Wed, 1 Apr 2015 07:22:34 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id 259E9264113 for ; Wed, 1 Apr 2015 12:22:32 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Subject: [PATCH 7/7] Access executable from remote system when first inferior appears Date: Wed, 1 Apr 2015 12:22:21 +0100 Message-Id: <1427887341-31819-8-git-send-email-gbenson@redhat.com> In-Reply-To: <1427887341-31819-1-git-send-email-gbenson@redhat.com> References: <1427887341-31819-1-git-send-email-gbenson@redhat.com> X-IsSubscribed: yes This commit modifies remote_add_inferior to take an extra argument try_open_exec. If this is nonzero, remote_add_inferior will attempt to open this inferior's executable as the main executable if no main executable is open already. Callers are updated appropriately. One testcase required updating as a result of this commit. The test checked that GDB's "info files" command does not crash if no main executable is open, and relied on GDB's inability to access the main executable over the remote protocol. The test was updated to inhibit this new behavior. gdb/ChangeLog: * remote.c (remote_add_inferior): New argument try_open_exec. If nonzero, attempt to open the inferior's executable file as the main executable if no main executable is open already. All callers updated. gdb/testsuite/ChangeLog: * gdb.server/server-exec-info.exp: Inhibit GDB from accessing the main executable over the remote protocol. --- gdb/ChangeLog | 7 +++++++ gdb/remote.c | 18 +++++++++++++----- gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.server/server-exec-info.exp | 1 + 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index a307e68..642bde1 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1516,10 +1516,13 @@ remote_query_attached (int pid) inferior. If ATTACHED is 1, then we had just attached to this inferior. If it is 0, then we just created this inferior. If it is -1, then try querying the remote stub to find out if it had - attached to the inferior or not. */ + attached to the inferior or not. If TRY_OPEN_EXEC is true then + attempt to open this inferior's executable as the main executable + if no main executable is open already. */ static struct inferior * -remote_add_inferior (int fake_pid_p, int pid, int attached) +remote_add_inferior (int fake_pid_p, int pid, int attached, + int try_open_exec) { struct inferior *inf; @@ -1553,6 +1556,11 @@ remote_add_inferior (int fake_pid_p, int pid, int attached) inf->attach_flag = attached; inf->fake_pid_p = fake_pid_p; + /* 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) + exec_file_locate_attach (pid, 1); + return inf; } @@ -1643,7 +1651,7 @@ remote_notice_new_inferior (ptid_t currthread, int running) int fake_pid_p = !remote_multi_process_p (rs); inf = remote_add_inferior (fake_pid_p, - ptid_get_pid (currthread), -1); + ptid_get_pid (currthread), -1, 1); } /* This is really a new thread. Add it. */ @@ -3413,7 +3421,7 @@ add_current_inferior_and_thread (char *wait_status) fake_pid_p = 1; } - remote_add_inferior (fake_pid_p, ptid_get_pid (inferior_ptid), -1); + remote_add_inferior (fake_pid_p, ptid_get_pid (inferior_ptid), -1, 1); /* Add the main thread. */ add_thread_silent (inferior_ptid); @@ -4539,7 +4547,7 @@ extended_remote_attach (struct target_ops *target, const char *args, target_pid_to_str (pid_to_ptid (pid))); } - set_current_inferior (remote_add_inferior (0, pid, 1)); + set_current_inferior (remote_add_inferior (0, pid, 1, 0)); inferior_ptid = pid_to_ptid (pid); diff --git a/gdb/testsuite/gdb.server/server-exec-info.exp b/gdb/testsuite/gdb.server/server-exec-info.exp index ca5f5ca..c12554a 100644 --- a/gdb/testsuite/gdb.server/server-exec-info.exp +++ b/gdb/testsuite/gdb.server/server-exec-info.exp @@ -27,6 +27,7 @@ if [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] { return -1 } +gdb_test_no_output "set remote pid-to-exec-file-packet off" gdb_test "file" ".*" "file" \ {Discard symbol table from `.*'\? \(y or n\) } "y" gdbserver_run ""