* [PATCH 1/4] scripts/decode_stacktrace: skip missing symbols
@ 2020-06-22 12:33 Konstantin Khlebnikov
2020-06-22 12:33 ` [PATCH 2/4] scripts/decode_stacktrace: guess basepath if not specified Konstantin Khlebnikov
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Konstantin Khlebnikov @ 2020-06-22 12:33 UTC (permalink / raw)
To: linux-kernel, Sasha Levin, Andrew Morton
For now script turns missing symbols into '0' and make bogus decode.
Skip them instead. Also simplify parsing output of 'nm'.
Before:
$ echo 'xxx+0x0/0x0' | ./scripts/decode_stacktrace.sh vmlinux ""
xxx (home/khlebnikov/src/linux/./arch/x86/include/asm/processor.h:398)
After:
$ echo 'xxx+0x0/0x0' | ./scripts/decode_stacktrace.sh vmlinux ""
xxx+0x0/0x0
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
---
scripts/decode_stacktrace.sh | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/scripts/decode_stacktrace.sh b/scripts/decode_stacktrace.sh
index 66a6d511b524..6ec8d6dff86c 100755
--- a/scripts/decode_stacktrace.sh
+++ b/scripts/decode_stacktrace.sh
@@ -56,7 +56,11 @@ parse_symbol() {
if [[ "${cache[$module,$name]+isset}" == "isset" ]]; then
local base_addr=${cache[$module,$name]}
else
- local base_addr=$(nm "$objfile" | grep -i ' t ' | awk "/ $name\$/ {print \$1}" | head -n1)
+ local base_addr=$(nm "$objfile" | awk '$3 == "'$name'" && ($2 == "t" || $2 == "T") {print $1; exit}')
+ if [[ $base_addr == "" ]] ; then
+ # address not found
+ return
+ fi
cache[$module,$name]="$base_addr"
fi
# Let's start doing the math to get the exact address into the
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/4] scripts/decode_stacktrace: guess basepath if not specified
2020-06-22 12:33 [PATCH 1/4] scripts/decode_stacktrace: skip missing symbols Konstantin Khlebnikov
@ 2020-06-22 12:33 ` Konstantin Khlebnikov
2020-06-22 12:33 ` [PATCH 3/4] scripts/decode_stacktrace: guess path to modules Konstantin Khlebnikov
2020-06-22 12:33 ` [PATCH 4/4] scripts/decode_stacktrace: guess path to vmlinux by release name Konstantin Khlebnikov
2 siblings, 0 replies; 4+ messages in thread
From: Konstantin Khlebnikov @ 2020-06-22 12:33 UTC (permalink / raw)
To: linux-kernel, Sasha Levin, Andrew Morton
Guess path to kernel sources using known location of symbol "kernel_init".
Make basepath argument optional.
Before:
$ echo 'vfs_open+0x0/0x0' | ./scripts/decode_stacktrace.sh vmlinux ""
vfs_open (home/khlebnikov/src/linux/fs/open.c:912)
After:
$ echo 'vfs_open+0x0/0x0' | ./scripts/decode_stacktrace.sh vmlinux
vfs_open (fs/open.c:912)
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
---
scripts/decode_stacktrace.sh | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/scripts/decode_stacktrace.sh b/scripts/decode_stacktrace.sh
index 6ec8d6dff86c..b1b85a7b2115 100755
--- a/scripts/decode_stacktrace.sh
+++ b/scripts/decode_stacktrace.sh
@@ -3,14 +3,14 @@
# (c) 2014, Sasha Levin <sasha.levin@oracle.com>
#set -x
-if [[ $# < 2 ]]; then
+if [[ $# < 1 ]]; then
echo "Usage:"
- echo " $0 [vmlinux] [base path] [modules path]"
+ echo " $0 <vmlinux> [base path] [modules path]"
exit 1
fi
vmlinux=$1
-basepath=$2
+basepath=${2-auto}
modpath=$3
declare -A cache
declare -A modcache
@@ -152,6 +152,14 @@ handle_line() {
echo "${words[@]}" "$symbol $module"
}
+if [[ $basepath == "auto" ]] ; then
+ module=""
+ symbol="kernel_init+0x0/0x0"
+ parse_symbol
+ basepath=${symbol#kernel_init (}
+ basepath=${basepath%/init/main.c:*)}
+fi
+
while read line; do
# Let's see if we have an address in the line
if [[ $line =~ \[\<([^]]+)\>\] ]] ||
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/4] scripts/decode_stacktrace: guess path to modules
2020-06-22 12:33 [PATCH 1/4] scripts/decode_stacktrace: skip missing symbols Konstantin Khlebnikov
2020-06-22 12:33 ` [PATCH 2/4] scripts/decode_stacktrace: guess basepath if not specified Konstantin Khlebnikov
@ 2020-06-22 12:33 ` Konstantin Khlebnikov
2020-06-22 12:33 ` [PATCH 4/4] scripts/decode_stacktrace: guess path to vmlinux by release name Konstantin Khlebnikov
2 siblings, 0 replies; 4+ messages in thread
From: Konstantin Khlebnikov @ 2020-06-22 12:33 UTC (permalink / raw)
To: linux-kernel, Sasha Levin, Andrew Morton
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>
---
scripts/decode_stacktrace.sh | 36 +++++++++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/scripts/decode_stacktrace.sh b/scripts/decode_stacktrace.sh
index b1b85a7b2115..7f18ac10af03 100755
--- a/scripts/decode_stacktrace.sh
+++ b/scripts/decode_stacktrace.sh
@@ -12,9 +12,40 @@ fi
vmlinux=$1
basepath=${2-auto}
modpath=$3
+release=""
+
declare -A cache
declare -A modcache
+find_module() {
+ if [[ "$modpath" != "" ]] ; then
+ for fn in $(find "$modpath" -name "${module//_/[-_]}.ko*") ; do
+ if readelf -WS "$fn" | grep -qwF .debug_line ; then
+ echo $fn
+ return
+ fi
+ done
+ return 1
+ fi
+
+ modpath=$(dirname "$vmlinux")
+ find_module && return
+
+ if [[ $release == "" ]] ; then
+ release=$(gdb -ex 'print init_uts_ns.name.release' -ex 'quit' -quiet -batch "$vmlinux" | sed -n 's/\$1 = "\(.*\)".*/\1/p')
+ fi
+
+ for dn in {/usr/lib/debug,}/lib/modules/$release ; do
+ if [ -e "$dn" ] ; then
+ modpath="$dn"
+ find_module && return
+ fi
+ done
+
+ modpath=""
+ return 1
+}
+
parse_symbol() {
# The structure of symbol at this point is:
# ([name]+[offset]/[total length])
@@ -27,12 +58,11 @@ parse_symbol() {
elif [[ "${modcache[$module]+isset}" == "isset" ]]; then
local objfile=${modcache[$module]}
else
- if [[ $modpath == "" ]]; then
+ local objfile=$(find_module)
+ if [[ $objfile == "" ]] ; then
echo "WARNING! Modules path isn't set, but is needed to parse this symbol" >&2
return
fi
- local objfile=$(find "$modpath" -name "${module//_/[-_]}.ko*" -print -quit)
- [[ $objfile == "" ]] && return
modcache[$module]=$objfile
fi
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 4/4] scripts/decode_stacktrace: guess path to vmlinux by release name
2020-06-22 12:33 [PATCH 1/4] scripts/decode_stacktrace: skip missing symbols Konstantin Khlebnikov
2020-06-22 12:33 ` [PATCH 2/4] scripts/decode_stacktrace: guess basepath if not specified Konstantin Khlebnikov
2020-06-22 12:33 ` [PATCH 3/4] scripts/decode_stacktrace: guess path to modules Konstantin Khlebnikov
@ 2020-06-22 12:33 ` Konstantin Khlebnikov
2 siblings, 0 replies; 4+ messages in thread
From: Konstantin Khlebnikov @ 2020-06-22 12:33 UTC (permalink / raw)
To: linux-kernel, Sasha Levin, Andrew Morton
Add option decode_stacktrace -r <release> to specify only release name.
This is enough to guess standard paths to vmlinux and modules:
$ echo -e 'schedule+0x0/0x0\ntap_open+0x0/0x0 [tap]' |
./scripts/decode_stacktrace.sh -r 5.4.0-37-generic
schedule (kernel/sched/core.c:4138)
tap_open (drivers/net/tap.c:502) tap
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
---
scripts/decode_stacktrace.sh | 29 ++++++++++++++++++++++++-----
1 file changed, 24 insertions(+), 5 deletions(-)
diff --git a/scripts/decode_stacktrace.sh b/scripts/decode_stacktrace.sh
index 7f18ac10af03..4bdcb6d8c605 100755
--- a/scripts/decode_stacktrace.sh
+++ b/scripts/decode_stacktrace.sh
@@ -5,14 +5,33 @@
if [[ $# < 1 ]]; then
echo "Usage:"
- echo " $0 <vmlinux> [base path] [modules path]"
+ echo " $0 -r <release> | <vmlinux> [base path] [modules path]"
exit 1
fi
-vmlinux=$1
-basepath=${2-auto}
-modpath=$3
-release=""
+if [[ $1 == "-r" ]] ; then
+ vmlinux=""
+ basepath="auto"
+ modpath=""
+ release=$2
+
+ for fn in {,/usr/lib/debug}/boot/vmlinux-$release{,.debug} /lib/modules/$release{,/build}/vmlinux ; do
+ if [ -e "$fn" ] ; then
+ vmlinux=$fn
+ break
+ fi
+ done
+
+ if [[ $vmlinux == "" ]] ; then
+ echo "ERROR! vmlinux image for release $release is not found" >&2
+ exit 2
+ fi
+else
+ vmlinux=$1
+ basepath=${2-auto}
+ modpath=$3
+ release=""
+fi
declare -A cache
declare -A modcache
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-06-22 12:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-22 12:33 [PATCH 1/4] scripts/decode_stacktrace: skip missing symbols Konstantin Khlebnikov
2020-06-22 12:33 ` [PATCH 2/4] scripts/decode_stacktrace: guess basepath if not specified Konstantin Khlebnikov
2020-06-22 12:33 ` [PATCH 3/4] scripts/decode_stacktrace: guess path to modules Konstantin Khlebnikov
2020-06-22 12:33 ` [PATCH 4/4] scripts/decode_stacktrace: guess path to vmlinux by release name Konstantin Khlebnikov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox