$NetBSD: KASSERT.9,v 1.12 2011/04/06 05:40:19 jruoho Exp $

Copyright (c) 2006 Igor Sobrado
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

.Dd September 27, 2011 .Dt KASSERT 9 .Os .Sh NAME .Nm KASSERT , .Nm KASSERTMSG , .Nm KDASSERT , .Nm KDASSERTMSG .Nd kernel expression verification macros .Sh SYNOPSIS .Ft void .Fn KASSERT expression .Ft void .Fn KASSERTMSG expression format ... .Ft void .Fn KDASSERT expression .Ft void .Fn KDASSERTMSG expression format ... .Sh DESCRIPTION These machine independent assertion-checking macros cause a kernel .Xr panic 9 if the given .Ar expression evaluates to false. Two compile-time .Xr options 4 define the behavior of the checks. l -enum -offset 2n t The .Fn KASSERT and .Fn KASSERTMSG tests are included only in kernels compiled with the .Dv DIAGNOSTIC configuration option. In a kernel that does not have this configuration option, the macros are defined to be no-ops. t The .Fn KDASSERT and .Fn KDASSERTMSG tests are included only in kernels compiled with the .Dv DEBUG configuration option. The .Fn KDASSERT and .Fn KASSERT macros are identical except for the controlling option

f ( Dv DEBUG vs .Dv DIAGNOSTIC ) . Basically, .Fn KASSERT should be used for light-weight checks and .Fn KDASSERT should be used for heavier ones. .El

p Callers should not rely on the side effects of .Ar expression because, depending on the kernel compile options mentioned above, .Ar expression might not be evaluated at all.

p 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 .Fn KASSERTMSG and .Fn KDASSERTMSG macros append to the .Xr panic 9 format string the message specified by .Fa format and its subsequent arguments, similar to .Xr printf 9 functions. .Sh SEE ALSO .Xr config 1 , .Xr options 4 , .Xr CTASSERT 9 , .Xr panic 9 , .Xr printf 9 .Sh AUTHORS These macros were written by .An Chris G. Demetriou .Aq cgd@netbsd.org .