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 2/2] [gdb] Make gdb_mbuild.sh shellcheck-clean
Date: Mon, 31 Aug 2026 08:50:19 +0200	[thread overview]
Message-ID: <20260831065019.3494642-3-tdevries@suse.de> (raw)
In-Reply-To: <20260831065019.3494642-1-tdevries@suse.de>

Make gdb/gdb_mbuild.sh shellcheck-clean:
- add missing quoting
- move unreachable code into comment
- add shellcheck ignore for "to be implemented" functionality
- make targexp an array, and change shell type to bash
- use $() and $(())
- use makejobs="$1" instead of makejobs="-j $1"
- use read -r
- use '' for trap argument
- remove useless cat
- add "|| exit 1" after cd
- don't use [] in tr arguments
---
 gdb/contrib/shellcheck.sh |   1 -
 gdb/gdb_mbuild.sh         | 102 +++++++++++++++++++-------------------
 2 files changed, 52 insertions(+), 51 deletions(-)

diff --git a/gdb/contrib/shellcheck.sh b/gdb/contrib/shellcheck.sh
index a3e80a553f4..1d01471c12d 100755
--- a/gdb/contrib/shellcheck.sh
+++ b/gdb/contrib/shellcheck.sh
@@ -46,7 +46,6 @@ for f in "$@"; do
 	    | gdb/contrib/cc-with-tweaks.sh \
 	    | gdb/contrib/gdb-add-index.sh \
 	    | gdb/gdb_buildall.sh \
-	    | gdb/gdb_mbuild.sh \
 	    | gdb/testsuite/lib/pdtrace.in)
 	    # Skip unclean files.
 	    continue
diff --git a/gdb/gdb_mbuild.sh b/gdb/gdb_mbuild.sh
index 705bb1f6f1f..c07ef724d88 100755
--- a/gdb/gdb_mbuild.sh
+++ b/gdb/gdb_mbuild.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 #  Multi-build script for testing compilation of all maintained
 #  configs of GDB.
@@ -44,19 +44,20 @@ Usage: gdb_mbuild.sh [ <options> ... ] <srcdir> <builddir>
    MAKE (make)"
 EOF
     exit 1;
-cat <<NOTYET
-  -b <maxbuilds> Run <maxbuild> builds in parallel.
-		 On a single cpu machine, 1 is recommended.
-NOTYET
+
+    # Not yet implemented:
+    # -b <maxbuilds> Run <maxbuild> builds in parallel.
+    #		   On a single cpu machine, 1 is recommended.
 }
 
 ### COMMAND LINE OPTIONS
 
 makejobs=
+# shellcheck disable=SC2034 # Not yet implemented.
 maxbuilds=1
 keepgoing=
 force=false
-targexp=""
+targexp=()
 verbose=0
 keep=false
 while test $# -gt 0
@@ -66,12 +67,13 @@ do
 	# Number of parallel make jobs.
 	shift
 	test $# -ge 1 || usage
-	makejobs="-j $1"
+	makejobs="$1"
 	;;
     -b | -c )
 	# Number of builds to fire off in parallel.
 	shift
 	test $# -ge 1 || usage
+	# shellcheck disable=SC2034 # Not yet implemented.
 	maxbuilds=$1
 	;;
     -k )
@@ -85,7 +87,7 @@ do
 	# A regular expression for selecting targets
 	shift
 	test $# -ge 1 || usage
-	targexp="${targexp} -e ${1}"
+	targexp=("${targexp[@]}" "-e" "${1}")
 	;;
     -f )
 	# Force a rebuild
@@ -93,7 +95,7 @@ do
 	;;
     -v )
 	# Be more, and more, and more, verbose
-	verbose=`expr ${verbose} + 1`
+	verbose=$((verbose + 1))
 	;;
     -* ) usage ;;
     *) break ;;
@@ -112,10 +114,10 @@ fi
 # Convert these to absolute directory paths.
 
 # Where the sources live
-srcdir=`cd $1 && /bin/pwd` || exit 1
+srcdir=$(cd "$1" && /bin/pwd) || exit 1
 
 # Where the builds occur
