Page MenuHomeFreeBSD

kinst: Initial revision

Authored by markj on Oct 1 2022, 3:47 PM.
Referenced Files
F81964650: D36851.diff
Tue, Apr 23, 8:34 PM
Unknown Object (File)
Mon, Apr 22, 9:31 AM
Unknown Object (File)
Thu, Apr 18, 2:12 PM
Unknown Object (File)
Fri, Apr 12, 1:06 PM
Unknown Object (File)
Sun, Apr 7, 8:50 PM
Unknown Object (File)
Sun, Apr 7, 5:45 PM
Unknown Object (File)
Sat, Apr 6, 8:02 PM
Unknown Object (File)
Wed, Apr 3, 2:09 AM



This is a new DTrace provider which allows arbitrary kernel instructions
to be traced. Currently it is implemented only for amd64.

kinst probes are created on demand by libdtrace, and there is a probe
for each kernel instruction. Probes are named
kinst:<module>:<function>:<offset>, where "offset" is the offset of the
target instruction relative to the beginning of the function. Omitting
"offset" causes all instructions in the function to be traced.

kinst works similarly to FBT in that it places a breakpoint on the
target instruction and hooks into the breakpoint handler. Because kinst
has to be able to trace arbitrary instructions, it does not emulate most
of them in software but rather causes the traced thread to execute a
copy of the instruction before returning to the original code.

The provider is quite low-level and as-is will be useful mostly only to
kernel developers. However, it provides a great deal of visibility into
kernel code execution and could be used as a building block for
higher-level tooling which can in some sense translate between C sources
and generated machine code.

kinst is experimental and should not be used on production systems for

In collaboration with: markj
Sponsored by: Google, Inc. (GSoC 2022)
MFC after: 3 months

Diff Detail

rG FreeBSD src repository
Lint Not Applicable
Tests Not Applicable

Event Timeline

markj requested review of this revision.Oct 1 2022, 3:47 PM

Doesn't dtrace_disx86() also increase the pointer?


Again, should we use KINST_LOG()?


Should we use KINST_LOG() instead?

markj marked an inline comment as done.

Address review comments, make some minor fixups.

Fix an incomplete comment.

This revision is now accepted and ready to land.Oct 4 2022, 5:32 PM
This revision was automatically updated to reflect the committed changes.