Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] [gdb] Use shfmt on regformats/regdat.sh
@ 2026-08-28 14:12 Tom de Vries
  2026-08-30 19:54 ` Tom de Vries
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2026-08-28 14:12 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:
- fixes up inconsistent indentation
- 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 | 149 +++++++++++++++++++--------------------
 1 file changed, 71 insertions(+), 78 deletions(-)

diff --git a/gdb/regformats/regdat.sh b/gdb/regformats/regdat.sh
index f93270ba0ca..0df4d07c44b 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
@@ -73,13 +68,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 ()
+copyright()
 {
-cat <<EOF
+    cat << EOF
 /* *INDENT-OFF* */ /* THIS FILE IS GENERATED */
 
 /* A register protocol for GDB, the GNU debugger.
@@ -105,7 +100,6 @@ cat <<EOF
 EOF
 }
 
-
 exec > new-"$3"
 copyright "$1"
 echo '#include "regdef.h"'
@@ -121,51 +115,50 @@ expedite=x
 feature=x
 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);"
+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);"
 
-    offset=$((offset + type))
-    i=$((i + 1))
-  fi
+	offset=$((offset + type))
+	i=$((i + 1))
+    fi
 done
 
 echo
@@ -173,28 +166,28 @@ 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
 
 osabi_enum=$(grep "${osabi}" "$2" | sed 's/.*(\([^,]\+\),.*/GDB_OSABI_\1/')
 
-cat <<EOF
+cat << EOF
   result->xmltarget = xmltarget_${name};
 #endif
 

base-commit: 5d09165a3e9c8d32742fc764e98e927950f7b2f5
-- 
2.51.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] [gdb] Use shfmt on regformats/regdat.sh
  2026-08-28 14:12 [PATCH] [gdb] Use shfmt on regformats/regdat.sh Tom de Vries
@ 2026-08-30 19:54 ` Tom de Vries
  0 siblings, 0 replies; 2+ messages in thread
From: Tom de Vries @ 2026-08-30 19:54 UTC (permalink / raw)
  To: gdb-patches

On 8/28/26 4:12 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
> ...
> 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:
> - fixes up inconsistent indentation

I've submitted a v2 ( 
https://sourceware.org/pipermail/gdb-patches/2026-August/229844.html ) 
that splits off this part into a separate patch, for easier review.

Thanks,
- TOm

> - 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 | 149 +++++++++++++++++++--------------------
>   1 file changed, 71 insertions(+), 78 deletions(-)
> 
> diff --git a/gdb/regformats/regdat.sh b/gdb/regformats/regdat.sh
> index f93270ba0ca..0df4d07c44b 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
> @@ -73,13 +68,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 ()
> +copyright()
>   {
> -cat <<EOF
> +    cat << EOF
>   /* *INDENT-OFF* */ /* THIS FILE IS GENERATED */
>   
>   /* A register protocol for GDB, the GNU debugger.
> @@ -105,7 +100,6 @@ cat <<EOF
>   EOF
>   }
>   
> -
>   exec > new-"$3"
>   copyright "$1"
>   echo '#include "regdef.h"'
> @@ -121,51 +115,50 @@ expedite=x
>   feature=x
>   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);"
> +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);"
>   
> -    offset=$((offset + type))
> -    i=$((i + 1))
> -  fi
> +	offset=$((offset + type))
> +	i=$((i + 1))
> +    fi
>   done
>   
>   echo
> @@ -173,28 +166,28 @@ 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
>   
>   osabi_enum=$(grep "${osabi}" "$2" | sed 's/.*(\([^,]\+\),.*/GDB_OSABI_\1/')
>   
> -cat <<EOF
> +cat << EOF
>     result->xmltarget = xmltarget_${name};
>   #endif
>   
> 
> base-commit: 5d09165a3e9c8d32742fc764e98e927950f7b2f5


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-30 19:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-28 14:12 [PATCH] [gdb] Use shfmt on regformats/regdat.sh Tom de Vries
2026-08-30 19:54 ` 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