History

scripts/decode_stacktrace.sh: support debuginfod

Now that stacktraces contain the build ID information we can update this script to use debuginfod-find to locate the debuginfo for the vmlinux and modules automatically. This can replace the existing code that requires specifying a path to vmlinux or tries to find the vmlinux and modules automatically by using the release number. Work it into the script as a fallback option if the vmlinux isn't specified on the commandline.

Stephen Boyd committed 5 years ago

Commit 26681eb1 parent 9ef8af21 file · +70 −11Browse files

Showing the changes to scripts/decode_stacktrace.sh (1 of 1 file). Show all

Unified · Split

scripts/decode_stacktrace.sh+70−11
@@ -3,11 +3,10 @@ · 2 unmodified lines
33 # (c) 2014, Sasha Levin <sasha.levin@oracle.com>
44 #set -x
55
6−if [[ $# < 1 ]]; then
6+usage() {
77 echo "Usage:"
88 echo " $0 -r <release> | <vmlinux> [base path] [modules path]"
9− exit 1
10−fi
9+}
1110
1211 if [[ $1 == "-r" ]] ; then
1312 vmlinux=""
@@ -24,6 +23,7 @@ if [[ $1 == "-r" ]] ; then · 10 unmodified lines
2423
2524 if [[ $vmlinux == "" ]] ; then
2625 echo "ERROR! vmlinux image for release $release is not found" >&2
26+ usage
2727 exit 2
2828 fi
2929 else
@@ -31,12 +31,35 @@ else · 1 unmodified line
3131 basepath=${2-auto}
3232 modpath=$3
3333 release=""
34+ debuginfod=
35+
36+ # Can we use debuginfod-find?
37+ if type debuginfod-find >/dev/null 2>&1 ; then
38+ debuginfod=${1-only}
39+ fi
40+
41+ if [[ $vmlinux == "" && -z $debuginfod ]] ; then
42+ echo "ERROR! vmlinux image must be specified" >&2
43+ usage
44+ exit 1
45+ fi
3446 fi
3547
3648 declare -A cache
3749 declare -A modcache
3850
3951 find_module() {
52+ if [[ -n $debuginfod ]] ; then
53+ if [[ -n $modbuildid ]] ; then
54+ debuginfod-find debuginfo $modbuildid && return
55+ fi
56+
57+ # Only using debuginfod so don't try to find vmlinux module path
58+ if [[ $debuginfod == "only" ]] ; then
59+ return
60+ fi
61+ fi
62+
4063 if [[ "$modpath" != "" ]] ; then
4164 for fn in $(find "$modpath" -name "${module//_/[-_]}.ko*") ; do
4265 if readelf -WS "$fn" | grep -qwF .debug_line ; then
@@ -150,6 +173,27 @@ parse_symbol() { · 107 unmodified lines
150173 symbol="$segment$name ($code)"
151174 }
152175
176+debuginfod_get_vmlinux() {
177+ local vmlinux_buildid=${1##* }
178+
179+ if [[ $vmlinux != "" ]]; then
180+ return
181+ fi
182+
183+ if [[ $vmlinux_buildid =~ ^[0-9a-f]+ ]]; then
184+ vmlinux=$(debuginfod-find debuginfo $vmlinux_buildid)
185+ if [[ $? -ne 0 ]] ; then
186+ echo "ERROR! vmlinux image not found via debuginfod-find" >&2
187+ usage
188+ exit 2
189+ fi
190+ return
191+ fi
192+ echo "ERROR! Build ID for vmlinux not found. Try passing -r or specifying vmlinux" >&2
193+ usage
194+ exit 2
195+}
196+
153197 decode_code() {
154198 local scripts=`dirname "${BASH_SOURCE[0]}"`
155199
@@ -157,6 +201,14 @@ decode_code() { · 1 unmodified line
157201 }
158202
159203 handle_line() {
204+ if [[ $basepath == "auto" && $vmlinux != "" ]] ; then
205+ module=""
206+ symbol="kernel_init+0x0/0x0"
207+ parse_symbol
208+ basepath=${symbol#kernel_init (}
209+ basepath=${basepath%/init/main.c:*)}
210+ fi
211+
160212 local words
161213
162214 # Tokenize
@@ -182,16 +234,28 @@ handle_line() { · 19 unmodified lines
182234 fi
183235 done
184236
237+ if [[ ${words[$last]} =~ ^[0-9a-f]+\] ]]; then
238+ words[$last-1]="${words[$last-1]} ${words[$last]}"
239+ unset words[$last]
240+ last=$(( $last - 1 ))
241+ fi
242+
185243 if [[ ${words[$last]} =~ \[([^]]+)\] ]]; then
186244 module=${words[$last]}
187245 module=${module#\[}
188246 module=${module%\]}
247+ modbuildid=${module#* }
248+ module=${module% *}
249+ if [[ $modbuildid == $module ]]; then
250+ modbuildid=
251+ fi
189252 symbol=${words[$last-1]}
190253 unset words[$last-1]
191254 else
192255 # The symbol is the last element, process it
193256 symbol=${words[$last]}
194257 module=
258+ modbuildid=
195259 fi
196260
197261 unset words[$last]
@@ -201,14 +265,6 @@ handle_line() { · 3 unmodified lines
201265 echo "${words[@]}" "$symbol $module"
202266 }
203267
204−if [[ $basepath == "auto" ]] ; then
205− module=""
206− symbol="kernel_init+0x0/0x0"
207− parse_symbol
208− basepath=${symbol#kernel_init (}
209− basepath=${basepath%/init/main.c:*)}
210−fi
211−
212268 while read line; do
213269 # Let's see if we have an address in the line
214270 if [[ $line =~ \[\<([^]]+)\>\] ]] ||
@@ -218,6 +274,9 @@ while read line; do · 3 unmodified lines
218274 # Is it a code line?
219275 elif [[ $line == *Code:* ]]; then
220276 decode_code "$line"
277+ # Is it a version line?
278+ elif [[ -n $debuginfod && $line =~ PID:\ [0-9]+\ Comm: ]]; then
279+ debuginfod_get_vmlinux "$line"
221280 else
222281 # Nothing special in this line, show it as is
223282 echo "$line"

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t