Skip to content

Allow tracing kernel threads - #385

Open
Nehal70 wants to merge 1 commit into
janestreet:masterfrom
Nehal70:allow-tracing-kernel-threads-226
Open

Allow tracing kernel threads#385
Nehal70 wants to merge 1 commit into
janestreet:masterfrom
Nehal70:allow-tracing-kernel-threads-226

Conversation

@Nehal70

@Nehal70 Nehal70 commented Aug 7, 2026

Copy link
Copy Markdown

Summary

  • Detect kernel threads by checking whether their parent PID is kthreadd (PID 2).
  • When attaching to a kernel thread, resolve debug symbols from vmlinux instead of /proc/$pid/exe.
  • Stop hiding kernel threads from the fzf attach picker and require -trace-include-kernel or -trace-kernel-only when attaching to them.

Fixes #226

Reproduction

On this WSL2 system, kernel thread PID 342 has ppid=2 and readlink /proc/342/exe fails. Before this change, magic-trace attach -pid 342 would fail when resolving the executable path.

Test plan

  • Added inline tests for /proc/$pid/stat ppid parsing and is_kernel_thread on the current process.
  • dune runtest (requires opam switch with project dependencies).
  • As root, with kernel debug symbols installed: magic-trace attach -pid <kernel-thread-pid> -trace-kernel-only, snapshot with Ctrl-C, verify trace decodes with kernel symbols.

Signed-off-by: Nehal Singhal nehalsinghal06@gmail.com

When attaching to a kernel thread, /proc/$pid/exe is unavailable. Detect
kernel threads by ppid=kthreadd (PID 2) and resolve symbols from vmlinux
instead. Show kernel threads in the fzf attach picker and require kernel
tracing flags when attaching to them.

Fixes janestreet#226

Signed-off-by: Nehal Singhal <nehalsinghal06@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow tracing kernel threads

1 participant