Skip to content

Commit 26681eb

Browse files
bebarinotorvalds
authored andcommitted
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. Link: https://lkml.kernel.org/r/20210511003845.2429846-9-swboyd@chromium.org Signed-off-by: Stephen Boyd <swboyd@chromium.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Jessica Yu <jeyu@kernel.org> Cc: Evan Green <evgreen@chromium.org> Cc: Hsin-Yi Wang <hsinyi@chromium.org> Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> Cc: Sasha Levin <sashal@kernel.org> Cc: Petr Mladek <pmladek@suse.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Baoquan He <bhe@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Dave Young <dyoung@redhat.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Will Deacon <will@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9ef8af2 commit 26681eb

1 file changed

Lines changed: 70 additions & 11 deletions

File tree

‎scripts/decode_stacktrace.sh‎

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
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,19 +23,43 @@ if [[ $1 == "-r" ]] ; then
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
3030
vmlinux=$1
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,13 +173,42 @@ parse_symbol() {
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

156200
echo "$1" | $scripts/decodecode
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() {
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() {
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
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"

0 commit comments

Comments
 (0)