1 /* 2 * CDDL HEADER START 3 * 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. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 27 /* All Rights Reserved */ 28 29 #ifndef _SYS_DEBUG_H 30 #define _SYS_DEBUG_H 31 32 #include <sys/types.h> 33 #include <sys/note.h> 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 /* 40 * ASSERT(ex) causes a panic or debugger entry if expression ex is not 41 * true. ASSERT() is included only for debugging, and is a no-op in 42 * production kernels. VERIFY(ex), on the other hand, behaves like 43 * ASSERT and is evaluated on both debug and non-debug kernels. 44 */ 45 46 #if defined(__STDC__) 47 extern int assfail(const char *, const char *, int); 48 #define VERIFY(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__))) 49 #ifndef ASSERT 50 #if DEBUG 51 #define ASSERT(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__))) 52 #else 53 #define ASSERT(x) ((void)0) 54 #endif 55 #endif 56 #else /* defined(__STDC__) */ 57 extern int assfail(); 58 #define VERIFY(EX) ((void)((EX) || assfail("EX", __FILE__, __LINE__))) 59 #if DEBUG 60 #define ASSERT(EX) ((void)((EX) || assfail("EX", __FILE__, __LINE__))) 61 #else 62 #define ASSERT(x) ((void)0) 63 #endif 64 #endif /* defined(__STDC__) */ 65 66 /* 67 * Assertion variants sensitive to the compilation data model 68 */ 69 #if defined(_LP64) 70 #define ASSERT64(x) ASSERT(x) 71 #define ASSERT32(x) 72 #else 73 #define ASSERT64(x) 74 #define ASSERT32(x) ASSERT(x) 75 #endif 76 77 /* 78 * IMPLY and EQUIV are assertions of the form: 79 * 80 * if (a) then (b) 81 * and 82 * if (a) then (b) *AND* if (b) then (a) 83 */ 84 #if DEBUG 85 #define IMPLY(A, B) \ 86 ((void)(((!(A)) || (B)) || \ 87 assfail("(" #A ") implies (" #B ")", __FILE__, __LINE__))) 88 #define EQUIV(A, B) \ 89 ((void)((!!(A) == !!(B)) || \ 90 assfail("(" #A ") is equivalent to (" #B ")", __FILE__, __LINE__))) 91 #else 92 #define IMPLY(A, B) ((void)0) 93 #define EQUIV(A, B) ((void)0) 94 #endif 95 96 /* 97 * ASSERT3() behaves like ASSERT() except that it is an explicit conditional, 98 * and prints out the values of the left and right hand expressions as part of 99 * the panic message to ease debugging. The three variants imply the type 100 * of their arguments. ASSERT3S() is for signed data types, ASSERT3U() is 101 * for unsigned, and ASSERT3P() is for pointers. The VERIFY3*() macros 102 * have the same relationship as above. 103 */ 104 extern void assfail3(const char *, uintmax_t, const char *, uintmax_t, 105 const char *, int); 106 #define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \ 107 const TYPE __left = (TYPE)(LEFT); \ 108 const TYPE __right = (TYPE)(RIGHT); \ 109 if (!(__left OP __right)) \ 110 assfail3(#LEFT " " #OP " " #RIGHT, \ 111 (uintmax_t)__left, #OP, (uintmax_t)__right, \ 112 __FILE__, __LINE__); \ 113 _NOTE(CONSTCOND) } while (0) 114 115 #define VERIFY3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t) 116 #define VERIFY3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t) 117 #define VERIFY3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t) 118 #if DEBUG 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 #else 123 #define ASSERT3S(x, y, z) ((void)0) 124 #define ASSERT3U(x, y, z) ((void)0) 125 #define ASSERT3P(x, y, z) ((void)0) 126 #endif 127 128 #ifdef _KERNEL 129 130 extern void abort_sequence_enter(char *); 131 extern void debug_enter(char *); 132 133 #endif /* _KERNEL */ 134 135 #if defined(DEBUG) && !defined(__sun) 136 /* CSTYLED */ 137 #define STATIC 138 #else 139 /* CSTYLED */ 140 #define STATIC static 141 #endif 142 143 #ifdef __cplusplus 144 } 145 #endif 146 147 #endif /* _SYS_DEBUG_H */ 148