* [PATCH v2 0/3] [gdb] Reformat regformats/regdat.sh
@ 2026-08-30 19:53 Tom de Vries
2026-08-30 19:53 ` [PATCH v2 1/3] [gdb] Re-indent regformats/regdat.sh Tom de Vries
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Tom de Vries @ 2026-08-30 19:53 UTC (permalink / raw)
To: gdb-patches
This patch series contains three patches touching gdb/regformats/regdat.sh.
The first standarized indentation.
The second uses shfmt.
The third uses shfmt --simplify.
Changes in v2:
- split off patch standarizing indentation
- added patch using shfmt --simplify
Versions:
- v1 https://sourceware.org/pipermail/gdb-patches/2026-August/229822.html
Tom de Vries (3):
[gdb] Re-indent regformats/regdat.sh
[gdb] Use shfmt on regformats/regdat.sh
[gdb] Use shfmt --simplify on regformats/regdat.sh
gdb/regformats/regdat.sh | 155 +++++++++++++++++++--------------------
1 file changed, 77 insertions(+), 78 deletions(-)
base-commit: 85a9f9eafebd99447e70e608246bc1d275e44d37
--
2.51.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/3] [gdb] Re-indent regformats/regdat.sh
2026-08-30 19:53 [PATCH v2 0/3] [gdb] Reformat regformats/regdat.sh Tom de Vries
@ 2026-08-30 19:53 ` Tom de Vries
2026-08-31 20:09 ` Simon Marchi
2026-08-30 19:53 ` [PATCH v2 2/3] [gdb] Use shfmt on regformats/regdat.sh Tom de Vries
2026-08-30 19:53 ` [PATCH v2 3/3] [gdb] Use shfmt --simplify " Tom de Vries
2 siblings, 1 reply; 9+ messages in thread
From: Tom de Vries @ 2026-08-30 19:53 UTC (permalink / raw)
To: gdb-patches
The script gdb/regformats/regdat.sh has inconsistent indentation: both 2 and 4
spaces.
Standardize to 4 spaces (as specified by .editorconfig), and document this
explicitly using a Local Variables setting, copied from
gdb/contrib/expect-read1.sh.
---
gdb/regformats/regdat.sh | 122 ++++++++++++++++++++-------------------
1 file changed, 64 insertions(+), 58 deletions(-)
diff --git a/gdb/regformats/regdat.sh b/gdb/regformats/regdat.sh
index f93270ba0ca..2f48c165fc8 100755
--- a/gdb/regformats/regdat.sh
+++ b/gdb/regformats/regdat.sh
@@ -73,13 +73,13 @@ EOF
}
if test ! -r "$1"; then
- echo "$0: Could not open $1." 1>&2
- exit 1
+ echo "$0: Could not open $1." 1>&2
+ exit 1
fi
copyright ()
{
-cat <<EOF
+ cat <<EOF
/* *INDENT-OFF* */ /* THIS FILE IS GENERATED */
/* A register protocol for GDB, the GNU debugger.
@@ -123,49 +123,49 @@ osabi=unknown
exec < "$1"
while do_read
do
- if test "${type}" = "name"; then
- name="${entry}"
-
- echo "const_target_desc_up tdesc_${name};"
- echo ""
-
- # This is necessary for -Wmissing-declarations.
- echo "void init_registers_${name} (void);"
-
- echo "void"
- echo "init_registers_${name} (void)"
- echo "{"
- echo " target_desc_up result = allocate_target_description ();"
- echo " struct tdesc_feature *feature = tdesc_create_feature (result.get (), \"${name}\");"
- continue
- elif test "${type}" = "xmltarget"; then
- xmltarget="${entry}"
- continue
- elif test "${type}" = "xmlarch"; then
- xmlarch="${entry}"
- continue
- elif test "${type}" = "xmlosabi"; then
- xmlosabi="${entry}"
- continue
- elif test "${type}" = "expedite"; then
- expedite="${entry}"
- continue
- elif test "${type}" = "feature"; then
- feature="${entry}"
- continue
- elif test "${type}" = "osabi"; then
- osabi="${entry}"
- continue
- elif test "${name}" = x; then
- echo "$0: $1 does not specify \`\`name''." 1>&2
- exit 1
- else
- echo " tdesc_create_reg (feature, \"${entry}\","
- echo " 0, 0, NULL, ${type}, NULL);"
+ if test "${type}" = "name"; then
+ name="${entry}"
+
+ echo "const_target_desc_up tdesc_${name};"
+ echo ""
+
+ # This is necessary for -Wmissing-declarations.
+ echo "void init_registers_${name} (void);"
+
+ echo "void"
+ echo "init_registers_${name} (void)"
+ echo "{"
+ echo " target_desc_up result = allocate_target_description ();"
+ echo " struct tdesc_feature *feature = tdesc_create_feature (result.get (), \"${name}\");"
+ continue
+ elif test "${type}" = "xmltarget"; then
+ xmltarget="${entry}"
+ continue
+ elif test "${type}" = "xmlarch"; then
+ xmlarch="${entry}"
+ continue
+ elif test "${type}" = "xmlosabi"; then
+ xmlosabi="${entry}"
+ continue
+ elif test "${type}" = "expedite"; then
+ expedite="${entry}"
+ continue
+ elif test "${type}" = "feature"; then
+ feature="${entry}"
+ continue
+ elif test "${type}" = "osabi"; then
+ osabi="${entry}"
+ continue
+ elif test "${name}" = x; then
+ echo "$0: $1 does not specify \`\`name''." 1>&2
+ exit 1
+ else
+ echo " tdesc_create_reg (feature, \"${entry}\","
+ echo " 0, 0, NULL, ${type}, NULL);"
- offset=$((offset + type))
- i=$((i + 1))
- fi
+ offset=$((offset + type))
+ i=$((i + 1))
+ fi
done
echo
@@ -173,22 +173,22 @@ echo "static const char *expedite_regs_${name}[] = { \"$(echo "${expedite}" | se
echo "#ifndef IN_PROCESS_AGENT"
if test "${feature}" != x; then
- echo "static const char *xmltarget_${name} = 0;"
-elif test "${xmltarget}" = x; then
- if test "${xmlarch}" = x && test "${xmlosabi}" = x; then
echo "static const char *xmltarget_${name} = 0;"
- else
- echo "static const char *xmltarget_${name} = \"@<target>\\"
- if test "${xmlarch}" != x; then
- echo "<architecture>${xmlarch}</architecture>\\"
- fi
- if test "${xmlosabi}" != x; then
- echo "<osabi>${xmlosabi}</osabi>\\"
+elif test "${xmltarget}" = x; then
+ if test "${xmlarch}" = x && test "${xmlosabi}" = x; then
+ echo "static const char *xmltarget_${name} = 0;"
+ else
+ echo "static const char *xmltarget_${name} = \"@<target>\\"
+ if test "${xmlarch}" != x; then
+ echo "<architecture>${xmlarch}</architecture>\\"
+ fi
+ if test "${xmlosabi}" != x; then
+ echo "<osabi>${xmlosabi}</osabi>\\"
+ fi
+ echo "</target>\";"
fi
- echo "</target>\";"
- fi
else
- echo "static const char *xmltarget_${name} = \"${xmltarget}\";"
+ echo "static const char *xmltarget_${name} = \"${xmltarget}\";"
fi
echo
@@ -207,3 +207,9 @@ EOF
# close things off
exec 1>&2
mv -- "new-$3" "$3"
+
+# Local Variables:
+# mode:shell-script
+# sh-indentation:4
+# End:
+# vi:sw=4
--
2.51.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 2/3] [gdb] Use shfmt on regformats/regdat.sh
2026-08-30 19:53 [PATCH v2 0/3] [gdb] Reformat regformats/regdat.sh Tom de Vries
2026-08-30 19:53 ` [PATCH v2 1/3] [gdb] Re-indent regformats/regdat.sh Tom de Vries
@ 2026-08-30 19:53 ` Tom de Vries
2026-08-31 20:13 ` Simon Marchi
2026-08-30 19:53 ` [PATCH v2 3/3] [gdb] Use shfmt --simplify " Tom de Vries
2 siblings, 1 reply; 9+ messages in thread
From: Tom de Vries @ 2026-08-30 19:53 UTC (permalink / raw)
To: gdb-patches
Run shfmt [1] on gdb/regformats/regdat.sh:
...
$ shfmt \
--language-dialect=posix \
--indent=4 \
--func-next-line \
--space-redirects \
--write \
gdb/regformats/regdat.sh
...
followed by emacs whitespace-cleanup (because shfmt doesn't know about mixed
tab/spaces indentation).
Normalizes things like:
...
if true
then
...
to:
...
if true; then
...
as suggested by Simon [2].
Also:
- makes sure statements are on their own line
- removes double empty line
- minor whitespace changes:
- do_read () -> do_read()
- cat <<EOF -> cat << EOF
[1] https://github.com/mvdan/sh
[2] https://sourceware.org/pipermail/gdb-patches/2026-August/229818.html
---
gdb/regformats/regdat.sh | 35 ++++++++++++++---------------------
1 file changed, 14 insertions(+), 21 deletions(-)
diff --git a/gdb/regformats/regdat.sh b/gdb/regformats/regdat.sh
index 2f48c165fc8..6cac186735e 100755
--- a/gdb/regformats/regdat.sh
+++ b/gdb/regformats/regdat.sh
@@ -23,17 +23,14 @@ set -u
# Format of the input files
read="type entry"
-do_read ()
+do_read()
{
type=""
entry=""
- while read -r line
- do
- if test "${line}" = ""
- then
+ while read -r line; do
+ if test "${line}" = ""; then
continue
- elif expr "${line}" : "#" > /dev/null
- then
+ elif expr "${line}" : "#" > /dev/null; then
continue
else
@@ -42,21 +39,20 @@ do_read ()
# Work around this by eliminating ``::'' ....
line="$(echo "${line}" | sed -e 's/::/: :/g' -e 's/::/: :/g')"
- OFS="${IFS}" ; IFS="[:]"
+ OFS="${IFS}"
+ IFS="[:]"
# Word-splitting on read variable is required.
# shellcheck disable=SC2086
- eval read ${read} <<EOF
+ eval read ${read} << EOF
${line}
EOF
IFS="${OFS}"
# .... and then going back through each field and strip out those
# that ended up with just that space character.
- for r in ${read}
- do
+ for r in ${read}; do
eval "rvalue=\$$r"
- if test "${rvalue:-}" = " "
- then
+ if test "${rvalue:-}" = " "; then
eval "$r=''"
fi
done
@@ -64,8 +60,7 @@ EOF
break
fi
done
- if [ -n "${type}" ]
- then
+ if [ -n "${type}" ]; then
true
else
false
@@ -77,9 +72,9 @@ if test ! -r "$1"; then
exit 1
fi
-copyright ()
+copyright()
{
- cat <<EOF
+ cat << EOF
/* *INDENT-OFF* */ /* THIS FILE IS GENERATED */
/* A register protocol for GDB, the GNU debugger.
@@ -105,7 +100,6 @@ copyright ()
EOF
}
-
exec > new-"$3"
copyright "$1"
echo '#include "regdef.h"'
@@ -121,8 +115,7 @@ expedite=x
feature=x
osabi=unknown
exec < "$1"
-while do_read
-do
+while do_read; do
if test "${type}" = "name"; then
name="${entry}"
@@ -194,7 +187,7 @@ echo
osabi_enum=$(grep "${osabi}" "$2" | sed 's/.*(\([^,]\+\),.*/GDB_OSABI_\1/')
-cat <<EOF
+cat << EOF
result->xmltarget = xmltarget_${name};
#endif
--
2.51.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 3/3] [gdb] Use shfmt --simplify on regformats/regdat.sh
2026-08-30 19:53 [PATCH v2 0/3] [gdb] Reformat regformats/regdat.sh Tom de Vries
2026-08-30 19:53 ` [PATCH v2 1/3] [gdb] Re-indent regformats/regdat.sh Tom de Vries
2026-08-30 19:53 ` [PATCH v2 2/3] [gdb] Use shfmt on regformats/regdat.sh Tom de Vries
@ 2026-08-30 19:53 ` Tom de Vries
2026-08-31 20:14 ` Simon Marchi
2 siblings, 1 reply; 9+ messages in thread
From: Tom de Vries @ 2026-08-30 19:53 UTC (permalink / raw)
To: gdb-patches
Use shfmt on gdb/regformats/regdat.sh as in the previous commit, but also use
--simplify.
---
gdb/regformats/regdat.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdb/regformats/regdat.sh b/gdb/regformats/regdat.sh
index 6cac186735e..486fc0e85ea 100755
--- a/gdb/regformats/regdat.sh
+++ b/gdb/regformats/regdat.sh
@@ -178,7 +178,7 @@ elif test "${xmltarget}" = x; then
if test "${xmlosabi}" != x; then
echo "<osabi>${xmlosabi}</osabi>\\"
fi
- echo "</target>\";"
+ echo '</target>";'
fi
else
echo "static const char *xmltarget_${name} = \"${xmltarget}\";"
--
2.51.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/3] [gdb] Re-indent regformats/regdat.sh
2026-08-30 19:53 ` [PATCH v2 1/3] [gdb] Re-indent regformats/regdat.sh Tom de Vries
@ 2026-08-31 20:09 ` Simon Marchi
2026-09-01 9:21 ` Tom de Vries
0 siblings, 1 reply; 9+ messages in thread
From: Simon Marchi @ 2026-08-31 20:09 UTC (permalink / raw)
To: Tom de Vries, gdb-patches
On 8/30/26 3:53 PM, Tom de Vries wrote:
> The script gdb/regformats/regdat.sh has inconsistent indentation: both 2 and 4
> spaces.
>
> Standardize to 4 spaces (as specified by .editorconfig), and document this
> explicitly using a Local Variables setting, copied from
> gdb/contrib/expect-read1.sh.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
LGTM, but I wonder why the local variables setting is needed, since we
have .editorconfig? For instance, we don't put that in every .c file...
I am not strongly opposed to it, but it seems redundant and less
maintainable to repeat the information in each file.
Simon
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/3] [gdb] Use shfmt on regformats/regdat.sh
2026-08-30 19:53 ` [PATCH v2 2/3] [gdb] Use shfmt on regformats/regdat.sh Tom de Vries
@ 2026-08-31 20:13 ` Simon Marchi
2026-09-02 13:21 ` Tom de Vries
0 siblings, 1 reply; 9+ messages in thread
From: Simon Marchi @ 2026-08-31 20:13 UTC (permalink / raw)
To: Tom de Vries, gdb-patches
On 8/30/26 3:53 PM, Tom de Vries wrote:
> Run shfmt [1] on gdb/regformats/regdat.sh:
> ...
> $ shfmt \
> --language-dialect=posix \
> --indent=4 \
> --func-next-line \
> --space-redirects \
> --write \
> gdb/regformats/regdat.sh
It would be nice to have a script to easily do this on all our shell
scripts, which we could also run in the CI (like we run black to verify
the Python code formatting).
> ...
> followed by emacs whitespace-cleanup (because shfmt doesn't know about mixed
> tab/spaces indentation).
I guess said script would need to do this too (I wonder if it can be
done with sed, replacing leading groups of 8 spaces with a tab).
> Normalizes things like:
> ...
> if true
> then
> ...
> to:
> ...
> if true; then
> ...
> as suggested by Simon [2].
>
> Also:
> - makes sure statements are on their own line
> - removes double empty line
> - minor whitespace changes:
> - do_read () -> do_read()
> - cat <<EOF -> cat << EOF
>
> [1] https://github.com/mvdan/sh
> [2] https://sourceware.org/pipermail/gdb-patches/2026-August/229818.html
All the changes in the diff LGTM.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Simon
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/3] [gdb] Use shfmt --simplify on regformats/regdat.sh
2026-08-30 19:53 ` [PATCH v2 3/3] [gdb] Use shfmt --simplify " Tom de Vries
@ 2026-08-31 20:14 ` Simon Marchi
0 siblings, 0 replies; 9+ messages in thread
From: Simon Marchi @ 2026-08-31 20:14 UTC (permalink / raw)
To: Tom de Vries, gdb-patches
On 8/30/26 3:53 PM, Tom de Vries wrote:
> Use shfmt on gdb/regformats/regdat.sh as in the previous commit, but also use
> --simplify.
> ---
> gdb/regformats/regdat.sh | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gdb/regformats/regdat.sh b/gdb/regformats/regdat.sh
> index 6cac186735e..486fc0e85ea 100755
> --- a/gdb/regformats/regdat.sh
> +++ b/gdb/regformats/regdat.sh
> @@ -178,7 +178,7 @@ elif test "${xmltarget}" = x; then
> if test "${xmlosabi}" != x; then
> echo "<osabi>${xmlosabi}</osabi>\\"
> fi
> - echo "</target>\";"
> + echo '</target>";'
> fi
> else
> echo "static const char *xmltarget_${name} = \"${xmltarget}\";"
LGTM.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Simon
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/3] [gdb] Re-indent regformats/regdat.sh
2026-08-31 20:09 ` Simon Marchi
@ 2026-09-01 9:21 ` Tom de Vries
0 siblings, 0 replies; 9+ messages in thread
From: Tom de Vries @ 2026-09-01 9:21 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
On 8/31/26 10:09 PM, Simon Marchi wrote:
> On 8/30/26 3:53 PM, Tom de Vries wrote:
>> The script gdb/regformats/regdat.sh has inconsistent indentation: both 2 and 4
>> spaces.
>>
>> Standardize to 4 spaces (as specified by .editorconfig), and document this
>> explicitly using a Local Variables setting, copied from
>> gdb/contrib/expect-read1.sh.
>
> Approved-By: Simon Marchi <simon.marchi@efficios.com>
>
> LGTM, but I wonder why the local variables setting is needed, since we
> have .editorconfig? For instance, we don't put that in every .c file...
> I am not strongly opposed to it, but it seems redundant and less
> maintainable to repeat the information in each file.
>
Hi Simon,
thanks for the reviews.
I've pushed this, without the local variables part.
Instead I've submitted a patch to add a setting in .dir-locals.el (
https://sourceware.org/pipermail/gdb-patches/2026-September/229895.html ).
Thanks,
- Tom
> Simon
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/3] [gdb] Use shfmt on regformats/regdat.sh
2026-08-31 20:13 ` Simon Marchi
@ 2026-09-02 13:21 ` Tom de Vries
0 siblings, 0 replies; 9+ messages in thread
From: Tom de Vries @ 2026-09-02 13:21 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
On 8/31/26 10:13 PM, Simon Marchi wrote:
> It would be nice to have a script to easily do this on all our shell
> scripts, which we could also run in the CI (like we run black to verify
> the Python code formatting).
>
I've submitted an RFC (
https://sourceware.org/pipermail/gdb-patches/2026-September/229953.html ).
>> ...
>> followed by emacs whitespace-cleanup (because shfmt doesn't know about mixed
>> tab/spaces indentation).
> I guess said script would need to do this too (I wonder if it can be
> done with sed, replacing leading groups of 8 spaces with a tab).
I found a tool unexpand, to I've used that.
Thanks,
- Tom
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-09-02 13:21 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-30 19:53 [PATCH v2 0/3] [gdb] Reformat regformats/regdat.sh Tom de Vries
2026-08-30 19:53 ` [PATCH v2 1/3] [gdb] Re-indent regformats/regdat.sh Tom de Vries
2026-08-31 20:09 ` Simon Marchi
2026-09-01 9:21 ` Tom de Vries
2026-08-30 19:53 ` [PATCH v2 2/3] [gdb] Use shfmt on regformats/regdat.sh Tom de Vries
2026-08-31 20:13 ` Simon Marchi
2026-09-02 13:21 ` Tom de Vries
2026-08-30 19:53 ` [PATCH v2 3/3] [gdb] Use shfmt --simplify " Tom de Vries
2026-08-31 20:14 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox