Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH] [gdb/contrib] Simplify rc usage in cc-with-tweaks.sh
Date: Wed,  2 Sep 2026 21:15:59 +0200	[thread overview]
Message-ID: <20260902191559.3951565-1-tdevries@suse.de> (raw)

The usage of the rc variable in gdb/contrib/cc-with-tweaks.sh follows a
certain pattern:
...
$ egrep '(rc=|\$rc)' gdb/contrib/cc-with-tweaks.sh | grep -v cmp_rc
rc=$?
[ $rc != 0 ] && exit $rc
    rc=$?
    [ $rc != 0 ] && exit $rc
    rc=${PIPESTATUS[0]}
    [ "$rc" != 0 ] && exit "$rc"
    rc=$?
    [ $rc != 0 ] && exit $rc
    rc=0
	rc=$?
	[ $rc != 0 ] && exit $rc
    rc=$?
    [ $rc != 0 ] && exit $rc
    rc=$?
    [ $rc != 0 ] && exit $rc
    rc=$?
    [ $rc != 0 ] && exit $rc
exit "$rc"
...

It is:
- set using 'rc=$?' or 'rc=${PIPESTATUS[0]}', and then
- used in '[ $rc != 0 ] && exit $rc'.

The two exceptions are 'rc=0', and 'exit "$rc"'.

Remove the 'rc=0', there's no path reaching it where it's not already 0.

Removing the 'exit "$rc"' changes semantics in a cornercase.

Consider:
...
if true; then
   rc=0
   [ $rc != 0 ] && exit $rc
fi
exit $rc
...

What happens is:
- the if block is entered
- rc is set to 0
- the test evaluates to 1, so the exit doesn't trigger
- the if returns status of last command (1)
- script exits with 0

If we remove the exit, we have:
- the if block is entered
- rc is set to 0
- the test evaluates to 1, so the exit doesn't trigger
- the if returns status of last command (1)
- script exits with status of last command (1)

Fix this using:
...
-[ $rc != 0 ] && exit $rc
+if [ $rc != 0 ]; then exit $rc; fi
...
---
 gdb/contrib/cc-with-tweaks.sh | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/gdb/contrib/cc-with-tweaks.sh b/gdb/contrib/cc-with-tweaks.sh
index 047c748e165..20f90d9c3ed 100755
--- a/gdb/contrib/cc-with-tweaks.sh
+++ b/gdb/contrib/cc-with-tweaks.sh
@@ -163,7 +163,7 @@ output_dir="${output_file%/*}"
 
 "$@"
 rc=$?
-[ $rc != 0 ] && exit $rc
+if [ $rc != 0 ]; then exit $rc; fi
 if [ ! -f "$output_file" ]
 then
     echo "$myname: Internal error: $output_file missing." >&2
@@ -184,7 +184,7 @@ get_tmpdir ()
 if [ "$want_objcopy_compress" = true ]; then
     $OBJCOPY --compress-debug-sections "$output_file"
     rc=$?
-    [ $rc != 0 ] && exit $rc
+    if [ $rc != 0 ]; then exit $rc; fi
 fi
 
 if [ "$want_index" = true ]; then
@@ -212,7 +212,7 @@ if [ "$want_index" = true ]; then
     rc=${PIPESTATUS[0]}
     mv "$tmpfile" "$output_file"
     rm -f "$tmpdir"/*.dwo
-    [ "$rc" != 0 ] && exit "$rc"
+    if [ "$rc" != 0 ]; then exit "$rc"; fi
 fi
 
 if [ "$want_index_cache" = true ]; then
@@ -221,7 +221,7 @@ if [ "$want_index_cache" = true ]; then
 	 -ex "set index-cache enabled on" \
 	 -ex "file $output_file"
     rc=$?
-    [ $rc != 0 ] && exit $rc
+    if [ $rc != 0 ]; then exit $rc; fi
 fi
 
 if [ "$want_dwz" = true ] || [ "$want_multi" = true ]; then
@@ -290,11 +290,10 @@ if [ "$want_dwp" = true ]; then
 		  | sed -e 's/^.*: //' \
 		  | sort \
 		  | uniq)
-    rc=0
     if  [ ${#dwo_files[@]} -ne 0 ]; then
 	$DWP -o "${output_file}.dwp" "${dwo_files[@]}" > /dev/null
 	rc=$?
-	[ $rc != 0 ] && exit $rc
+	if [ $rc != 0 ]; then exit $rc; fi
 	rm -f "${dwo_files[@]}"
     fi
 fi
@@ -313,11 +312,11 @@ if [ "$want_gnu_debuglink" = true ]; then
     strip "${STRIP_ARGS_STRIP_DEBUG[@]}" "${output_file}" \
 	  -o "${stripped_file}"
     rc=$?
-    [ $rc != 0 ] && exit $rc
+    if [ $rc != 0 ]; then exit $rc; fi
     strip "${STRIP_ARGS_KEEP_DEBUG[@]}" "${output_file}" \
 	  -o "${debug_file}"
     rc=$?
-    [ $rc != 0 ] && exit $rc
+    if [ $rc != 0 ]; then exit $rc; fi
 
     # The .gnu_debuglink is supposed to contain no leading directories.
     link=$(basename "${debug_file}")
@@ -332,7 +331,5 @@ if [ "$want_gnu_debuglink" = true ]; then
 		 "${output_file}"
     )
     rc=$?
-    [ $rc != 0 ] && exit $rc
+    if [ $rc != 0 ]; then exit $rc; fi
 fi
-
-exit "$rc"

base-commit: 62b131d7aebdb9921f47656cb0590f99fc31edbf
-- 
2.51.0


             reply	other threads:[~2026-09-02 19:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02 19:15 Tom de Vries [this message]
2026-09-09 13:04 ` Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260902191559.3951565-1-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox