Skip to contentSkip to conversation

scripts/decode_stacktrace: strip all base path prefixes

PATCH In review Jiri Slaby 2 participants 3 messages Jul 20, 2020 – Jul 22, 2020

lore
Share & tools
lore

Jiri Slaby

author
#0 lore raw

PATCH 1/1 scripts/decode_stacktrace: strip all base path prefixes

When addr2line returns more than one location, decode_stacktrace does not currently remove base path from the paths. So the result might look like (line wrapped here):

 ptrace_stop (include/linux/freezer.h:57
 /home/abuild/rpmbuild/BUILD/kernel-default-5.8.rc5/linux-5.8-rc5/linux-obj/../include/linux/freezer.h:67
 /home/abuild/rpmbuild/BUILD/kernel-default-5.8.rc5/linux-5.8-rc5/linux-obj/../include/linux/freezer.h:128
 /home/abuild/rpmbuild/BUILD/kernel-default-5.8.rc5/linux-5.8-rc5/linux-obj/../include/linux/freezer.h:173
 /home/abuild/rpmbuild/BUILD/kernel-default-5.8.rc5/linux-5.8-rc5/linux-obj/../kernel/signal.c:2217)

Make sure all the lines are processed, so the result now looks like (line wrapped here again):

 ptrace_stop (include/linux/freezer.h:57 include/linux/freezer.h:67
 include/linux/freezer.h:128 include/linux/freezer.h:173
 kernel/signal.c:2217)
Fixes 67a28de47faa (scripts/decode_stacktrace: only strip base path when a prefix of the path)
Cc Sasha Levin <[email protected]>
---
 scripts/decode_stacktrace.sh | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
scripts/decode_stacktrace.sh +7 -6
index 4bdcb6d8c605..3fddcb48b464 100755
@@ -140,14 +140,15 @@ parse_symbol() {
 		return
 	fi
 
-	# Strip out the base of the path
-	code=${code#$basepath/}
-
-	# In the case of inlines, move everything to same line
-	code=${code//$'\n'/' '}
+	declare -a output
+	while read LINE; do
+		# Strip out the base of the path
+		LINE=${LINE#$basepath/}
+		output+=("$LINE")
+	done <<< $code
 
 	# Replace old address with pretty line numbers
-	symbol="$segment$name ($code)"
+	symbol="$segment$name (${output[@]})"
 }
 
 decode_code() {
Signature · 1 line
2.27.0
#1 lore raw
Quoted 9 lines · On Mon, 20 Jul 2020 09:44:29 +0200 Jiri Slaby <[email protected]> wrote:

When addr2line returns more than one location, decode_stacktrace does not currently remove base path from the paths. So the result might look like (line wrapped here):

 ptrace_stop (include/linux/freezer.h:57
 /home/abuild/rpmbuild/BUILD/kernel-default-5.8.rc5/linux-5.8-rc5/linux-obj/../include/linux/freezer.h:67
 /home/abuild/rpmbuild/BUILD/kernel-default-5.8.rc5/linux-5.8-rc5/linux-obj/../include/linux/freezer.h:128
 /home/abuild/rpmbuild/BUILD/kernel-default-5.8.rc5/linux-5.8-rc5/linux-obj/../include/linux/freezer.h:173
 /home/abuild/rpmbuild/BUILD/kernel-default-5.8.rc5/linux-5.8-rc5/linux-obj/../kernel/signal.c:2217)
Quoted 5 lines

Make sure all the lines are processed, so the result now looks like (line wrapped here again):

 ptrace_stop (include/linux/freezer.h:57 include/linux/freezer.h:67
 include/linux/freezer.h:128 include/linux/freezer.h:173
 kernel/signal.c:2217)

hm, I just merged
http://lkml.kernel.org/r/[email protected].
Which is preferable?

Quoted 26 lines
scripts/decode_stacktrace.sh +7 -6
@@ -140,14 +140,15 @@ parse_symbol() {
 		return
 	fi
 
-	# Strip out the base of the path
-	code=${code#$basepath/}
-
-	# In the case of inlines, move everything to same line
-	code=${code//$'\n'/' '}
+	declare -a output
+	while read LINE; do
+		# Strip out the base of the path
+		LINE=${LINE#$basepath/}
+		output+=("$LINE")
+	done <<< $code
 
 	# Replace old address with pretty line numbers
-	symbol="$segment$name ($code)"
+	symbol="$segment$name (${output[@]})"
 }
 
 decode_code() {
Signature · 1 line
2.27.0
author Reviewed-by
#2 lore raw
Quoted 17 lines · Andrew Morton
Quoted 9 lines · On Mon, 20 Jul 2020 09:44:29 +0200 Jiri Slaby <[email protected]> wrote:

When addr2line returns more than one location, decode_stacktrace does not currently remove base path from the paths. So the result might look like (line wrapped here):

 ptrace_stop (include/linux/freezer.h:57
 /home/abuild/rpmbuild/BUILD/kernel-default-5.8.rc5/linux-5.8-rc5/linux-obj/../include/linux/freezer.h:67
 /home/abuild/rpmbuild/BUILD/kernel-default-5.8.rc5/linux-5.8-rc5/linux-obj/../include/linux/freezer.h:128
 /home/abuild/rpmbuild/BUILD/kernel-default-5.8.rc5/linux-5.8-rc5/linux-obj/../include/linux/freezer.h:173
 /home/abuild/rpmbuild/BUILD/kernel-default-5.8.rc5/linux-5.8-rc5/linux-obj/../kernel/signal.c:2217)
Quoted 5 lines

Make sure all the lines are processed, so the result now looks like (line wrapped here again):

 ptrace_stop (include/linux/freezer.h:57 include/linux/freezer.h:67
 include/linux/freezer.h:128 include/linux/freezer.h:173
 kernel/signal.c:2217)
Quoted 3 lines

hm, I just merged
http://lkml.kernel.org/r/[email protected].
Which is preferable?

Nobody cares, apparently. And I don't mind either of them. You can add:

to the other one if you want. FTR it is this commit in -next-20200721:

commit a1bc7c359e6044391cfc759ae8a2adf0bc5cd731

Author: Pi-Hsun Shih <[email protected]>
Date:   Tue Jul 21 12:57:33 2020 +1000

scripts/decode_stacktrace: strip basepath from all paths

thanks,

Signature · 2 lines
js
suse labs