xref: /titanic_51/usr/src/uts/common/sys/debug.h (revision b72c368a02e0464faeef362bc5a1cf0fc69981da)
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 2009 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/isa_defs.h>
33 #include <sys/types.h>
34 #include <sys/note.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * ASSERT(ex) causes a panic or debugger entry if expression ex is not
42  * true.  ASSERT() is included only for debugging, and is a no-op in
43  * production kernels.  VERIFY(ex), on the other hand, behaves like
44  * ASSERT and is evaluated on both debug and non-debug kernels.
45  */
46 
47 #if defined(__STDC__)
48 extern int assfail(const char *, const char *, int);
49 #define	VERIFY(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__)))
50 #if DEBUG
51 #define	ASSERT(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__)))
52 #else
53 #define	ASSERT(x)  ((void)0)
54 #endif
55 #else	/* defined(__STDC__) */
56 extern int assfail();
57 #define	VERIFY(EX) ((void)((EX) || assfail("EX", __FILE__, __LINE__)))
58 #if DEBUG
59 #define	ASSERT(EX) ((void)((EX) || assfail("EX", __FILE__, __LINE__)))
60 #else
61 #define	ASSERT(x)  ((void)0)
62 #endif
63 #endif	/* defined(__STDC__) */
64 
65 /*
66  * Assertion variants sensitive to the compilation data model
67  */
68 #if defined(_LP64)
69 #define	ASSERT64(x)	ASSERT(x)
70 #define	ASSERT32(x)
71 #else
72 #define	ASSERT64(x)
73 #define	ASSERT32(x)	ASSERT(x)
74 #endif
75 
76 /*
77  * ASSERT3() behaves like ASSERT() except that it is an explicit conditional,
78  * and prints out the values of the left and right hand expressions as part of
79  * the panic message to ease debugging.  The three variants imply the type
80  * of their arguments.  ASSERT3S() is for signed data types, ASSERT3U() is
81  * for unsigned, and ASSERT3P() is for pointers.  The VERIFY3*() macros
82  * have the same relationship as above.
83  */
84 extern void assfail3(const char *, uintmax_t, const char *, uintmax_t,
85     const char *, int);
86 #define	VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \
87 	const TYPE __left = (TYPE)(LEFT); \
88 	const TYPE __right = (TYPE)(RIGHT); \
89 	if (!(__left OP __right)) \
90 		assfail3(#LEFT " " #OP " " #RIGHT, \
91 			(uintmax_t)__left, #OP, (uintmax_t)__right, \
92 			__FILE__, __LINE__); \
93 _NOTE(CONSTCOND) } while (0)
94 
95 #define	VERIFY3S(x, y, z)	VERIFY3_IMPL(x, y, z, int64_t)
96 #define	VERIFY3U(x, y, z)	VERIFY3_IMPL(x, y, z, uint64_t)
97 #define	VERIFY3P(x, y, z)	VERIFY3_IMPL(x, y, z, uintptr_t)
98 #if DEBUG
99 #define	ASSERT3S(x, y, z)	VERIFY3_IMPL(x, y, z, int64_t)
100 #define	ASSERT3U(x, y, z)	VERIFY3_IMPL(x, y, z, uint64_t)
101 #define	ASSERT3P(x, y, z)	VERIFY3_IMPL(x, y, z, uintptr_t)
102 #else
103 #define	ASSERT3S(x, y, z)	((void)0)
104 #define	ASSERT3U(x, y, z)	((void)0)
105 #define	ASSERT3P(x, y, z)	((void)0)
106 #endif
107 
108 #ifdef	_KERNEL
109 
110 extern void abort_sequence_enter(char *);
111 extern void debug_enter(char *);
112 
113 #endif	/* _KERNEL */
114 
115 #if defined(DEBUG) && !defined(__sun)
116 /* CSTYLED */
117 #define	STATIC
118 #else
119 /* CSTYLED */
120 #define	STATIC static
121 #endif
122 
123 #ifdef	__cplusplus
124 }
125 #endif
126 
127 #endif	/* _SYS_DEBUG_H */
128