8585 improve batching done in zil_commit()
[unleashed.git] / usr / src / uts / common / sys / debug.h
blob05e62aa1a14ecdca389ec4f6a02f28db813a9908
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
29 * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
30 * Copyright 2013 Saso Kiselkov. All rights reserved.
33 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
34 /* All Rights Reserved */
36 #ifndef _SYS_DEBUG_H
37 #define _SYS_DEBUG_H
39 #include <sys/isa_defs.h>
40 #include <sys/types.h>
41 #include <sys/note.h>
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
48 * ASSERT(ex) causes a panic or debugger entry if expression ex is not
49 * true. ASSERT() is included only for debugging, and is a no-op in
50 * production kernels. VERIFY(ex), on the other hand, behaves like
51 * ASSERT and is evaluated on both debug and non-debug kernels.
54 extern int assfail(const char *, const char *, int);
55 #define VERIFY(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__)))
56 #if DEBUG
57 #define ASSERT(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__)))
58 #else
59 #define ASSERT(x) ((void)0)
60 #endif
63 * Assertion variants sensitive to the compilation data model
65 #if defined(_LP64)
66 #define ASSERT64(x) ASSERT(x)
67 #define ASSERT32(x)
68 #else
69 #define ASSERT64(x)
70 #define ASSERT32(x) ASSERT(x)
71 #endif
74 * IMPLY and EQUIV are assertions of the form:
76 * if (a) then (b)
77 * and
78 * if (a) then (b) *AND* if (b) then (a)
80 #if DEBUG
81 #define IMPLY(A, B) \
82 ((void)(((!(A)) || (B)) || \
83 assfail("(" #A ") implies (" #B ")", __FILE__, __LINE__)))
84 #define EQUIV(A, B) \
85 ((void)((!!(A) == !!(B)) || \
86 assfail("(" #A ") is equivalent to (" #B ")", __FILE__, __LINE__)))
87 #else
88 #define IMPLY(A, B) ((void)0)
89 #define EQUIV(A, B) ((void)0)
90 #endif
93 * ASSERT3() behaves like ASSERT() except that it is an explicit conditional,
94 * and prints out the values of the left and right hand expressions as part of
95 * the panic message to ease debugging. The three variants imply the type
96 * of their arguments. ASSERT3S() is for signed data types, ASSERT3U() is
97 * for unsigned, and ASSERT3P() is for pointers. The VERIFY3*() macros
98 * have the same relationship as above.
100 extern void assfail3(const char *, uintmax_t, const char *, uintmax_t,
101 const char *, int);
102 #define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \
103 const TYPE __left = (TYPE)(LEFT); \
104 const TYPE __right = (TYPE)(RIGHT); \
105 if (!(__left OP __right)) \
106 assfail3(#LEFT " " #OP " " #RIGHT, \
107 (uintmax_t)__left, #OP, (uintmax_t)__right, \
108 __FILE__, __LINE__); \
109 _NOTE(CONSTCOND) } while (0)
111 #define VERIFY3B(x, y, z) VERIFY3_IMPL(x, y, z, boolean_t)
112 #define VERIFY3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t)
113 #define VERIFY3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t)
114 #define VERIFY3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t)
115 #define VERIFY0(x) VERIFY3_IMPL(x, ==, 0, uintmax_t)
117 #if DEBUG
118 #define ASSERT3B(x, y, z) VERIFY3_IMPL(x, y, z, boolean_t)
119 #define ASSERT3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t)
120 #define ASSERT3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t)
121 #define ASSERT3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t)
122 #define ASSERT0(x) VERIFY3_IMPL(x, ==, 0, uintmax_t)
123 #else
124 #define ASSERT3B(x, y, z) ((void)0)
125 #define ASSERT3S(x, y, z) ((void)0)
126 #define ASSERT3U(x, y, z) ((void)0)
127 #define ASSERT3P(x, y, z) ((void)0)
128 #define ASSERT0(x) ((void)0)
129 #endif
132 * Compile-time assertion. The condition 'x' must be constant.
134 #define CTASSERT(x) _CTASSERT(x, __LINE__)
135 #define _CTASSERT(x, y) __CTASSERT(x, y)
136 #define __CTASSERT(x, y) \
137 typedef char __compile_time_assertion__ ## y [(x) ? 1 : -1]
139 #ifdef _KERNEL
141 extern void abort_sequence_enter(char *);
142 extern void debug_enter(char *);
144 #endif /* _KERNEL */
146 #if defined(DEBUG) && !defined(__sun)
147 /* CSTYLED */
148 #define STATIC
149 #else
150 /* CSTYLED */
151 #define STATIC static
152 #endif
154 #ifdef __cplusplus
156 #endif
158 #endif /* _SYS_DEBUG_H */