SYNOPSIS
void
KASSERT(
expression);
void
KASSERTMSG(expression, message);
void
KDASSERT(expression);
DESCRIPTION
These machine independent assertion-checking macros cause a kernel
panic(9) if the given
expression evaluates to false. Two compile-time
options(4) define the behavior of the checks.
-
The KASSERT() and KASSERTMSG() tests are included only in kernels compiled with the DIAGNOSTIC configuration option. In a kernel that does not have this configuration option, the macros are defined to be no-ops.
-
The KDASSERT() tests are included only in kernels compiled with the DEBUG configuration option. The KDASSERT() and KASSERT() macros are identical except for the controlling option (DEBUG vs DIAGNOSTIC). Basically, KASSERT() should be used for light-weight checks and KDASSERT() should be used for heavier ones.
Callers should not rely on the side effects of expression because, depending on the kernel compile options mentioned above, expression might not be evaluated at all.
The panic message will display the style of assertion (debugging vs. diagnostic), the expression that failed and the filename, and line number the failure happened on. The KASSERTMSG() macro appends additional message to the panic(9) format string.