From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/2] [gdb] Make regformats/regdat.sh shellcheck-clean
Date: Fri, 28 Aug 2026 14:04:38 +0200 [thread overview]
Message-ID: <20260828120439.3857602-2-tdevries@suse.de> (raw)
In-Reply-To: <20260828120439.3857602-1-tdevries@suse.de>
Make regformats/regdat.sh shellcheck-clean:
- use read -r
- use $()
- ignore intentional word-splitting
- add missing quotes
- use $(())
Handle a shellcheck error in this:
...
if eval test \"\${${r}}\" = \"\ \"
...
by simplifying to:
...
eval "rvalue=\$$r"
if test "${rvalue:-}" = " "
...
Note that shellcheck can't detect that rvalue is assigned to, so we use
'${parameter:-word}' to use default value "", to silence a SC2154 [1].
Also, handle a shellcheck error in this:
...
eval ${r}=""
...
by simplifying to:
...
eval "$r=''"
...
Tested on x86_64-linux using:
...
$ for f in $(find gdb/regformats -name "*.dat"); do \
sh gdb/regformats/regdat.sh \
$f \
gdbsupport/osabi.def \
$(echo $f | sed 's%/%-%g'); \
done
...
and comparing the generated files with and without this patch.
[1] https://www.shellcheck.net/wiki/SC2154
---
gdb/contrib/shellcheck.sh | 1 -
gdb/regformats/regdat.sh | 25 ++++++++++++++-----------
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/gdb/contrib/shellcheck.sh b/gdb/contrib/shellcheck.sh
index f7f7bf9efbf..a3e80a553f4 100755
--- a/gdb/contrib/shellcheck.sh
+++ b/gdb/contrib/shellcheck.sh
@@ -47,7 +47,6 @@ for f in "$@"; do
| gdb/contrib/gdb-add-index.sh \
| gdb/gdb_buildall.sh \
| gdb/gdb_mbuild.sh \
- | gdb/regformats/regdat.sh \
| gdb/testsuite/lib/pdtrace.in)
# Skip unclean files.
continue
diff --git a/gdb/regformats/regdat.sh b/gdb/regformats/regdat.sh
index b57b76132aa..01f2dabe459 100755
--- a/gdb/regformats/regdat.sh
+++ b/gdb/regformats/regdat.sh
@@ -25,7 +25,7 @@ do_read ()
{
type=""
entry=""
- while read line
+ while read -r line
do
if test "${line}" = ""
then
@@ -42,9 +42,11 @@ ${line}"
# The semantics of IFS varies between different SH's. Some
# treat ``::' as three fields while some treat it as just too.
# Work around this by eliminating ``::'' ....
- line="`echo "${line}" | sed -e 's/::/: :/g' -e 's/::/: :/g'`"
+ line="$(echo "${line}" | sed -e 's/::/: :/g' -e 's/::/: :/g')"
OFS="${IFS}" ; IFS="[:]"
+ # Word-splitting on read variable is required.
+ # shellcheck disable=SC2086
eval read ${read} <<EOF
${line}
EOF
@@ -54,9 +56,10 @@ EOF
# that ended up with just that space character.
for r in ${read}
do
- if eval test \"\${${r}}\" = \"\ \"
+ eval "rvalue=\$$r"
+ if test "${rvalue:-}" = " "
then
- eval ${r}=""
+ eval "$r=''"
fi
done
@@ -71,7 +74,7 @@ EOF
fi
}
-if test ! -r $1; then
+if test ! -r "$1"; then
echo "$0: Could not open $1." 1>&2
exit 1
fi
@@ -105,8 +108,8 @@ EOF
}
-exec > new-$3
-copyright $1
+exec > new-"$3"
+copyright "$1"
echo '#include "regdef.h"'
echo '#include "tdesc.h"'
echo
@@ -119,7 +122,7 @@ xmlosabi=x
expedite=x
feature=x
osabi=unknown
-exec < $1
+exec < "$1"
while do_read
do
if test "${type}" = "name"; then
@@ -162,13 +165,13 @@ do
echo " tdesc_create_reg (feature, \"${entry}\","
echo " 0, 0, NULL, ${type}, NULL);"
- offset=`expr ${offset} + ${type}`
- i=`expr $i + 1`
+ offset=$((offset + type))
+ i=$((i + 1))
fi
done
echo
-echo "static const char *expedite_regs_${name}[] = { \"`echo ${expedite} | sed 's/,/", "/g'`\", 0 };"
+echo "static const char *expedite_regs_${name}[] = { \"$(echo "${expedite}" | sed 's/,/", "/g')\", 0 };"
echo "#ifndef IN_PROCESS_AGENT"
if test "${feature}" != x; then
--
2.51.0
next prev parent reply other threads:[~2026-08-28 12:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 12:04 [PATCH 0/2] [gdb] Two regformats/regdat.sh fixes Tom de Vries
2026-08-28 12:04 ` Tom de Vries [this message]
2026-08-28 12:43 ` [PATCH 1/2] [gdb] Make regformats/regdat.sh shellcheck-clean Simon Marchi
2026-08-28 14:40 ` Tom de Vries
2026-08-28 13:34 ` Andreas Schwab
2026-08-28 14:04 ` Tom de Vries
2026-08-28 12:04 ` [PATCH 2/2] [gdb] Fix unbound variable in regformats/regdat.sh Tom de Vries
2026-08-28 12:46 ` Simon Marchi
2026-08-28 14:19 ` 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=20260828120439.3857602-2-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