From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 80079 invoked by alias); 12 Feb 2018 04:18:41 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 80069 invoked by uid 89); 12 Feb 2018 04:18:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Feb 2018 04:18:39 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id w1C4IR6g015275 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Feb 2018 23:18:32 -0500 Received: from [10.0.0.11] (192-222-251-162.qc.cable.ebox.net [192.222.251.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 8408E1E093; Sun, 11 Feb 2018 23:18:27 -0500 (EST) Subject: Re: [PATCH 2/2] Make gdbserver work with filename-only binaries To: Sergio Durigan Junior , GDB Patches Cc: Simon Marchi References: <20180210014241.19278-1-sergiodj@redhat.com> <20180210014241.19278-3-sergiodj@redhat.com> From: Simon Marchi Message-ID: Date: Mon, 12 Feb 2018 04:18:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180210014241.19278-3-sergiodj@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Mon, 12 Feb 2018 04:18:27 +0000 X-IsSubscribed: yes X-SW-Source: 2018-02/txt/msg00165.txt.bz2 On 2018-02-09 08:42 PM, Sergio Durigan Junior wrote: > Simon mentioned on IRC that, after the startup-with-shell feature has > been implemented on gdbserver, it is not possible to specify a > filename-only binary, like: > > $ gdbserver :1234 a.out > /bin/bash: line 0: exec: a.out: not found > During startup program exited with code 127. > Exiting > > This happens on systems where the current directory "." is not listed > in the PATH environment variable. Although include "." in the PATH > variable is a possible workaround, this can be considered a regression > because before startup-with-shell it was possible to use only the > filename (due to reason that gdbserver used "exec*" directly). > > The idea of the patch is to perform a call to "gdb_abspath" and adjust > the PROGRAM_NAME variable before the call to "create_inferior". This > adjustment will consist of tilde-expansion or prefixing PROGRAM_NAME > using the CURRENT_DIRECTORY (a variable that was specific to GDB, but > has been put into common/common-defs.h and now is set/used by > gdbserver as well), thus transforming PROGRAM_NAME in an absolute > path. > > This mimicks the behaviour seen on GDB (look at "openp" and > "attach_inferior", for example). Now, we'll always execute the binary > using its full path on gdbserver. > > I am also submitting a testcase which exercises the scenario described > above. Because the test requires copying (and deleting) files > locally, I decided to restrict its execution to non-remote > targets/hosts. I've also had to do a minor adjustment on > gdb.server/non-existing-program.exp's regexp in order to match the > correct error message. Hi Sergio, The behavior is still different than for GDB (and previous gdbservers), in the case where you specify a filename-only binary that is found in PATH. For example, try "gdb ls" and/or "gdbserver ls". The expected behavior is to search for a file with this name in the current directory, and if there isn't one, to search in the PATH. This is what openp does when OPF_TRY_CWD_FIRST is passed. Bringing openp to gdbserver may not be easy nor desirable, since it supports some concepts that don't exist in gdbserver (like $-variables). Also, we would not really want to open the file in this case, only see if it exists. I didn't think this through completely, but maybe we could do something simpler, if the program_name doesn't contain a directory separator and the file exists in the current working directory, we add "./" in front of it when passing it to the shell? I think all three use cases would work: - gdbserver :1234 foo (foo in current directory) - gdbserver :1234 foo (foo in PATH) - gdbserver :1234 ./foo Simon