Skip to content

Commit 431151b

Browse files
koct9itorvalds
authored andcommitted
scripts/decode_stacktrace.sh: guess path to modules
Try to find module in directory with vmlinux (for fresh build). Then try standard paths where debuginfo are usually placed. Pick first file which have elf section '.debug_line'. Before: $ echo 'tap_open+0x0/0x0 [tap]' | ./scripts/decode_stacktrace.sh /usr/lib/debug/boot/vmlinux-5.4.0-37-generic WARNING! Modules path isn't set, but is needed to parse this symbol tap_open+0x0/0x0 tap After: $ echo 'tap_open+0x0/0x0 [tap]' | ./scripts/decode_stacktrace.sh /usr/lib/debug/boot/vmlinux-5.4.0-37-generic tap_open (drivers/net/tap.c:502) tap Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Sasha Levin <sashal@kernel.org> Link: http://lkml.kernel.org/r/159282923068.248444.5461337458421616083.stgit@buzz Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ecda6e2 commit 431151b

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

‎scripts/decode_stacktrace.sh‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,40 @@ fi
1212
vmlinux=$1
1313
basepath=${2-auto}
1414
modpath=$3
15+
release=""
16+
1517
declare -A cache
1618
declare -A modcache
1719

20+
find_module() {
21+
if [[ "$modpath" != "" ]] ; then
22+
for fn in $(find "$modpath" -name "${module//_/[-_]}.ko*") ; do
23+
if readelf -WS "$fn" | grep -qwF .debug_line ; then
24+
echo $fn
25+
return
26+
fi
27+
done
28+
return 1
29+
fi
30+
31+
modpath=$(dirname "$vmlinux")
32+
find_module && return
33+
34+
if [[ $release == "" ]] ; then
35+
release=$(gdb -ex 'print init_uts_ns.name.release' -ex 'quit' -quiet -batch "$vmlinux" | sed -n 's/\$1 = "\(.*\)".*/\1/p')
36+
fi
37+
38+
for dn in {/usr/lib/debug,}/lib/modules/$release ; do
39+
if [ -e "$dn" ] ; then
40+
modpath="$dn"
41+
find_module && return
42+
fi
43+
done
44+
45+
modpath=""
46+
return 1
47+
}
48+
1849
parse_symbol() {
1950
# The structure of symbol at this point is:
2051
# ([name]+[offset]/[total length])
@@ -27,12 +58,11 @@ parse_symbol() {
2758
elif [[ "${modcache[$module]+isset}" == "isset" ]]; then
2859
local objfile=${modcache[$module]}
2960
else
30-
if [[ $modpath == "" ]]; then
61+
local objfile=$(find_module)
62+
if [[ $objfile == "" ]] ; then
3163
echo "WARNING! Modules path isn't set, but is needed to parse this symbol" >&2
3264
return
3365
fi
34-
local objfile=$(find "$modpath" -name "${module//_/[-_]}.ko*" -print -quit)
35-
[[ $objfile == "" ]] && return
3666
modcache[$module]=$objfile
3767
fi
3868

0 commit comments

Comments
 (0)