From nobody Thu Apr 9 20:28:40 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2865B26ED33 for ; Fri, 6 Mar 2026 00:50:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772758222; cv=none; b=ZfJDTXy+cZvty+stIYBd9tUkdzw7SxvOh3a4AFv3QsNlhEhR2Du9M7j8kEoL+7JFrCd5Q4SP9FhY4BpmLGWGvG4Yg0KaGEQJst5zDPVU9m9OOQq4zm7kzskUaz/9P/erX8jhSLR2hiOdLGEBsaYuTw/m8g/C+3gmiYcZqUSwJoQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772758222; c=relaxed/simple; bh=m3h4/tM8KlwZGjvCUGEo0ULS2Nz5mO6i8B+Dn7TZ94s=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=fZC4T/XfITESIKdYb9Xh3e+11D0q7iqDAeroq1g05SbNQ9QdUHj/DEcAFEqEAM/wmYC3TfhkAytfoiciIeglp1eVxhdt3TMf5zs691Jj6Q1oSy1itEkJ5n1Fa6BS+7ImF1QtXAA8TQFL+3258amn86RjzsYpVXM7/yAEOUxneEU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ng/VYZCJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ng/VYZCJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB4C5C116C6; Fri, 6 Mar 2026 00:50:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772758221; bh=m3h4/tM8KlwZGjvCUGEo0ULS2Nz5mO6i8B+Dn7TZ94s=; h=From:To:Cc:Subject:Date:From; b=Ng/VYZCJ55CyBF/7wWAB6+2JbORMlg+nk3NwLDOdJJhTkhk8c5wfqJHDJ6T9T9OCw IQiiVVCg6Eg4oV8esJP50RKI3wn8YKHQXF5rdo8CKIrdIz0U+EaNPs8P1w8HAdXLgW t2QsX+kAEPpJby9zQAsCnrWsK2W2irjehMo/eyh1IA0NONWsAifCGmEyeBcDzx/FLj 7jXMAoR3tHN2+/xHHAtZst4YZrT3FJATmf/XNXCEgtQMfAqZ4EJ4cjB1sQqWjqgCBv 7wq3tLioWYQb54gD36qt4v/AodganoW33nPZodDrTHXux+c75QbUpmnN7cEUj2hSjT hRq7ePNghd6rQ== From: "Masami Hiramatsu (Google)" To: Matthieu Baerts , Andrew Morton , Sasha Levin Cc: Carlos Llamas , Luca Ceresoli , Masami Hiramatsu , linux-kernel@vger.kernel.org Subject: [PATCH v3] decode_stacktrace: Decode caller address Date: Fri, 6 Mar 2026 09:50:16 +0900 Message-ID: <177275821652.1557019.18367881408364381866.stgit@mhiramat.tok.corp.google.com> X-Mailer: git-send-email 2.53.0.473.g4a7958ca14-goog User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Masami Hiramatsu (Google) Decode the caller address instead of the return address by default. This also introduced -R option to provide return address decoding mode. This changes the decode_stacktrace.sh to decode the line info 1byte before the return address which will be the call(branch) instruction address. If the return address is a symbol address (zero offset from it), it falls back to decoding the return address. This improves results especially when optimizations have changed the order of the lines around the return address, or when the return address does not have the actual line information. With this change; Call Trace: dump_stack_lvl (lib/dump_stack.c:94 lib/dump_stack.c:120) lockdep_rcu_suspicious (kernel/locking/lockdep.c:6876) event_filter_pid_sched_process_fork (kernel/trace/trace_events.c:1057) kernel_clone (include/trace/events/sched.h:396 include/trace/events/sched= .h:396 kernel/fork.c:2664) __x64_sys_clone (kernel/fork.c:2795 kernel/fork.c:2779 kernel/fork.c:2779) do_syscall_64 (arch/x86/entry/syscall_64.c:63 arch/x86/entry/syscall_64.c= :94) ? entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) ? trace_irq_disable (include/trace/events/preemptirq.h:36) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) Without this (or give -R option); Call Trace: dump_stack_lvl (lib/dump_stack.c:122) lockdep_rcu_suspicious (kernel/locking/lockdep.c:6877) event_filter_pid_sched_process_fork (kernel/trace/trace_events.c:?) kernel_clone (include/trace/events/sched.h:? include/trace/events/sched.h= :396 kernel/fork.c:2664) __x64_sys_clone (kernel/fork.c:2779) do_syscall_64 (arch/x86/entry/syscall_64.c:?) ? entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:130) ? trace_irq_disable (include/trace/events/preemptirq.h:36) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:130) Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Matthieu Baerts (NGI0) Tested-by: Luca Ceresoli # arm64 --- Changes in v3: - Decode call address by default. - Add -R option for decoding return address. Changes in v2: - Do not search, but just decode return_address - 1. --- scripts/decode_stacktrace.sh | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/scripts/decode_stacktrace.sh b/scripts/decode_stacktrace.sh index 8d01b741de62..5a25844003cc 100755 --- a/scripts/decode_stacktrace.sh +++ b/scripts/decode_stacktrace.sh @@ -5,9 +5,11 @@ =20 usage() { echo "Usage:" - echo " $0 -r " - echo " $0 [ [|auto []]]" + echo " $0 [-R] -r " + echo " $0 [-R] [ [|auto []]]" echo " $0 -h" + echo "Options:" + echo " -R: decode return address instead of caller address." } =20 # Try to find a Rust demangler @@ -33,11 +35,17 @@ fi READELF=3D${UTIL_PREFIX}readelf${UTIL_SUFFIX} ADDR2LINE=3D${UTIL_PREFIX}addr2line${UTIL_SUFFIX} NM=3D${UTIL_PREFIX}nm${UTIL_SUFFIX} +decode_retaddr=3Dfalse =20 if [[ $1 =3D=3D "-h" ]] ; then usage exit 0 -elif [[ $1 =3D=3D "-r" ]] ; then +elif [[ $1 =3D=3D "-R" ]] ; then + decode_retaddr=3Dtrue + shift 1 +fi + +if [[ $1 =3D=3D "-r" ]] ; then vmlinux=3D"" basepath=3D"auto" modpath=3D"" @@ -176,13 +184,23 @@ parse_symbol() { # Let's start doing the math to get the exact address into the # symbol. First, strip out the symbol total length. local expr=3D${symbol%/*} + # Also parse the offset from symbol. + local offset=3D${expr#*+} + offset=3D$((offset)) =20 # Now, replace the symbol name with the base address we found # before. expr=3D${expr/$name/0x$base_addr} =20 # Evaluate it to find the actual address - expr=3D$((expr)) + # The stack trace shows the return address, which is the next + # instruction after the actual call, so as long as it's in the same + # symbol, substract one from that to point the call instruction. + if [[ $decode_retaddr =3D=3D false && $offset !=3D 0 ]]; then + expr=3D$((expr-1)) + else + expr=3D$((expr)) + fi local address=3D$(printf "%x\n" "$expr") =20 # Pass it to addr2line to get filename and line number