* [PATCH] [gdb/contrib] Simplify rc usage in cc-with-tweaks.sh
@ 2026-09-02 19:15 Tom de Vries
2026-09-09 13:04 ` Tom de Vries
0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2026-09-02 19:15 UTC (permalink / raw)
To: gdb-patches
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] [gdb/contrib] Simplify rc usage in cc-with-tweaks.sh
2026-09-02 19:15 [PATCH] [gdb/contrib] Simplify rc usage in cc-with-tweaks.sh Tom de Vries
@ 2026-09-09 13:04 ` Tom de Vries
0 siblings, 0 replies; 2+ messages in thread
From: Tom de Vries @ 2026-09-09 13:04 UTC (permalink / raw)
To: gdb-patches
On 9/2/26 9:15 PM, Tom de Vries wrote:
> Fix this using:
> ...
> -[ $rc != 0 ] && exit $rc
> +if [ $rc != 0 ]; then exit $rc; fi
> ...
I've pushed this, with one change in the code: add a final "exit 0".
I've also changed the rationale for removing rc=0 to "unused def".
Thanks,
- Tom
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-09 13:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-02 19:15 [PATCH] [gdb/contrib] Simplify rc usage in cc-with-tweaks.sh Tom de Vries
2026-09-09 13:04 ` Tom de Vries
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox