Skip to content

Commit 0f69dc2

Browse files
lucaceresoliakpm00
authored andcommitted
scripts/decode_stacktrace.sh: remove find_module recursion and improve error reporting
Patch series "scripts/decode_stacktrace.sh: improve error reporting and usability", v2. This small series improves usability of scripts/decode_stacktrace.sh by improving the usage text and correctly reporting when modules are built without debugging symbols. This patch (of 3): The find_module() function can fail for two reasons: * the module was not found * the module was found but without debugging info In both cases the user is reported the same error: WARNING! Modules path isn't set, but is needed to parse this symbol This is misleading in case the modules path is set correctly. find_module() is currently implemented as a recursive function based on global variables in order to check up to 4 different paths. This is not straightforward to read and even less to modify. Besides, the debuginfo code at the beginning of find_module() is executed identically every time the function is entered, i.e. up to 4 times per each module search due to recursion. To be able to improve error reporting, first rewrite the find_module() function to remove recursion. The new version of the function iterates over all the same (up to 4) paths as before and for each of them does the same checks as before. At the end of the iteration it is now able to print an appropriate error message, so that has been moved from the caller into find_module(). Finally, when the module is found but without debugging info, mention the two Kconfig variables one needs to set in order to have the needed debugging symbols. Link: https://lkml.kernel.org/r/20240823-decode_stacktrace-find_module-improvements-v2-0-d7a57d35558b@bootlin.com Link: https://lkml.kernel.org/r/20240823-decode_stacktrace-find_module-improvements-v2-1-d7a57d35558b@bootlin.com Signed-off-by: Luca Ceresoli <[email protected]> Reviewed-by: Stephen Boyd <[email protected]> Cc: Alexis Lothoré (eBPF Foundation) <[email protected]> Cc: Konstantin Khlebnikov <[email protected]> Cc: Luca Ceresoli <[email protected]> Cc: Sasha Levin <[email protected]> Cc: Thomas Petazzoni <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 38676d9 commit 0f69dc2

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

scripts/decode_stacktrace.sh

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,31 +89,32 @@ find_module() {
8989
fi
9090
fi
9191

92-
if [[ "$modpath" != "" ]] ; then
93-
for fn in $(find "$modpath" -name "${module//_/[-_]}.ko*") ; do
94-
if ${READELF} -WS "$fn" | grep -qwF .debug_line ; then
95-
echo $fn
96-
return
97-
fi
98-
done
99-
return 1
100-
fi
101-
102-
modpath=$(dirname "$vmlinux")
103-
find_module && return
104-
105-
if [[ $release == "" ]] ; then
92+
if [ -z $release ] ; then
10693
release=$(gdb -ex 'print init_uts_ns.name.release' -ex 'quit' -quiet -batch "$vmlinux" 2>/dev/null | sed -n 's/\$1 = "\(.*\)".*/\1/p')
10794
fi
95+
if [ -n "${release}" ] ; then
96+
release_dirs="/usr/lib/debug/lib/modules/$release /lib/modules/$release"
97+
fi
10898

109-
for dn in {/usr/lib/debug,}/lib/modules/$release ; do
110-
if [ -e "$dn" ] ; then
111-
modpath="$dn"
112-
find_module && return
99+
found_without_debug_info=false
100+
for dir in "$modpath" "$(dirname "$vmlinux")" ${release_dirs}; do
101+
if [ -n "${dir}" ] && [ -e "${dir}" ]; then
102+
for fn in $(find "$dir" -name "${module//_/[-_]}.ko*") ; do
103+
if ${READELF} -WS "$fn" | grep -qwF .debug_line ; then
104+
echo $fn
105+
return
106+
fi
107+
found_without_debug_info=true
108+
done
113109
fi
114110
done
115111

116-
modpath=""
112+
if [[ ${found_without_debug_info} == true ]]; then
113+
echo "WARNING! No debugging info in module ${module}, rebuild with DEBUG_KERNEL and DEBUG_INFO" >&2
114+
else
115+
echo "WARNING! Cannot find .ko for module ${module}, please pass a valid module path" >&2
116+
fi
117+
117118
return 1
118119
}
119120

@@ -131,7 +132,6 @@ parse_symbol() {
131132
else
132133
local objfile=$(find_module)
133134
if [[ $objfile == "" ]] ; then
134-
echo "WARNING! Modules path isn't set, but is needed to parse this symbol" >&2
135135
return
136136
fi
137137
if [[ $aarray_support == true ]]; then

0 commit comments

Comments
 (0)