GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — scripts/decode_stacktrace.sh: handle symbols in modules · diffuzor2a9/BPI-Router-Linux@310c6dd

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • scripts
    • decode_stacktrace.sh
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎scripts/decode_stacktrace.sh‎

Copy file name to clipboardExpand all lines: scripts/decode_stacktrace.sh
+39-16Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
# (c) 2014, Sasha Levin <[email protected]>
33
#set -x
44

5-
if [[ $# != 2 ]]; then
5+
if [[ $# < 2 ]]; then
66
echo "Usage:"
7-
echo " $0 [vmlinux] [base path]"
7+
echo " $0 [vmlinux] [base path] [modules path]"
88
exit 1
99
fi
1010

1111
vmlinux=$1
1212
basepath=$2
13+
modpath=$3
1314
declare -A cache
15+
declare -A modcache
1416

1517
parse_symbol() {
1618
# The structure of symbol at this point is:
@@ -19,6 +21,17 @@ parse_symbol() {
1921
# For example:
2022
# do_basic_setup+0x9c/0xbf
2123

24+
if [[ $module == "" ]] ; then
25+
local objfile=$vmlinux
26+
elif [[ "${modcache[$module]+isset}" == "isset" ]]; then
27+
local objfile=${modcache[$module]}
28+
else
29+
[[ $modpath == "" ]] && return
30+
local objfile=$(find "$modpath" -name $module.ko -print -quit)
31+
[[ $objfile == "" ]] && return
32+
modcache[$module]=$objfile
33+
fi
34+
2235
# Remove the englobing parenthesis
2336
symbol=${symbol#\(}
2437
symbol=${symbol%\)}
@@ -29,11 +42,11 @@ parse_symbol() {
2942
# Use 'nm vmlinux' to figure out the base address of said symbol.
3043
# It's actually faster to call it every time than to load it
3144
# all into bash.
32-
if [[ "${cache[$name]+isset}" == "isset" ]]; then
33-
local base_addr=${cache[$name]}
45+
if [[ "${cache[$module,$name]+isset}" == "isset" ]]; then
46+
local base_addr=${cache[$module,$name]}
3447
else
35-
local base_addr=$(nm "$vmlinux" | grep -i ' t ' | awk "/ $name\$/ {print \$1}" | head -n1)
36-
cache["$name"]="$base_addr"
48+
local base_addr=$(nm "$objfile" | grep -i ' t ' | awk "/ $name\$/ {print \$1}" | head -n1)
49+
cache[$module,$name]="$base_addr"
3750
fi
3851
# Let's start doing the math to get the exact address into the
3952
# symbol. First, strip out the symbol total length.
@@ -48,12 +61,12 @@ parse_symbol() {
4861
local address=$(printf "%x\n" "$expr")
4962

5063
# Pass it to addr2line to get filename and line number
51-
# Could get more than one result
52-
if [[ "${cache[$address]+isset}" == "isset" ]]; then
53-
local code=${cache[$address]}
64+
# Could get more than one result
65+
if [[ "${cache[$module,$address]+isset}" == "isset" ]]; then
66+
local code=${cache[$module,$address]}
5467
else
55-
local code=$(addr2line -i -e "$vmlinux" "$address")
56-
cache[$address]=$code
68+
local code=$(addr2line -i -e "$objfile" "$address")
69+
cache[$module,$address]=$code
5770
fi
5871

5972
# addr2line doesn't return a proper error code if it fails, so
@@ -105,13 +118,23 @@ handle_line() {
105118
fi
106119
done
107120

108-
# The symbol is the last element, process it
109-
symbol=${words[$last]}
121+
if [[ ${words[$last]} =~ \[([^]]+)\] ]]; then
122+
module=${words[$last]}
123+
module=${module#\[}
124+
module=${module%\]}
125+
symbol=${words[$last-1]}
126+
unset words[$last-1]
127+
else
128+
# The symbol is the last element, process it
129+
symbol=${words[$last]}
130+
module=
131+
fi
132+
110133
unset words[$last]
111134
parse_symbol # modifies $symbol
112135

113136
# Add up the line number to the symbol
114-
echo "${words[@]}" "$symbol"
137+
echo "${words[@]}" "$symbol $module"
115138
}
116139

117140
while read line; do
@@ -121,8 +144,8 @@ while read line; do
121144
handle_line "$line"
122145
# Is it a code line?
123146
elif [[ $line == *Code:* ]]; then
124-
decode_code "$line"
125-
else
147+
decode_code "$line"
148+
else
126149
# Nothing special in this line, show it as is
127150
echo "$line"
128151
fi

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.