-builddir=`cd $2 && /bin/pwd` || exit 1
+builddir=$(cd "$2" && /bin/pwd) || exit 1
 
 ### ENVIRONMENT PARAMETERS
 
@@ -127,14 +129,14 @@ export MAKE
 
 # Where to look for the list of targets to test
 maintainers=${srcdir}/gdb/MAINTAINERS
-if [ ! -r ${maintainers} ]
+if [ ! -r "${maintainers}" ]
 then
-    echo Maintainers file ${maintainers} not found
+    echo "Maintainers file ${maintainers} not found"
     exit 1
 fi
 
 # Get the list of targets and the build options
-alltarg=`cat ${maintainers} | tr -s '[\t]' '[ ]' | sed -n '
+alltarg=$(tr -s '\t' ' ' < "${maintainers}" | sed -n '
 /^[ ]*[-a-z0-9\.]*[ ]*[(]*--target=.*/ !d
 s/^.*--target=//
 s/).*$//
@@ -150,12 +152,12 @@ h
 b loop
 :end
 p
-' | if test "${targexp}" = ""
+' | if test ${#targexp[@]} -eq 0
 then
     grep -v -e broken -e OBSOLETE
 else
-    grep ${targexp}
-fi`
+    grep "${targexp[@]}"
+fi)
 
 
 # Usage: fail <message> <test-that-should-succeed>.  Should the build
@@ -185,11 +187,11 @@ fail ()
 
 log ()
 {
-    if test ${verbose} -ge $1
+    if test ${verbose} -ge "$1"
     then
-	tee $2
+	tee "$2"
     else
-	cat > $2
+	cat > "$2"
     fi
 }
 
@@ -203,7 +205,7 @@ echo ""
 
 # For each target, configure, build and test it.
 
-echo "$alltarg" | while read target gdbopts simopts
+echo "$alltarg" | while read -r target gdbopts simopts
 do
 
     trap "exit 1"  1 2 15
@@ -214,24 +216,24 @@ do
 
     if ${force}
     then
-	echo forcing ${target} ...
-	rm -rf ${dir}
-    elif test -f ${dir}
+	echo "forcing ${target} ..."
+	rm -rf "${dir}"
+    elif test -f "${dir}"
     then
 	echo "${target}"
 	continue
     else
-	echo ${target} ...
+	echo "${target} ..."
     fi
 
     # Did the previous configure attempt fail?  If it did
     # restart from scratch.
 
-    if test -d ${dir} -a ! -r ${dir}/Makefile
+    if test -d "${dir}" -a ! -r "${dir}/Makefile"
     then
-	echo ... removing partially configured ${target}
-	rm -rf ${dir}
-	if test -d ${dir}
+	echo "... removing partially configured ${target}"
+	rm -rf "${dir}"
+	if test -d "${dir}"
 	then
 	    echo "${target}: unable to remove directory ${dir}"
 	    exit 1
@@ -240,8 +242,8 @@ do
 
     # From now on, we're in this target's build directory
 
-    mkdir -p ${dir}
-    cd ${dir} || exit 1
+    mkdir -p "${dir}"
+    cd "${dir}" || exit 1
 
     # Configure, if not already.  Should this go back to being
     # separate and done in parallel?
@@ -252,16 +254,16 @@ do
 	test -z "${simopts}" && simopts="${gdbopts}"
 	# The config options
 	__target="--target=${target}"
-	__enable_gdb_build_warnings=`test -z "${gdbopts}" \
-	    || echo "--enable-gdb-build-warnings=${gdbopts}"`
-	__enable_sim_build_warnings=`test -z "${simopts}" \
-	    || echo "--enable-sim-build-warnings=${simopts}"`
+	__enable_gdb_build_warnings=$(test -z "${gdbopts}" \
+	    || echo "--enable-gdb-build-warnings=${gdbopts}")
+	__enable_sim_build_warnings=$(test -z "${simopts}" \
+	    || echo "--enable-sim-build-warnings=${simopts}")
 	__configure="${srcdir}/configure \
 	    ${__target} \
 	    ${__enable_gdb_build_warnings} \
 	    ${__enable_sim_build_warnings}"
