From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1225 invoked by alias); 11 Oct 2013 16:46:28 -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 1216 invoked by uid 89); 11 Oct 2013 16:46:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 11 Oct 2013 16:46:27 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1VUfr6-0007G6-7Q from Luis_Gustavo@mentor.com ; Fri, 11 Oct 2013 09:46:24 -0700 Received: from NA1-MAIL.mgc.mentorg.com ([147.34.98.181]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 11 Oct 2013 09:46:24 -0700 Received: from [172.30.8.57] ([172.30.8.57]) by NA1-MAIL.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 11 Oct 2013 09:46:23 -0700 Message-ID: <52582B57.8090006@codesourcery.com> Date: Fri, 11 Oct 2013 16:46:00 -0000 From: Luis Machado Reply-To: lgustavo@codesourcery.com User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.0 MIME-Version: 1.0 To: Jan Kratochvil CC: "'gdb-patches@sourceware.org'" Subject: Re: [PATCH] Fix calling gcore when gdb is not in $PATH. References: <525806C8.8040108@codesourcery.com> <20131011143145.GA1517@host2.jankratochvil.net> <52580F4B.8050306@codesourcery.com> In-Reply-To: <52580F4B.8050306@codesourcery.com> Content-Type: multipart/mixed; boundary="------------050809010008070205090509" X-IsSubscribed: yes X-SW-Source: 2013-10/txt/msg00391.txt.bz2 This is a multi-part message in MIME format. --------------050809010008070205090509 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1297 On 10/11/2013 11:46 AM, Luis Machado wrote: > On 10/11/2013 11:31 AM, Jan Kratochvil wrote: >> On Fri, 11 Oct 2013 16:10:16 +0200, Luis Machado wrote: >>> --- a/gdb/gcore.in >>> +++ b/gdb/gcore.in >>> @@ -51,7 +51,7 @@ for pid in $* >>> do >>> # `>> # available but not accessible as GDB would get stopped on >>> SIGTTIN. >>> - @GDB_TRANSFORM_NAME@ >> + "$(dirname "$0")"/@GDB_TRANSFORM_NAME@ > >> I have only some concern if $0 does not contain a directory name. >> Then `dirname basename` will be . and gdb -> ./gdb will be a >> regression as >> ./gdb will typically not be found. >> >> For example if you run: >> $ sh gcore foo >> then sh (or bash) executes /usr/bin/gcore but $0 is still just "gcore". >> >> It IMO even corresponds to the sh $0 POSIX description ("command_file"): >> http://pubs.opengroup.org/onlinepubs/007908799/xcu/sh.html > > > Right. That situation can indeed happen. Though it looks a little > awkward to call something in your path like that. > > I suppose we can extend the check to cover that case as well. Let me go > back to the drawing board. Is this one more acceptable (though slightly less portable)? Regards, Luis --------------050809010008070205090509 Content-Type: text/x-patch; name="gcore.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gcore.diff" Content-length: 1271 2013-10-11 Luis Machado * gcore.in: Call gdb using the full path to the gcore script. diff --git a/gdb/gcore.in b/gdb/gcore.in index 9c5b14d..dc6a8f9 100644 --- a/gdb/gcore.in +++ b/gdb/gcore.in @@ -49,9 +49,26 @@ rc=0 # Loop through pids for pid in $* do +# Attempt to fetch the absolute path to the gcore script that was +# called. +binary_path=`dirname "$0"` + + if test "x$binary_path" = x. ; then + # We got "." back as a path. This means the user executed + # the gcore script locally (i.e. ./gcore) or called the + # script via a shell interpreter (i.e. sh gcore). We use + # the "which" command to locate the real path of the gcore + # script, disambiguating this situation. + binary_path_from_env=`which "$0"` + binary_path=`dirname $binary_path_from_env` + fi + + # Add a slash to the path. + binary_path="$binary_path/" + # `