From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id D60003894E60; Thu, 30 Apr 2020 00:37:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D60003894E60 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: fix shellcheck warnings SC2154 (referenced but not assigned) in gdbarch.sh X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 9fdb2916fec2833fd5c359c35916d2e632a06c23 X-Git-Newrev: 1207375d768ae2b901c3bea6543b610c461160dd Message-Id: <20200430003718.D60003894E60@sourceware.org> Date: Thu, 30 Apr 2020 00:37:18 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Apr 2020 00:37:18 -0000 https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1207375d768ae2b901c3bea6543b610c461160dd commit 1207375d768ae2b901c3bea6543b610c461160dd Author: Simon Marchi Date: Wed Apr 29 20:35:35 2020 -0400 gdb: fix shellcheck warnings SC2154 (referenced but not assigned) in gdbarch.sh Fix all instances of this kind of warning: In gdbarch.sh line 96: m ) staticdefault="${predefault}" ;; ^-----------^ SC2154: predefault is referenced but not assigned. These warnings appear because we are doing something a bit funky when reading the gdbarch fields. These variables are not assigned explicitly, but using some `eval` commands. I don't think there is so much we can fix about those warnings. To silence them, I've changed `${foo}` to `${foo:-}`. This tells the shell to substitute with an empty string if `foo` is not defined. This retains the current behavior, but the warnings go away. gdb/ChangeLog: * gdbarch.sh: Use ${foo:-} where shellcheck would report a "referenced but not assigned" warning. Diff: --- gdb/ChangeLog | 5 +++++ gdb/gdbarch.sh | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index dee9a6edd3b..eb6841640b9 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2020-04-29 Simon Marchi + + * gdbarch.sh: Use ${foo:-} where shellcheck would report a + "referenced but not assigned" warning. + 2020-04-29 Simon Marchi * gdbarch.sh: Remove code that sets fallbackdefault. diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh index 4e4cc827b89..24f8cdfe90b 100755 --- a/gdb/gdbarch.sh +++ b/gdb/gdbarch.sh @@ -75,7 +75,7 @@ ${line} EOF IFS="${OFS}" - if test -n "${garbage_at_eol}" + if test -n "${garbage_at_eol:-}" then echo "Garbage at end-of-line in ${line}" 1>&2 kill $$ @@ -93,19 +93,19 @@ EOF done case "${class}" in - m ) staticdefault="${predefault}" ;; + m ) staticdefault="${predefault:-}" ;; M ) staticdefault="0" ;; * ) test "${staticdefault}" || staticdefault=0 ;; esac case "${class}" in F | V | M ) - case "${invalid_p}" in + case "${invalid_p:-}" in "" ) if test -n "${predefault}" then #invalid_p="gdbarch->${function} == ${predefault}" - predicate="gdbarch->${function} != ${predefault}" + predicate="gdbarch->${function:-} != ${predefault}" elif class_is_variable_p then predicate="gdbarch->${function} != 0" @@ -139,7 +139,7 @@ EOF fallback_default_p () { - { [ -n "${postdefault}" ] && [ "x${invalid_p}" != "x0" ]; } \ + { [ -n "${postdefault:-}" ] && [ "x${invalid_p}" != "x0" ]; } \ || { [ -n "${predefault}" ] && [ "x${invalid_p}" = "x0" ]; } } @@ -1206,7 +1206,7 @@ exec > new-gdbarch.log function_list | while do_read do cat <= 2)\n" printf " fprintf_unfiltered (gdb_stdlog, \"gdbarch_%s called\\\\n\");\n" "$function" - if [ "x${actual}" = "x-" ] || [ "x${actual}" = "x" ] + if [ "x${actual:-}" = "x-" ] || [ "x${actual:-}" = "x" ] then if class_is_multiarch_p then