Thread (23 messages) flat view 23 messages, 3 authors, 10d ago

Re: [PATCH 6/8] perf scripts: Add perf-stuck, to tell where a running perf is stuck

From: sashiko-bot@kernel.org
Date: 2026-09-13 22:36:20

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] GDB `printf` with `%s` on `NULL` pointer causes script abort when `dwarf_diename` returns `NULL`.
--

commit 65695a427d0e95be616d39c680b3d1d8ddb81e11
Author: Arnaldo Carvalho de Melo [off-list ref]
Subject: perf scripts: Add perf-stuck, to tell where a running perf is stuck

This commit adds a stopgap utility for sampling a running perf process to
identify if it is stuck in a loop. It uses a shell script to poll /proc for
progress and CPU usage, and optionally calls into a new GDB command file to
print the DIE chain if the process is stuck in a DWARF type chasing loop.
quoted hunk ↗ jump to hunk
diff --git a/tools/perf/scripts/perf-stuck.gdb b/tools/perf/scripts/perf-stuck.gdb
new file mode 100644
index 0000000000000..53e9019828b6e
--- /dev/null
+++ b/tools/perf/scripts/perf-stuck.gdb
[ ... ]
+define perf-die-chain
+  if $argc < 2
+    printf "usage: perf-die-chain <function> <die variable> [iterations]\n"
+  else
+    frame function $arg0
+    if $argc == 3
+      set $perf_die_chain_n = $arg2
+    else
+      set $perf_die_chain_n = 10
+    end
+    set $perf_die_chain_head = $pc
+    set $perf_die_chain_i = 0
+    while $perf_die_chain_i < $perf_die_chain_n
+      printf "chain[%d] die=%p addr=%p cu=%p off=0x%lx tag=%d name=%s\n", $perf_die_chain_i, $arg1, $arg1->addr, $arg1->cu, ((Dwarf_Off) dwarf_dieoffset($arg1)), ((int) dwarf_tag($arg1)), ((char *) dwarf_diename($arg1))
[Severity: Medium]
Will this script abort execution if dwarf_diename() returns a NULL pointer?

When perf-die-chain processes DIEs that lack a DW_AT_name attribute, such as
type modifiers (e.g., DW_TAG_const_type or DW_TAG_pointer_type),
dwarf_diename() evaluates to NULL (0x0).

Passing a NULL pointer to GDB's printf with %s forces it to read from
unmapped memory at address 0x0, which results in a "Cannot access memory at
address 0x0" error.

Could this be adjusted to check if dwarf_diename() returns NULL before
attempting to print it, to prevent the debugging macro from failing
unexpectedly?
+      until *$perf_die_chain_head
+      set $perf_die_chain_i = $perf_die_chain_i + 1
+    end
+  end
+end
-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260913222821.3353-1-acme@kernel.org?part=6
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help