From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YYRuMAcBs2peiDQAWB0awg (envelope-from ) for ; Tue, 22 Sep 2026 18:28:23 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=Q6PCOlzL; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=gE5dw4cb; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=MKnQxkzT; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=/jOJENiq; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 9AAB31E06B; Tue, 22 Sep 2026 18:28:23 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.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 17F411E033 for ; Tue, 22 Sep 2026 18:28:21 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95D304BB1C3A for ; Tue, 22 Sep 2026 22:28:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95D304BB1C3A Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=Q6PCOlzL; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=gE5dw4cb; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=MKnQxkzT; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=/jOJENiq Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 12C064BB1C1F for ; Tue, 22 Sep 2026 22:27:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 12C064BB1C1F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 12C064BB1C1F Authentication-Results: sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790116074; cv=none; b=gbyli7D31s7bT3y8yTN2I/ZLQguzIN6bNHsxXBok/lifGcDnHsiVrhfjAKyJT/puvfPaYJseC45QbqLAUxhwQ5utxoy2gePz0u3yEBeQmId81uDjcPIIx5yDHC01GUBORiedmEZY5G0CqFfWo7/zLGH4PWAK+8Upzx2iG48ezBM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790116074; c=relaxed/simple; bh=fgwVCDMsxUZJX1uwVMlhQslZb09F5YTa5n7xlzrElII=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:To:From; b=W2e4dTRjsHDZHDG2wEZFLapN9vB2jJ3nSduBBxurgXO6G/QjGQECbt/7CqNWvNerh7E4mzkAELfnVBUOzy9h2mPhuvZB53attj1IlGp9u7+QydMgh0H8eKkQ/XU3vsXhNIkDeaBrweboGH7Wdy5sNvommh64233eCJ/y0nja5zg= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=Q6PCOlzL; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=gE5dw4cb; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=MKnQxkzT; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=/jOJENiq DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 12C064BB1C1F Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BE6CB21DDB; Tue, 22 Sep 2026 22:27:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1790116068; h=from:from:reply-to: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=1gbGvdm+8QETtcqrmx1FxH62Vza/ebXNf+oAj2yFIic=; b=Q6PCOlzLPBdjl9iDWJxEmzpQpBCfIOC/G7ofTIAxubB6ETxKg8rFJkfNqf8mVhdX4Xzoxv lVF8+tff64L61hKVPA9//oEdoftgwo4uXDy5Hvw75ZznyilvSNimfzsbU7mIxxoBs4H8FO HJKWsrylTxDlqishj79qP5IIRa323/k= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1790116068; h=from:from:reply-to: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=1gbGvdm+8QETtcqrmx1FxH62Vza/ebXNf+oAj2yFIic=; b=gE5dw4cb8+dRIE/6oXagrOdNLRweqciarasPaSVVdZ4+XcgL2hRottlkmP5jvi4BredAW1 40xF1xUOU45lHyCg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1790116064; h=from:from:reply-to: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=1gbGvdm+8QETtcqrmx1FxH62Vza/ebXNf+oAj2yFIic=; b=MKnQxkzT3ZaY1NMW5zQqCqmJcceh6hPd5gQUwakjZ0fpHfVTNECQYorOOIa+pJypWkOxRz iGAi55XcbHC0Af7VRuWOt2csS7ChOS/EUIXXqxfwJ3Nj3gAWsaOTuHAMawr7ZjbW6uH2fd 6is3j+tB1vDyrkPIvhb4LVVMilphgB0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1790116064; h=from:from:reply-to: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=1gbGvdm+8QETtcqrmx1FxH62Vza/ebXNf+oAj2yFIic=; b=/jOJENiqEVlNrFI63uc+s2S+8Nlf2DebVtUS/yiJJedsabke/AzPEPJ0CfuqvJn94SKMJ4 8WdtMt6Laq+w+NDA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 888FA13312; Tue, 22 Sep 2026 22:27:44 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id SayCGeAAs2qPNAAAD6G6ig (envelope-from ); Tue, 22 Sep 2026 22:27:44 +0000 Message-ID: <9368e2a9-ea97-4306-b081-33b81d181d28@suse.de> Date: Wed, 23 Sep 2026 00:27:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] [gdb/contrib] Make gdb-add-index.sh shellcheck-clean To: Keith Seitz , gdb-patches@sourceware.org References: <20260915171459.2753844-1-tdevries@suse.de> Content-Language: en-US From: Tom de Vries In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-0.995]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; URIBL_BLOCKED(0.00)[imap1.dmz-prg2.suse.org:helo,trap-test.sh:url,gdb-add-index.sh:url,suse.de:mid]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid, gdb-add-index.sh:url, trap-test.sh:url, imap1.dmz-prg2.suse.org:helo] 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 On 9/22/26 10:13 PM, Keith Seitz wrote: > 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"? > Indeed, thanks for catching that. >> @@ -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 > I see, I didn't take that into account. I can fix this by doing: ... trap '{ skip=true for arg in "$@"; do if [ "$arg" = "--" ]; then skip=false continue fi if $skip; then continue fi rm -f "$arg" done }' 0 ... and doing: ... andle_file "$file" -- "$@" if [ "$dwz_file" != "" ]; then handle_file "$dwz_file" -- "$@" fi ... and like wise here: ... set -- \ "--" \ "$@" \ "$index4" \ "$index5" \ "$debugstr" \ "$debugstrmerge" \ "$debugstrerr" ... But it all feels a bit convoluted. I'll try to come up with something else. Thanks for catching this. - Tom > Keith >