From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16033 invoked by alias); 14 Oct 2013 12:24:26 -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 15823 invoked by uid 89); 14 Oct 2013 12:24:24 -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; Mon, 14 Oct 2013 12:24:24 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1VVhC8-0006Dt-2n from Luis_Gustavo@mentor.com ; Mon, 14 Oct 2013 05:24:20 -0700 Received: from NA1-MAIL.mgc.mentorg.com ([147.34.98.181]) by svr-orw-fem-01.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 14 Oct 2013 05:24:20 -0700 Received: from [172.30.0.4] ([172.30.0.4]) by NA1-MAIL.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 14 Oct 2013 05:24:19 -0700 Message-ID: <525BE269.9070907@codesourcery.com> Date: Mon, 14 Oct 2013 12:24: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> <52582B57.8090006@codesourcery.com> <20131011165622.GA20960@host2.jankratochvil.net> <52583B08.3010907@codesourcery.com> <20131011181008.GA2115@host2.jankratochvil.net> <525841CD.8070506@codesourcery.com> <20131011190020.GA13493@host2.jankratochvil.net> In-Reply-To: <20131011190020.GA13493@host2.jankratochvil.net> Content-Type: multipart/mixed; boundary="------------090200010901040105090506" X-IsSubscribed: yes X-SW-Source: 2013-10/txt/msg00432.txt.bz2 This is a multi-part message in MIME format. --------------090200010901040105090506 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 903 On 10/11/2013 04:00 PM, Jan Kratochvil wrote: > On Fri, 11 Oct 2013 20:22:05 +0200, Luis Machado wrote: >> Hmmm... unless there is some discrepancy between shell interpreters, >> mine (bash) does the following: > > OK, true, it works thanks to the 'which' command there. > > But then why you have there the conditional > if test "x$binary_path" = x. ; then > ? > You can run the 'which' block every time and it will work. That's true. Though i've noticed that the following gives an unexpected result... Invocation: sh gcore (with gcore living in ".") The /usr/bin/gdb binary gets picked up, because "which gcore" returns nothing even if gcore lives in ".". *sigh*. An additional check needs to be done. The attached update patch accomplishes this. It seems to cover all the scenarios. I decided to add a chunk of code to error out in case the correct GDB binary is not found. Thoughts? Luis --------------090200010901040105090506 Content-Type: text/x-patch; name="gcore.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gcore.diff" Content-length: 2042 2013-10-14 Luis Machado * gcore.in: Call GDB using the full path to the gcore script. Error out if the GDB binary is not found. diff --git a/gdb/gcore.in b/gdb/gcore.in index 9c5b14d..cbc8f06 100644 --- a/gdb/gcore.in +++ b/gdb/gcore.in @@ -43,6 +43,40 @@ then shift; shift fi +# 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). + binary_basename=`basename "$0"` + + # If the gcore script was called like "sh gcore" and the script + # lives in the current directory, "which" will not give us "gcore". + # So first we check if the script is in the current directory + # before using the output "which". + if test -f "$binary_basename" ; then + # We have a local gcore script in ".". This covers the case of + # doing "./gcore" or "sh gcore". + binary_path="." + else + # The gcore script was not found in ".", which means the script + # was called from somewhere else in $PATH. Extract the correct + # path now. + binary_path_from_env=`which "$0"` + binary_path=`dirname "$binary_path_from_env"` + fi +fi + +# Check if the GDB binary is in the expected path. If not, just +# quit with a message. +if [ ! -f "$binary_path"/@GDB_TRANSFORM_NAME@ ]; then + echo "gcore: GDB binary (${binary_path}/@GDB_TRANSFORM_NAME@) not found" + exit 1 +fi + # Initialise return code. rc=0 @@ -51,7 +85,7 @@ for pid in $* do # `