Commit 3af8acf6 authored by Schspa Shi's avatar Schspa Shi Committed by akpm

scripts/decode_stacktrace.sh: support old bash version

Old bash version don't support associative array variables.  Avoid to use
associative array variables to avoid error.

Without this, old bash version will report error as fellowing
[   15.954042] Kernel panic - not syncing: sysrq triggered crash
[   15.955252] CPU: 1 PID: 167 Comm: sh Not tainted 5.18.0-rc1-00208-gb7d075db2fd5 #4
[   15.956472] Hardware name: Hobot J5 Virtual development board (DT)
[   15.957856] Call trace:
./scripts/decode_stacktrace.sh: line 128: ,dump_backtrace: syntax error: operand expected (error token is ",dump_backtrace")

Link: https://lkml.kernel.org/r/20220409180331.24047-1-schspa@gmail.comSigned-off-by: default avatarSchspa Shi <schspa@gmail.com>
Cc: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent bd7155a0
...@@ -45,8 +45,13 @@ else ...@@ -45,8 +45,13 @@ else
fi fi
fi fi
declare -A cache declare aarray_support=true
declare -A modcache declare -A cache 2>/dev/null
if [[ $? != 0 ]]; then
aarray_support=false
else
declare -A modcache
fi
find_module() { find_module() {
if [[ -n $debuginfod ]] ; then if [[ -n $debuginfod ]] ; then
...@@ -97,7 +102,7 @@ parse_symbol() { ...@@ -97,7 +102,7 @@ parse_symbol() {
if [[ $module == "" ]] ; then if [[ $module == "" ]] ; then
local objfile=$vmlinux local objfile=$vmlinux
elif [[ "${modcache[$module]+isset}" == "isset" ]]; then elif [[ $aarray_support == true && "${modcache[$module]+isset}" == "isset" ]]; then
local objfile=${modcache[$module]} local objfile=${modcache[$module]}
else else
local objfile=$(find_module) local objfile=$(find_module)
...@@ -105,8 +110,10 @@ parse_symbol() { ...@@ -105,8 +110,10 @@ parse_symbol() {
echo "WARNING! Modules path isn't set, but is needed to parse this symbol" >&2 echo "WARNING! Modules path isn't set, but is needed to parse this symbol" >&2
return return
fi fi
if [[ $aarray_support == true ]]; then
modcache[$module]=$objfile modcache[$module]=$objfile
fi fi
fi
# Remove the englobing parenthesis # Remove the englobing parenthesis
symbol=${symbol#\(} symbol=${symbol#\(}
...@@ -125,7 +132,7 @@ parse_symbol() { ...@@ -125,7 +132,7 @@ parse_symbol() {
# Use 'nm vmlinux' to figure out the base address of said symbol. # Use 'nm vmlinux' to figure out the base address of said symbol.
# It's actually faster to call it every time than to load it # It's actually faster to call it every time than to load it
# all into bash. # all into bash.
if [[ "${cache[$module,$name]+isset}" == "isset" ]]; then if [[ $aarray_support == true && "${cache[$module,$name]+isset}" == "isset" ]]; then
local base_addr=${cache[$module,$name]} local base_addr=${cache[$module,$name]}
else else
local base_addr=$(nm "$objfile" 2>/dev/null | awk '$3 == "'$name'" && ($2 == "t" || $2 == "T") {print $1; exit}') local base_addr=$(nm "$objfile" 2>/dev/null | awk '$3 == "'$name'" && ($2 == "t" || $2 == "T") {print $1; exit}')
...@@ -133,8 +140,10 @@ parse_symbol() { ...@@ -133,8 +140,10 @@ parse_symbol() {
# address not found # address not found
return return
fi fi
if [[ $aarray_support == true ]]; then
cache[$module,$name]="$base_addr" cache[$module,$name]="$base_addr"
fi fi
fi
# Let's start doing the math to get the exact address into the # Let's start doing the math to get the exact address into the
# symbol. First, strip out the symbol total length. # symbol. First, strip out the symbol total length.
local expr=${symbol%/*} local expr=${symbol%/*}
...@@ -149,12 +158,14 @@ parse_symbol() { ...@@ -149,12 +158,14 @@ parse_symbol() {
# Pass it to addr2line to get filename and line number # Pass it to addr2line to get filename and line number
# Could get more than one result # Could get more than one result
if [[ "${cache[$module,$address]+isset}" == "isset" ]]; then if [[ $aarray_support == true && "${cache[$module,$address]+isset}" == "isset" ]]; then
local code=${cache[$module,$address]} local code=${cache[$module,$address]}
else else
local code=$(${CROSS_COMPILE}addr2line -i -e "$objfile" "$address" 2>/dev/null) local code=$(${CROSS_COMPILE}addr2line -i -e "$objfile" "$address" 2>/dev/null)
if [[ $aarray_support == true ]]; then
cache[$module,$address]=$code cache[$module,$address]=$code
fi fi
fi
# addr2line doesn't return a proper error code if it fails, so # addr2line doesn't return a proper error code if it fails, so
# we detect it using the value it prints so that we could preserve # we detect it using the value it prints so that we could preserve
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment