DTRACE_KINST(4)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’… DTRACE_KINST(4) β€” the Kernel Interfaces Manual, bestie edition πŸŽ€

okay so picture this: a whole manual page from the Kernel Interfaces Manual, and it's about dtrace_kinst β€” and I'm gonna walk you through literally every single thing in it, no skips, no cap πŸ’–


✨ NAME ✨

dtrace_kinst β€” a DTrace provider for tracing arbitrary instructions in a given kernel function πŸ¦‹


🌸 SYNOPSIS 🌸

kinst::<function>:<instruction>

that's the whole vibe. three little pieces, colon-separated, and you're in πŸ‘‘


πŸ’œ DESCRIPTION πŸ’œ

The DTrace kinst provider lets you trace any instruction in a given kernel function. iconic behavior, honestly.

  • <function> β€” corresponds to the function to be traced 🫢
  • <instruction> β€” the offset to the specific instruction, and you can grab that from the function's disassembly using kgdb from the gdb package πŸ”₯

kinst creates probes on-demand, meaning it searches for and parses the function's instructions each time dtrace(1) is run, and not at module load time. ngl that's the main character difference here.

This is in contrast to dtrace_fbt(4)'s load-time parsing, because kinst can potentially create thousands of probes for just a single function, instead of up to two (entry and return) in the case of dtrace_fbt(4). the way that's a whole different scale 😭

A result of this is that dtrace -l -P kinst will not match any probes. yes, really. don't come for me, that's just how it is πŸ’€

🧚 IMPLEMENTATION NOTES 🧚

The provider is currently implemented only for amd64. that's it, that's the note πŸ’…


⭐ EXAMPLES ⭐

πŸ“ find the offset for the third instruction in vm_fault() and trace it, printing the contents of the RSI register

# kgdb
(kgdb) disas /r vm_fault
Dump of assembler code for function vm_fault:
   0xffffffff80876df0 <+0>:     55      push   %rbp
   0xffffffff80876df1 <+1>:     48 89 e5        mov    %rsp,%rbp
   0xffffffff80876df4 <+4>:     41 57   push   %r15

# dtrace -n 'kinst::vm_fault:4 {printf("%#x", regs[R_RSI]);}'
  2  81500                       vm_fault:4 0x827c56000
  2  81500                       vm_fault:4 0x827878000
  2  81500                       vm_fault:4 0x1fab9bef0000
  2  81500                       vm_fault:4 0xe16cf749000
  0  81500                       vm_fault:4 0x13587c366000
...

🌈 trace all instructions in amd64_syscall()

# dtrace -n 'kinst::amd64_syscall:'

look at that. no instruction specified, and it ate πŸ”₯


πŸ¦‹ SEE ALSO πŸ¦‹

go read those too, iykyk πŸ’–


πŸ‘‘ HISTORY πŸ‘‘

The kinst provider first appeared in FreeBSD 14.0. a whole era ✨


πŸŽ€ AUTHORS πŸŽ€

This manual page was written by Christos Margiolis <christos@FreeBSD.org>. ty for your service, king 🫢


okay bestie that's the whole page, mwah πŸ’œ and before you go: this lovely little Debian build is dated July 16, 2025 β€” go forth and trace some instructions, periodt πŸŒΈπŸ’…

πŸ“¦ where this page comes from