From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kRkEOW3hsmrKJjQAWB0awg (envelope-from ) for ; Tue, 22 Sep 2026 16:13:33 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=a5XWm7LL; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id E3E741E06B; Tue, 22 Sep 2026 16:13:33 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 0DC281E01F for ; Tue, 22 Sep 2026 16:13:33 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1EB084B99F65 for ; Tue, 22 Sep 2026 20:13:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1EB084B99F65 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=a5XWm7LL Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 9DDA44BA2E03 for ; Tue, 22 Sep 2026 20:13:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9DDA44BA2E03 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9DDA44BA2E03 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790107986; cv=none; b=nInPQg1Xr3vOoykHUtwX+m2T0XJpqbILHsbk9M0t+izl38eHlPwFf8R7zLTnJJ9o/70viM4fAHCI66lf8TcTW7eNRjTRRNTVtXRqN7GhaaG+/w2IMVgLvZiY3YA4KRQV8YKfYByRym4EdqFJCtV/hdo0enMrJwrR8s/RTMAQ4tE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790107986; c=relaxed/simple; bh=MRqc5P76hHCd6EPzZrB8rlY5h3rvfcYu2LW3uFRuRLI=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=VvXrb5CWli5F5bl6asAbpFrwKMakpDWS8NraCV1MCTvzmNB0UkQbr8of73YSoPHWYXxUQ9PjWUQEzFjBrVe8pBOWtmkPOE86N7439r4RHdhkIgKjAEy4qJqytJvTYwPLNtQM594DKmRMKGlds5+nhh7JlARTsWVZMcvCIc+uoRE= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=a5XWm7LL DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9DDA44BA2E03 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1790107986; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FkvJS/JASdzzeV4zRdP6bD21JSe3JNRQyG/Ww5aDgls=; b=a5XWm7LLknB825EXBkxADX7oFHPcW1ffTg7INaP35XKT4tdhxmdKNC5aWzD6FWXRQhlit+ lzCmVF75PnwpyNSyuFwWCE4B5TtWHWvWKXz7UUx7t7fgnnkdxfaYtxswlumsANvrY/socM M9b49diAqlJ9/xY9lfPkdP/FStB1hjY= Received: from mail-yw1-f200.google.com (mail-yw1-f200.google.com [209.85.128.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-397-8VE02fADPsiWhDOM9tHujA-1; Tue, 22 Sep 2026 16:13:04 -0400 X-MC-Unique: 8VE02fADPsiWhDOM9tHujA-1 X-Mimecast-MFC-AGG-ID: 8VE02fADPsiWhDOM9tHujA_1790107984 Received: by mail-yw1-f200.google.com with SMTP id 00721157ae682-8a1d3de9eb8so15325097b3.0 for ; Tue, 22 Sep 2026 13:13:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790107984; x=1790712784; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:to:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=FkvJS/JASdzzeV4zRdP6bD21JSe3JNRQyG/Ww5aDgls=; b=O/+YYGPTXWrNMqG3KzvqUEXUSzILftnkruWgE0BMZ0vaG/f9h5dxfU1skXTCXQ1Kyr OWB0CvGX1UkYKtzwCvAxt7ZFTZOiMjplFDdusO51NSmBJd3ABZjYw6dC4it4Ubhu0oPp V3MezvTkdnZEJjzPgvnhSeo4uEfYahr8NJt2tGchjyjbEY4XISTUv4jhHjeD9GqXc8bx q1ZADYqaME2faLVbSxPcZLo3WvqA3MZWnAQtdNpe+QHik+fSeq7VyuVPYzAUiNbSy8jr L4DsFGK5F62SYNT0KYf+K8aTYsQtLIFcDzK90cknJBBGnHo4j5vaRyMHtPKm+EIXyhJh IGPA== X-Forwarded-Encrypted: i=1; AKwUvBzqbaAP+msFPpTOuWSVmUXUc84x7tsd27kCgY6/pF+EZV0Pqs1DSq6wXPMvO8lj9uaIdJNFsORkNpGeLQ==@sourceware.org X-Gm-Message-State: AFuF++mJtCM4hou5xHn3ve73IiFJt+sPKfyy4Tk5zdsY+zbax2fji8BU lZw41NkJJ6MyG/CxX7ZpTF9FoyrgEgpvYjuzBgpLbaKeec7WqdCuO4txyMSTm5f1Zl8p46h1Js3 mBEtZuPgiKBfrX+lFMbSQfbDP3fBQiGUeEu0PAWpXjRfEvEYEOR9HIxmQrvnDnTokj5T7LtM= X-Gm-Gg: AYBFou2JwhwkzI9W3g8k5B56vmOkPi+Brd/BNFUwOFiI19risam0TU62O51M8g3qyLE 9X8JonaEcLfImMiQOAqCIrpi53Xc1wJbcSxN2zThqn9ETpfduEr0HzuwNMkhPyuMgnh1yl6OZTf xG2tP7brEmdf3SAxSV3Ha0hPOJgk5Rahy4UQElFag7XWzG9oK13El1CJq6jRWdK0EQeCP+zfKDT FEy2NtVWAvu68uvbHNQrIDn7hLIdmE6y5NI2ovreXk14rn1yQd1Oo0/doswcDGWNz+x33K4xDLF gkpVJCg5/Tl1665Ngq8+odkLMoc9tNdRIc2oj5t/Hd6DTkAK2c5zpeQsXr04nlQ1bj1h6fPaUNa D1QS+qdU= X-Received: by 2002:a05:690c:e18b:10b0:86c:295c:8d1c with SMTP id 00721157ae682-8a4599fb837mr2700537b3.4.1790107984017; Tue, 22 Sep 2026 13:13:04 -0700 (PDT) X-Received: by 2002:a05:690c:e18b:10b0:86c:295c:8d1c with SMTP id 00721157ae682-8a4599fb837mr2700487b3.4.1790107983447; Tue, 22 Sep 2026 13:13:03 -0700 (PDT) Received: from [150.1.200.157] ([172.56.108.234]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8a461482ab8sm2103897b3.4.2026.09.22.13.13.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Sep 2026 13:13:02 -0700 (PDT) Message-ID: Date: Tue, 22 Sep 2026 13:13:01 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] [gdb/contrib] Make gdb-add-index.sh shellcheck-clean To: Tom de Vries , gdb-patches@sourceware.org References: <20260915171459.2753844-1-tdevries@suse.de> From: Keith Seitz In-Reply-To: <20260915171459.2753844-1-tdevries@suse.de> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: oXN-8DcGwYjYbmCRG9iwsxLULehbKikqOMByI1OA9Lw_1790107984 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Hi, Thank you for doing this. On 9/15/26 10:14 AM, Tom de Vries wrote: > Make gdb-add-index.sh shellcheck-clean: > - drop x in "xa" != "xb" comparison > - eliminate tmp_files and use the args array instead > - drop dwz_file=$(echo $dwz_file) and strip leading spaces using > sed instead > --- > gdb/contrib/gdb-add-index.sh | 19 ++++++++++++------- > gdb/contrib/shellcheck.sh | 4 ---- > 2 files changed, 12 insertions(+), 11 deletions(-) > > diff --git a/gdb/contrib/gdb-add-index.sh b/gdb/contrib/gdb-add-index.sh > index 4a30c5c5536..e1a37f2cd4c 100755 > --- a/gdb/contrib/gdb-add-index.sh > +++ b/gdb/contrib/gdb-add-index.sh > @@ -82,7 +82,7 @@ case ${opt} in > ;; > esac > # Break from loop if the first character of OPT is not '-'. > -[ "x$(printf %.1s "$opt")" != "x-" ] > +[ "$(printf %.1s "$opt")" != "-" ] > do > shift > done > @@ -93,6 +93,7 @@ if test $# != 1; then > fi > > file="$1" > +set -- > This unsets the positional parameters, clearing $1, but this is subsequently used if readlink fails: > if test -L "$file"; then > if ! command -v readlink >/dev/null 2>&1; then echo "$myname: 'readlink' missing. Failed to follow symlink $1." 1>&2 exit 1 fi Does this need to change to "$file"? > @@ -135,8 +136,7 @@ if $READELF -S "$file" | grep -q " \.gnu_debugaltlink "; then > dwz_file=$($READELF --string-dump=.gnu_debugaltlink "$file" \ > | grep -A1 "'\.gnu_debugaltlink':" \ > | tail -n +2 \ > - | sed 's/.*]//') > - dwz_file=$(echo $dwz_file) > + | sed 's/.*] *//') > if $READELF -S "$dwz_file" | grep -E -q " \.(gdb_index|debug_names) "; then > # Already has an index, skip it. > dwz_file="" > @@ -154,19 +154,24 @@ set_files () > debugstrerr="${fpath}.debug_str.err" > } > > -tmp_files= > for f in "$file" "$dwz_file"; do > if [ "$f" = "" ]; then > continue > fi > set_files "$f" > - tmp_files="$tmp_files $index4 $index5 $debugstr $debugstrmerge $debugstrerr" > + set -- \ > + "$@" \ > + "$index4" \ > + "$index5" \ > + "$debugstr" \ > + "$debugstrmerge" \ > + "$debugstrerr" > done > > -rm -f $tmp_files > +rm -f "$@" > > # Ensure intermediate index file is removed when we exit. > -trap "rm -f $tmp_files" 0 > +trap 'rm -f "$@"' 0 I'm not sure this is safe. The "$@" in the trap is expanded when the trap runs, using whatever positional parameters are active in that context. If that happens when exit is called from a function (as in handle_file on objcopy failure), bash substitutes the function's arguments instead of the temp-file list, erasing the real binary and leaving the temps behind. [On Fedora, /bin/sh --> /bin/bash.] Demonstration: $ cat > trap-test.sh << 'EOF' #! /bin/sh # These are our temporary files... set -- /tmp/index.tmp /tmp/debugstr.tmp touch "$@" trap 'echo "trap removes: $*"; rm -f "$@"' EXIT handle_file () { echo "in handle_file, \$1=$1" exit 1 # like gdb-add-index.sh on objcopy failure } handle_file /tmp/important-binary EOF $ touch /tmp/important-binary; # for clarity $ bash trap-test.sh in handle_file, $1=/tmp/important-binary trap removes: /tmp/important-binary Keith