-	echo ... ${__configure}
-	trap "echo Removing partially configured ${dir} directory ...; rm -rf ${dir}; exit 1" 1 2 15
+	echo "... ${__configure}"
+	trap 'echo "Removing partially configured ${dir} directory ..."; rm -rf "${dir}"; exit 1' 1 2 15
 	${__configure} 2>&1 | log 2 Config.log
 	trap "exit 1"  1 2 15
     fi
@@ -275,16 +277,16 @@ do
 	# the follow-on code knows things failed.  Stops the follow-on
 	# code thinking that a failed rebuild succeeded (executable
 	# left around from previous build).
-	echo ... ${make} ${keepgoing} ${makejobs} ${target}
-	( ${make} ${keepgoing} ${makejobs} all-gdb || rm -f gdb/gdb gdb/gdb.exe
+	echo "... ${make} ${keepgoing} ${makejobs:+-j $makejobs} ${target}"
+	( ${make} ${keepgoing} ${makejobs:+-j $makejobs} all-gdb || rm -f gdb/gdb gdb/gdb.exe
 	) 2>&1 | log 1 Build.log
     fi
     fail "compile failed" ! -x gdb/gdb -a ! -x gdb/gdb.exe
 
     # Check that the built GDB can at least print it's architecture.
 
-    echo ... run ${target}
-    rm -f core gdb.core ${dir}/gdb/x
+    echo "... run ${target}"
+    rm -f core gdb.core "${dir}/gdb/x"
     cat <<EOF > x
 maint print architecture
 quit
@@ -294,7 +296,7 @@ EOF
     fail "gdb printed no output" ! -s Gdb.log
     grep -e internal-error Gdb.log && fail "gdb panic" 1
 
-    echo ... cleanup ${target}
+    echo "... cleanup ${target}"
 
     # Create a sed script that cleans up the output from GDB.
     rm -f mbuild.sed
@@ -303,9 +305,9 @@ EOF
     # name.
     sed -n -e '/<0x0*>/d' -e 's/^.*<0x\([0-9a-f]*\)>.*$/0x\1/p' Gdb.log \
     | sort -u \
-    | while read addr
+    | while read -r addr
     do
-	func="`addr2line -f -e ./gdb/gdb -s ${addr} | sed -n -e 1p`"
+	func="$(addr2line -f -e ./gdb/gdb -s "${addr}" | sed -n -e 1p)"
 	test ${verbose} -gt 0 && echo "${addr} ${func}" 1>&2
 	echo "s/<${addr}>/<${func}>/g"
     done >> mbuild.sed
@@ -317,20 +319,20 @@ EOF
     # Replace the build directory with a file as semaphore that stops
     # a rebuild. (should the logs be saved?)
 
-    cd ${builddir}
+    cd "${builddir}" || exit 1
 
     if ${keep}
     then
 	:
     else
-	rm -f ${target}.tmp
-	mv ${target}/Mbuild.log ${target}.tmp
-	rm -rf ${target}
-	mv ${target}.tmp ${target}
+	rm -f "${target}.tmp"
+	mv "${target}/Mbuild.log" "${target}.tmp"
+	rm -rf "${target}"
+	mv "${target}.tmp" "${target}"
     fi
 
     # Success!
-    echo ... ${target} built
+    echo "... ${target} built"
 
 done
 
-- 
2.51.0


  parent reply	other threads:[~2026-08-31  6:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31  6:50 [PATCH 0/2] [gdb] Two gdb_mbuild.sh fixes Tom de Vries
2026-08-31  6:50 ` [PATCH 1/2] [gdb] Fix warning in gdb_mbuild.sh Tom de Vries
2026-08-31  6:50 ` Tom de Vries [this message]
2026-09-14 21:27 ` [PATCH 0/2] [gdb] Two gdb_mbuild.sh fixes 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=20260831065019.3494642-3-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