From nobody Thu Apr 9 21:52:42 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 40C7F3D5675 for ; Thu, 5 Mar 2026 16:52:49 +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=1772729569; cv=none; b=cODykSEoJlVquG4NvlmRhoXDEPexrYNsfYcldk2mbgJmLy0K13BPHRZ425tdGRb+RoKoNYws7dXLlpuVIuCT8lQVofd9OyN4lW9KmIA//QIzKNBuaLl+r+GHgu47EbAiZGACv5LUeZOp5w0c1jUzHNEzQXI5Cmi6kjInvwGa1tQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772729569; c=relaxed/simple; bh=bRuRUXzAUszt7EEzbdM4qA1IL6yn8xR69mO3S+tjhiU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=en9xLpEyAuJhZjexZlWLqeOzQ6DfictzDufNK0gOIZWkn1opuoi/uePfVMJapFIEl/93vVjtGg2HAa1nMOS/Jb8jNXmJfTtJ/fTZxWckTwSD6YcMd44Kd5ObJMiaXum5WoDcAatWF1DEZHhCP/XsjFFbVwXl89NLdv7dIw2xCSM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LNP1dY0f; 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="LNP1dY0f" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 115A7C116C6; Thu, 5 Mar 2026 16:52:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772729568; bh=bRuRUXzAUszt7EEzbdM4qA1IL6yn8xR69mO3S+tjhiU=; h=From:To:Cc:Subject:Date:From; b=LNP1dY0f4ySNVxRIMGqmUNP6Zhw+6+PlUDBYgAIt25Qv04TvM97n94voCu206JxTX gYPrlkC3uz1JCsbvxxtlv8oqX3Ea3acfKgKRhfm04Gec4cDF+sroK2T19ZXjgVgOdN /ATa9sbxEs6ev8sBIPallAfhH9/hOQ/xYQuPS3Nl7ujEYmpRsbNYAA+lhCw0dW5unK UPIvC6iaFLuRIZmD9btKDGWmqBF0wQYlGmGeBbQGBPcwsHd6zqwR786GHj7z6j0h4M p2tRLO9mefOPpvcpCon0/1hAinEAsfHNHQdKAC3eY2/MkMts1HSzWx06lJFsUYj2ig 8zWH3+qyh2npA== 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 v2] decode_stacktrace: Support caller address decoding Date: Fri, 6 Mar 2026 01:52:42 +0900 Message-ID: <177272956276.1018623.6026552620206046640.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) Add -c option to decodecall address instead of the return address. With this option, it decodes the line info 1byte before the return address which will be the call(branch) instruction address. If the return address is a symbol address, it falls back to decoding the return address. With -c option: 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 -c 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) --- Changes in v2: - Do not search, but just decode return_address - 1. --- scripts/decode_stacktrace.sh | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/scripts/decode_stacktrace.sh b/scripts/decode_stacktrace.sh index 8d01b741de62..0c95362dfc84 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 [-c] -r " + echo " $0 [-c] [ [|auto []]]" echo " $0 -h" + echo "Options:" + echo " -c: Decode call address instead of return 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} +call_search=3Dfalse =20 if [[ $1 =3D=3D "-h" ]] ; then usage exit 0 -elif [[ $1 =3D=3D "-r" ]] ; then +elif [[ $1 =3D=3D "-c" ]] ; then + call_search=3Dtrue + shift 1 +fi + +if [[ $1 =3D=3D "-r" ]] ; then vmlinux=3D"" basepath=3D"auto" modpath=3D"" @@ -176,13 +184,20 @@ 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)) + if [[ $call_search =3D=3D true && $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