Skip to contentSkip to conversation

scripts/decode_stacktrace.sh: canonicalize basepath and modpath

PATCH In review Kirill A. Shutemov 3 participants 3 messages Nov 21, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts/decode_stacktrace.sh: canonicalize basepath and modpath

I use decode_stacktrace.sh as

$ ./scripts/decode_stacktrace.sh vmlinux . .

It means basepath is equal to "." and decode_stacktrace stips dot from the filepath instead of actual basepath. Not very helpful.

Let's fix this.

Canonicalize modepath too while I'm there.

Cc Sasha Levin <[email protected]>
Cc Konstantin Khlebnikov <[email protected]>
---
 scripts/decode_stacktrace.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/decode_stacktrace.sh +3 -3
index c332684e1b5a..27e3cb7a14e8 100755
@@ -9,8 +9,8 @@ if [[ $# < 2 ]]; then
 fi
 
 vmlinux=$1
-basepath=$2
-modpath=$3
+basepath=$(readlink -ev "$2")
+modpath=$(readlink -ev "$3")
 declare -A cache
 declare -A modcache
 
@@ -77,7 +77,7 @@ parse_symbol() {
 	fi
 
 	# Strip out the base of the path
-	code=${code//$basepath/""}
+	code=${code//$basepath\//""}
 
 	# In the case of inlines, move everything to same line
 	code=${code//$'\n'/' '}
Signature · 1 line
2.10.2
#1 lore raw
Quoted 6 lines · Kirill A. Shutemov

I use decode_stacktrace.sh as

$ ./scripts/decode_stacktrace.sh vmlinux . .

It means basepath is equal to "." and decode_stacktrace stips dot from the filepath instead of actual basepath. Not very helpful.

This doesn't work if basepath is some non-existenting directory. In my case this usually path in pbulder container.

You could try to replace only "." to "$PWD/"

Quoted 4 lines

Let's fix this.

Canonicalize modepath too while I'm there.

This is redundant. =)

Quoted 35 lines
Cc Sasha Levin <[email protected]>
Cc Konstantin Khlebnikov <[email protected]>
---
 scripts/decode_stacktrace.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/decode_stacktrace.sh +3 -4
index c332684e1b5a..27e3cb7a14e8 100755
@@ -9,8 +9,8 @@ if [[ $# < 2 ]]; then
 fi
 
 vmlinux=$1
-basepath=$2
-modpath=$3
+basepath=$(readlink -ev "$2")
+modpath=$(readlink -ev "$3")
 declare -A cache
 declare -A modcache
 
@@ -77,7 +77,7 @@ parse_symbol() {
        fi
 
        # Strip out the base of the path
-       code=${code//$basepath/""}
+       code=${code//$basepath\//""}
 
        # In the case of inlines, move everything to same line
        code=${code//$'\n'/' '}
--

2.10.2

#2 lore raw
Quoted 11 lines · Konstantin Khlebnikov
Quoted 6 lines · Kirill A. Shutemov

I use decode_stacktrace.sh as

$ ./scripts/decode_stacktrace.sh vmlinux . .

It means basepath is equal to "." and decode_stacktrace stips dot from the filepath instead of actual basepath. Not very helpful.

This doesn't work if basepath is some non-existenting directory. In my case this usually path in pbulder container.

What about "readlink -m"? It should be good enough for you too.

Signature · 1 line
 Kirill A. Shutemov