scripts: decode_stacktrace: demangle Rust symbols
[sfrench/cifs-2.6.git] / scripts / decode_stacktrace.sh
index 7075e26ab2c4f420f521f89c2550c1aa6691f4b5..564c5632e1a243f2c3ebed14370ce12b4e99d64b 100755 (executable)
@@ -8,6 +8,14 @@ usage() {
        echo "  $0 -r <release> | <vmlinux> [<base path>|auto] [<modules path>]"
 }
 
+# Try to find a Rust demangler
+if type llvm-cxxfilt >/dev/null 2>&1 ; then
+       cppfilt=llvm-cxxfilt
+elif type c++filt >/dev/null 2>&1 ; then
+       cppfilt=c++filt
+       cppfilt_opts=-i
+fi
+
 if [[ $1 == "-r" ]] ; then
        vmlinux=""
        basepath="auto"
@@ -180,6 +188,12 @@ parse_symbol() {
        # In the case of inlines, move everything to same line
        code=${code//$'\n'/' '}
 
+       # Demangle if the name looks like a Rust symbol and if
+       # we got a Rust demangler
+       if [[ $name =~ ^_R && $cppfilt != "" ]] ; then
+               name=$("$cppfilt" "$cppfilt_opts" "$name")
+       fi
+
        # Replace old address with pretty line numbers
        symbol="$segment$name ($code)"
 }