gdb-add-index.sh: Remove use of non posix 'local'

Message ID 20210326171454.2795-1-lsix@lancelotsix.com
State New
Headers show
Series
  • gdb-add-index.sh: Remove use of non posix 'local'
Related show

Commit Message

Luis Machado via Gdb-patches March 26, 2021, 5:14 p.m.
While working on gdb-add-index.sh, it appeared that it uses the non
POSIX 'local' keyword.  Instead of using local to allow variable
shadowing, I rename the local one to avoid name conflicts altogether.

gdb/ChangeLog:

	* contrib/gdb-add-index.sh: Avoid variable shadowing and get
	rid of 'local'.
---
 gdb/contrib/gdb-add-index.sh | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

-- 
2.30.1

Comments

Luis Machado via Gdb-patches March 26, 2021, 6:39 p.m. | #1
On 2021-03-26 1:14 p.m., Lancelot SIX via Gdb-patches wrote:
> While working on gdb-add-index.sh, it appeared that it uses the non

> POSIX 'local' keyword.  Instead of using local to allow variable

> shadowing, I rename the local one to avoid name conflicts altogether.


Thanks, this is OK.  You can also mention in the commit message that it
gets rid of this shellcheck warning:


In gdb-add-index.sh line 63:
    local file="$1"
    ^--------^ SC2039: In POSIX sh, 'local' is undefined.


Simon
Luis Machado via Gdb-patches March 26, 2021, 11:56 p.m. | #2
Le Fri, Mar 26, 2021 at 02:39:52PM -0400, Simon Marchi a écrit :
> On 2021-03-26 1:14 p.m., Lancelot SIX via Gdb-patches wrote:

> > While working on gdb-add-index.sh, it appeared that it uses the non

> > POSIX 'local' keyword.  Instead of using local to allow variable

> > shadowing, I rename the local one to avoid name conflicts altogether.

> 

> Thanks, this is OK.  You can also mention in the commit message that it

> gets rid of this shellcheck warning:

> 

> 

> In gdb-add-index.sh line 63:

>     local file="$1"

>     ^--------^ SC2039: In POSIX sh, 'local' is undefined.

> 

> 

> Simon


I have added this info to the commit message and pushed.

Thanks,
Lancelot.

Patch

diff --git a/gdb/contrib/gdb-add-index.sh b/gdb/contrib/gdb-add-index.sh
index 48a85136a4c..dfefc507001 100755
--- a/gdb/contrib/gdb-add-index.sh
+++ b/gdb/contrib/gdb-add-index.sh
@@ -73,13 +73,13 @@  fi
 
 set_files ()
 {
-    local file="$1"
+    fpath="$1"
 
-    index4="${file}.gdb-index"
-    index5="${file}.debug_names"
-    debugstr="${file}.debug_str"
-    debugstrmerge="${file}.debug_str.merge"
-    debugstrerr="${file}.debug_str.err"
+    index4="${fpath}.gdb-index"
+    index5="${fpath}.debug_names"
+    debugstr="${fpath}.debug_str"
+    debugstrmerge="${fpath}.debug_str.merge"
+    debugstrerr="${fpath}.debug_str.err"
 }
 
 tmp_files=
@@ -112,13 +112,12 @@  status=0
 
 handle_file ()
 {
-    local file
-    file="$1"
+    fpath="$1"
 
-    set_files "$file"
+    set_files "$fpath"
 
     if test -f "$index4" -a -f "$index5"; then
-	echo "$myname: Both index types were created for $file" 1>&2
+	echo "$myname: Both index types were created for $fpath" 1>&2
 	status=1
     elif test -f "$index4" -o -f "$index5"; then
 	if test -f "$index4"; then
@@ -131,7 +130,7 @@  handle_file ()
 	debugstradd=false
 	debugstrupdate=false
 	if test -s "$debugstr"; then
-	    if ! $OBJCOPY --dump-section .debug_str="$debugstrmerge" "$file" \
+	    if ! $OBJCOPY --dump-section .debug_str="$debugstrmerge" "$fpath" \
 		 /dev/null 2>$debugstrerr; then
 		cat >&2 $debugstrerr
 		exit 1
@@ -155,11 +154,11 @@  handle_file ()
 		   if $debugstrupdate; then \
 		       echo --update-section .debug_str="$debugstrmerge"; \
 		   fi) \
-		 "$file" "$file"
+		 "$fpath" "$fpath"
 
 	status=$?
     else
-	echo "$myname: No index was created for $file" 1>&2
+	echo "$myname: No index was created for $fpath" 1>&2
 	echo "$myname: [Was there no debuginfo? Was there already an index?]" \
 	     1>&2
     fi