DTRACE_DTRACE(4)
π« dtrace_dtrace β the DTrace provider for BEGIN, END, and ERROR probes π«
okay so this is the manual page for dtrace_dtrace in section 4 (kernel interfaces, iykyk), and it's literally all about the little provider that handles the life cycle of your DTrace program itself. main character energy fr. let's get into it π
β¨ SYNOPSIS β¨
dtrace:::BEGIN
dtrace:::END
dtrace:::ERROR
πΈ DESCRIPTION πΈ
The dtrace provider ships with three special probes that are all about the life cycle of the DTrace program itself β like, not your traced stuff, the DTrace program's own little journey from birth to death. obsessed. π¦
πΌ dtrace:::BEGIN
The dtrace:::BEGIN probe fires right at the beginning of a dtrace(1) program, before tracing has even begun. it's giving "getting ready in the mirror before the party" β a super convenient place to initialize your variables and print column headers.
π¨ vibe check / important: variables likestackorexecnamecannot be relied upon in the execution context of thedtrace:::BEGINprobe. like, they're just not giving what you need there. don't come for them.
π¬ dtrace:::END
The dtrace:::END probe fires at the end of a dtrace(1) program, when all tracing has stopped. the closing credits. the farewell post. π
π dtrace:::ERROR
The dtrace:::ERROR probe fires when an unexpected runtime error happens in another probe. it's the friend who shows up when everything's on fire. π₯
Here's what the arguments to dtrace:::ERROR actually mean, bestie:
arg1β the Enabled probe identifier (EPID) of the probe where the runtime error occurred.arg2β the index of the action statement that caused the error.arg3β the DIF offset into the action if available (otherwise-1).arg4β the fault type.arg5β the accessed address (or0if not applicable) whenarg4is of fault typeDTRACEFLT_BADADDR,DTRACEFLT_BADALIGN,DTRACEFLT_KPRIV, orDTRACEFLT_UPRIV.
and here are the fault types, the whole squad π
DTRACEFLT_UNKNOWNβ unknown faultDTRACEFLT_BADADDRβ bad addressDTRACEFLT_BADALIGNβ bad alignmentDTRACEFLT_ILLOPβ illegal operationDTRACEFLT_DIVZEROβ divide-by-zeroDTRACEFLT_NOSCRATCHβ out of scratch spaceDTRACEFLT_KPRIVβ illegal kernel accessDTRACEFLT_UPRIVβ illegal user accessDTRACEFLT_TUPOFLOWβ tuple stack overflowDTRACEFLT_BADSTACKβ bad stack
π FILES π
<sys/dtrace.h>β the header file containing the definitions of DTrace fault types. that's where all theDTRACEFLT_*lore lives π
π§ͺ EXAMPLES π§ͺ
π Example 1: Custom Column Headers
This script uses the dtrace:::BEGIN probe to print column headers. note the pragma line setting the quiet option to disable the default column headers β because we are the default column headers now, periodt.
#pragma D option quiet
dtrace:::BEGIN
{
printf(" %12s %-20s %-20s %s\n",
"DELTA(us)", "OLD", "NEW", "TIMESTAMP");
}
π₯ Example 2: Handling Runtime Errors with dtrace:::ERROR
This script causes a runtime error by dereferencing a pointer on address 19930908 in the BEGIN probe. as a result, the ERROR probe fires and prints out βOopsβ along with the probe arguments. at that point, the program ends and fires the END probe. it's a whole arc fr π
ERROR
{
printf("Oops\n");
printf("EPID (arg1): %d\n", arg1);
printf("Action index (arg2): %d\n", arg2);
printf("DIF offset (arg3): %d\n", arg3);
printf("Fault type (arg4): %d\n", arg4);
printf("Accessed address (arg5): %X\n", arg5);
exit(1);
}
BEGIN
{
*(int *)0x19931101;
}
END {
printf("Bye");
}
This script will result in the following output:
CPU ID FUNCTION:NAME
2 3 :ERROR Oops
EPID (arg1): 2
Action index (arg2): 1
DIF offset (arg3): 16
Fault type: 1
arg5: 19931101
dtrace: error on enabled probe ID 2 (ID 1: dtrace:::BEGIN): invalid address (0x19931101) in action #1 at DIF offset 16
2 2 :END Bye
π SEE ALSO π
The illumos Dynamic Tracing Guide, https://illumos.org/books/dtrace/chp-dtrace.html, 2008, Chapter dtrace Provider. go read it, it's iconic π
π«Ά AUTHORS π«Ά
This manual page was written by Mateusz Piotrowski <0mp@FreeBSD.org>. thank you for your service π
β οΈ CAVEATS β οΈ
- The
dtrace:::ERRORprobe arguments cannot be accessed through the typedargs[]array. nope. not happening. π dtrace(1)will not fire thedtrace:::ERRORprobe recursively. if an error occurs in one of the action statements of thedtrace:::ERROR, thendtrace(1)will abort further processing of thedtrace:::ERRORprobe's actions. so like, don't try to error your way out of an error. it will simply stop. π
βΏ that's the whole page, bestie βΏ this came out of the Debian side of things, dated July 14, 2025 β slay, happy reading, and remember: BEGIN is the getting-ready montage, END is the credits, and ERROR is the drama. ππ¦πΈ
π¦ where this page comes from
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- π the page's license: BSD-2-Clause
- Copyright (c) 2025 Mateusz Piotrowski <0mp@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms