VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   33 Branches   55 Tags
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400   1) #!/bin/bash
b24413180f560 (Greg Kroah-Hartman    2017-11-01 15:07:57 +0100   2) # SPDX-License-Identifier: GPL-2.0
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400   3) # (c) 2014, Sasha Levin <sasha.levin@oracle.com>
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400   4) #set -x
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400   5) 
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700   6) usage() {
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400   7) 	echo "Usage:"
d5ce757d8f1bd (Stephen Boyd          2021-07-07 18:09:38 -0700   8) 	echo "	$0 -r <release> | <vmlinux> [<base path>|auto] [<modules path>]"
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700   9) }
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400  10) 
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  11) if [[ $1 == "-r" ]] ; then
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  12) 	vmlinux=""
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  13) 	basepath="auto"
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  14) 	modpath=""
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  15) 	release=$2
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  16) 
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  17) 	for fn in {,/usr/lib/debug}/boot/vmlinux-$release{,.debug} /lib/modules/$release{,/build}/vmlinux ; do
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  18) 		if [ -e "$fn" ] ; then
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  19) 			vmlinux=$fn
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  20) 			break
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  21) 		fi
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  22) 	done
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  23) 
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  24) 	if [[ $vmlinux == "" ]] ; then
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  25) 		echo "ERROR! vmlinux image for release $release is not found" >&2
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  26) 		usage
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  27) 		exit 2
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  28) 	fi
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  29) else
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  30) 	vmlinux=$1
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  31) 	basepath=${2-auto}
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  32) 	modpath=$3
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  33) 	release=""
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  34) 	debuginfod=
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  35) 
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  36) 	# Can we use debuginfod-find?
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  37) 	if type debuginfod-find >/dev/null 2>&1 ; then
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  38) 		debuginfod=${1-only}
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  39) 	fi
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  40) 
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  41) 	if [[ $vmlinux == "" && -z $debuginfod ]] ; then
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  42) 		echo "ERROR! vmlinux image must be specified" >&2
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  43) 		usage
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  44) 		exit 1
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  45) 	fi
f90dde44c57a1 (Konstantin Khlebnikov 2020-08-06 23:17:43 -0700  46) fi
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  47) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400  48) declare -A cache
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700  49) declare -A modcache
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400  50) 
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  51) find_module() {
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  52) 	if [[ -n $debuginfod ]] ; then
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  53) 		if [[ -n $modbuildid ]] ; then
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  54) 			debuginfod-find debuginfo $modbuildid && return
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  55) 		fi
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  56) 
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  57) 		# Only using debuginfod so don't try to find vmlinux module path
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  58) 		if [[ $debuginfod == "only" ]] ; then
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  59) 			return
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  60) 		fi
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  61) 	fi
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700  62) 
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  63) 	if [[ "$modpath" != "" ]] ; then
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  64) 		for fn in $(find "$modpath" -name "${module//_/[-_]}.ko*") ; do
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  65) 			if readelf -WS "$fn" | grep -qwF .debug_line ; then
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  66) 				echo $fn
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  67) 				return
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  68) 			fi
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  69) 		done
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  70) 		return 1
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  71) 	fi
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  72) 
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  73) 	modpath=$(dirname "$vmlinux")
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  74) 	find_module && return
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  75) 
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  76) 	if [[ $release == "" ]] ; then
5bf0f3bc377e5 (Stephen Boyd          2021-07-07 18:09:35 -0700  77) 		release=$(gdb -ex 'print init_uts_ns.name.release' -ex 'quit' -quiet -batch "$vmlinux" 2>/dev/null | sed -n 's/\$1 = "\(.*\)".*/\1/p')
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  78) 	fi
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  79) 
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  80) 	for dn in {/usr/lib/debug,}/lib/modules/$release ; do
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  81) 		if [ -e "$dn" ] ; then
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  82) 			modpath="$dn"
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  83) 			find_module && return
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  84) 		fi
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  85) 	done
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  86) 
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  87) 	modpath=""
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  88) 	return 1
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  89) }
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700  90) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400  91) parse_symbol() {
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400  92) 	# The structure of symbol at this point is:
e260fe01fa39e (Robert Jarzmik        2015-09-04 15:43:26 -0700  93) 	#   ([name]+[offset]/[total length])
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400  94) 	#
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400  95) 	# For example:
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400  96) 	#   do_basic_setup+0x9c/0xbf
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400  97) 
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700  98) 	if [[ $module == "" ]] ; then
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700  99) 		local objfile=$vmlinux
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 100) 	elif [[ "${modcache[$module]+isset}" == "isset" ]]; then
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 101) 		local objfile=${modcache[$module]}
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 102) 	else
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700 103) 		local objfile=$(find_module)
431151b64af6c (Konstantin Khlebnikov 2020-08-06 23:17:41 -0700 104) 		if [[ $objfile == "" ]] ; then
a5dc8300df75e (Sasha Levin           2020-06-15 18:24:27 -0400 105) 			echo "WARNING! Modules path isn't set, but is needed to parse this symbol" >&2
a5dc8300df75e (Sasha Levin           2020-06-15 18:24:27 -0400 106) 			return
a5dc8300df75e (Sasha Levin           2020-06-15 18:24:27 -0400 107) 		fi
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 108) 		modcache[$module]=$objfile
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 109) 	fi
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 110) 
e260fe01fa39e (Robert Jarzmik        2015-09-04 15:43:26 -0700 111) 	# Remove the englobing parenthesis
e260fe01fa39e (Robert Jarzmik        2015-09-04 15:43:26 -0700 112) 	symbol=${symbol#\(}
e260fe01fa39e (Robert Jarzmik        2015-09-04 15:43:26 -0700 113) 	symbol=${symbol%\)}
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 114) 
1d6693fb9d157 (Konstantin Khlebnikov 2019-03-05 15:41:34 -0800 115) 	# Strip segment
1d6693fb9d157 (Konstantin Khlebnikov 2019-03-05 15:41:34 -0800 116) 	local segment
1d6693fb9d157 (Konstantin Khlebnikov 2019-03-05 15:41:34 -0800 117) 	if [[ $symbol == *:* ]] ; then
1d6693fb9d157 (Konstantin Khlebnikov 2019-03-05 15:41:34 -0800 118) 		segment=${symbol%%:*}:
1d6693fb9d157 (Konstantin Khlebnikov 2019-03-05 15:41:34 -0800 119) 		symbol=${symbol#*:}
1d6693fb9d157 (Konstantin Khlebnikov 2019-03-05 15:41:34 -0800 120) 	fi
1d6693fb9d157 (Konstantin Khlebnikov 2019-03-05 15:41:34 -0800 121) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 122) 	# Strip the symbol name so that we could look it up
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 123) 	local name=${symbol%+*}
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 124) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 125) 	# Use 'nm vmlinux' to figure out the base address of said symbol.
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 126) 	# It's actually faster to call it every time than to load it
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 127) 	# all into bash.
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 128) 	if [[ "${cache[$module,$name]+isset}" == "isset" ]]; then
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 129) 		local base_addr=${cache[$module,$name]}
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 130) 	else
5bf0f3bc377e5 (Stephen Boyd          2021-07-07 18:09:35 -0700 131) 		local base_addr=$(nm "$objfile" 2>/dev/null | awk '$3 == "'$name'" && ($2 == "t" || $2 == "T") {print $1; exit}')
f643b9ee97766 (Konstantin Khlebnikov 2020-08-06 23:17:35 -0700 132) 		if [[ $base_addr == "" ]] ; then
f643b9ee97766 (Konstantin Khlebnikov 2020-08-06 23:17:35 -0700 133) 			# address not found
f643b9ee97766 (Konstantin Khlebnikov 2020-08-06 23:17:35 -0700 134) 			return
f643b9ee97766 (Konstantin Khlebnikov 2020-08-06 23:17:35 -0700 135) 		fi
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 136) 		cache[$module,$name]="$base_addr"
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 137) 	fi
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 138) 	# Let's start doing the math to get the exact address into the
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 139) 	# symbol. First, strip out the symbol total length.
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 140) 	local expr=${symbol%/*}
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 141) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 142) 	# Now, replace the symbol name with the base address we found
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 143) 	# before.
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 144) 	expr=${expr/$name/0x$base_addr}
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 145) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 146) 	# Evaluate it to find the actual address
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 147) 	expr=$((expr))
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 148) 	local address=$(printf "%x\n" "$expr")
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 149) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 150) 	# Pass it to addr2line to get filename and line number
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 151) 	# Could get more than one result
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 152) 	if [[ "${cache[$module,$address]+isset}" == "isset" ]]; then
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 153) 		local code=${cache[$module,$address]}
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 154) 	else
5bf0f3bc377e5 (Stephen Boyd          2021-07-07 18:09:35 -0700 155) 		local code=$(${CROSS_COMPILE}addr2line -i -e "$objfile" "$address" 2>/dev/null)
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 156) 		cache[$module,$address]=$code
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 157) 	fi
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 158) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 159) 	# addr2line doesn't return a proper error code if it fails, so
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 160) 	# we detect it using the value it prints so that we could preserve
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 161) 	# the offset/size into the function and bail out
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 162) 	if [[ $code == "??:0" ]]; then
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 163) 		return
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 164) 	fi
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 165) 
d178770d8d214 (Pi-Hsun Shih          2020-07-23 21:15:43 -0700 166) 	# Strip out the base of the path on each line
d178770d8d214 (Pi-Hsun Shih          2020-07-23 21:15:43 -0700 167) 	code=$(while read -r line; do echo "${line#$basepath/}"; done <<< "$code")
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 168) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 169) 	# In the case of inlines, move everything to same line
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 170) 	code=${code//$'\n'/' '}
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 171) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 172) 	# Replace old address with pretty line numbers
1d6693fb9d157 (Konstantin Khlebnikov 2019-03-05 15:41:34 -0800 173) 	symbol="$segment$name ($code)"
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 174) }
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 175) 
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 176) debuginfod_get_vmlinux() {
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 177) 	local vmlinux_buildid=${1##* }
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 178) 
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 179) 	if [[ $vmlinux != "" ]]; then
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 180) 		return
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 181) 	fi
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 182) 
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 183) 	if [[ $vmlinux_buildid =~ ^[0-9a-f]+ ]]; then
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 184) 		vmlinux=$(debuginfod-find debuginfo $vmlinux_buildid)
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 185) 		if [[ $? -ne 0 ]] ; then
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 186) 			echo "ERROR! vmlinux image not found via debuginfod-find" >&2
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 187) 			usage
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 188) 			exit 2
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 189) 		fi
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 190) 		return
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 191) 	fi
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 192) 	echo "ERROR! Build ID for vmlinux not found. Try passing -r or specifying vmlinux" >&2
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 193) 	usage
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 194) 	exit 2
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 195) }
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 196) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 197) decode_code() {
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 198) 	local scripts=`dirname "${BASH_SOURCE[0]}"`
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 199) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 200) 	echo "$1" | $scripts/decodecode
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 201) }
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 202) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 203) handle_line() {
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 204) 	if [[ $basepath == "auto" && $vmlinux != "" ]] ; then
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 205) 		module=""
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 206) 		symbol="kernel_init+0x0/0x0"
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 207) 		parse_symbol
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 208) 		basepath=${symbol#kernel_init (}
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 209) 		basepath=${basepath%/init/main.c:*)}
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 210) 	fi
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 211) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 212) 	local words
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 213) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 214) 	# Tokenize
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 215) 	read -a words <<<"$1"
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 216) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 217) 	# Remove hex numbers. Do it ourselves until it happens in the
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 218) 	# kernel
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 219) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 220) 	# We need to know the index of the last element before we
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 221) 	# remove elements because arrays are sparse
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 222) 	local last=$(( ${#words[@]} - 1 ))
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 223) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 224) 	for i in "${!words[@]}"; do
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 225) 		# Remove the address
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 226) 		if [[ ${words[$i]} =~ \[\<([^]]+)\>\] ]]; then
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 227) 			unset words[$i]
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 228) 		fi
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 229) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 230) 		# Format timestamps with tabs
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 231) 		if [[ ${words[$i]} == \[ && ${words[$i+1]} == *\] ]]; then
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 232) 			unset words[$i]
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 233) 			words[$i+1]=$(printf "[%13s\n" "${words[$i+1]}")
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 234) 		fi
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 235) 	done
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 236) 
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 237) 	if [[ ${words[$last]} =~ ^[0-9a-f]+\] ]]; then
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 238) 		words[$last-1]="${words[$last-1]} ${words[$last]}"
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 239) 		unset words[$last]
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 240) 		last=$(( $last - 1 ))
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 241) 	fi
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 242) 
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 243) 	if [[ ${words[$last]} =~ \[([^]]+)\] ]]; then
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 244) 		module=${words[$last]}
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 245) 		module=${module#\[}
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 246) 		module=${module%\]}
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 247) 		modbuildid=${module#* }
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 248) 		module=${module% *}
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 249) 		if [[ $modbuildid == $module ]]; then
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 250) 			modbuildid=
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 251) 		fi
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 252) 		symbol=${words[$last-1]}
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 253) 		unset words[$last-1]
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 254) 	else
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 255) 		# The symbol is the last element, process it
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 256) 		symbol=${words[$last]}
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 257) 		module=
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 258) 		modbuildid=
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 259) 	fi
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 260) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 261) 	unset words[$last]
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 262) 	parse_symbol # modifies $symbol
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 263) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 264) 	# Add up the line number to the symbol
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 265) 	echo "${words[@]}" "$symbol $module"
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 266) }
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 267) 
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 268) while read line; do
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 269) 	# Let's see if we have an address in the line
53938ee427bf2 (Josh Poimboeuf        2016-11-28 17:06:35 -0600 270) 	if [[ $line =~ \[\<([^]]+)\>\] ]] ||
53938ee427bf2 (Josh Poimboeuf        2016-11-28 17:06:35 -0600 271) 	   [[ $line =~ [^+\ ]+\+0x[0-9a-f]+/0x[0-9a-f]+ ]]; then
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 272) 		# Translate address to line numbers
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 273) 		handle_line "$line"
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 274) 	# Is it a code line?
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 275) 	elif [[ $line == *Code:* ]]; then
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 276) 		decode_code "$line"
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 277) 	# Is it a version line?
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 278) 	elif [[ -n $debuginfod && $line =~ PID:\ [0-9]+\ Comm: ]]; then
26681eb3724b6 (Stephen Boyd          2021-07-07 18:09:31 -0700 279) 		debuginfod_get_vmlinux "$line"
310c6dd06a0b3 (Konstantin Khlebnikov 2016-05-19 17:09:11 -0700 280) 	else
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 281) 		# Nothing special in this line, show it as is
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 282) 		echo "$line"
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 283) 	fi
dbd1abb209715 (Sasha Levin           2014-06-04 11:39:23 -0400 284) done