Commit 2f68c791 authored by Miguel Ojeda's avatar Miguel Ojeda Committed by sanglipeng1
Browse files

scripts: decode_stacktrace: demangle Rust symbols

stable inclusion
from stable-v5.10.210
commit 0f906882eba54874fdbd69eaa946efbf3e045a22
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IAE52H

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=0f906882eba54874fdbd69eaa946efbf3e045a22



--------------------------------

[ Upstream commit 99115db4 ]

Recent versions of both Binutils (`c++filt`) and LLVM (`llvm-cxxfilt`)
provide Rust v0 mangling support.

Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Co-developed-by: default avatarAlex Gaynor <alex.gaynor@gmail.com>
Signed-off-by: default avatarAlex Gaynor <alex.gaynor@gmail.com>
Co-developed-by: default avatarWedson Almeida Filho <wedsonaf@google.com>
Signed-off-by: default avatarWedson Almeida Filho <wedsonaf@google.com>
Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
Stable-dep-of: efbd63983533 ("scripts/decode_stacktrace.sh: optionally use LLVM utilities")
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarsanglipeng1 <sanglipeng1@jd.com>
parent a0796e2a
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -9,6 +9,14 @@ if [[ $# < 1 ]]; then
	exit 1
fi

# 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"
@@ -157,6 +165,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)"
}