xref: /titanic_44/usr/src/uts/common/sys/debug.h (revision d291d9f21e8c0417aec99de243dd48bc400002d0)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved	*/
29 
30 
31 #ifndef _SYS_DEBUG_H
32 #define	_SYS_DEBUG_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 #include <sys/isa_defs.h>
37 #include <sys/types.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 /*
44  * ASSERT(ex) causes a panic or debugger entry if expression ex is not
45  * true.  ASSERT() is included only for debugging, and is a no-op in
46  * production kernels.  VERIFY(ex), on the other hand, behaves like
47  * ASSERT and is evaluated on both debug and non-debug kernels.
48  */
49 
50 #if defined(__STDC__)
51 extern int assfail(const char *, const char *, int);
52 #define	VERIFY(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__)))
53 #if DEBUG
54 #define	ASSERT(EX) VERIFY(EX)
55 #else
56 #define	ASSERT(x)  ((void)0)
57 #endif
58 #else	/* defined(__STDC__) */
59 extern int assfail();
60 #define	VERIFY(EX) ((void)((EX) || assfail("EX", __FILE__, __LINE__)))
61 #if DEBUG
62 #define	ASSERT(EX) VERIFY(EX)
63 #else
64 #define	ASSERT(x)  ((void)0)
65 #endif
66 #endif	/* defined(__STDC__) */
67 
68 /*
69  * Assertion variants sensitive to the compilation data model
70  */
71 #if defined(_LP64)
72 #define	ASSERT64(x)	ASSERT(x)
73 #define	ASSERT32(x)
74 #else
75 #define	ASSERT64(x)
76 #define	ASSERT32(x)	ASSERT(x)
77 #endif
78 
79 /*
80  * ASSERT3() behaves like ASSERT() except that it is an explicit conditional,
81  * and prints out the values of the left and right hand expressions as part of
82  * the panic message to ease debugging.  The three variants imply the type
83  * of their arguments.  ASSERT3S() is for signed data types, ASSERT3U() is
84  * for unsigned, and ASSERT3P() is for pointers.  The VERIFY3*() macros
85  * have the same relationship as above.
86  */
87 extern void assfail3(const char *, uintmax_t, const char *, uintmax_t,
88     const char *, int);
89 #define	VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \
90 	const TYPE __left = (TYPE)(LEFT); \
91 	const TYPE __right = (TYPE)(RIGHT); \
92 	if (!(__left OP __right)) \
93 		assfail3(#LEFT " " #OP " " #RIGHT, \
94 			(uintmax_t)__left, #OP, (uintmax_t)__right, \
95 			__FILE__, __LINE__); \
96 _NOTE(CONSTCOND) } while (0)
97 
98 
99 #define	VERIFY3S(x, y, z)	VERIFY3_IMPL(x, y, z, int64_t)
100 #define	VERIFY3U(x, y, z)	VERIFY3_IMPL(x, y, z, uint64_t)
101 #define	VERIFY3P(x, y, z)	VERIFY3_IMPL(x, y, z, uintptr_t)
102 #if DEBUG
103 #define	ASSERT3S(x, y, z)	VERIFY3S(x, y, z)
104 #define	ASSERT3U(x, y, z)	VERIFY3U(x, y, z)
105 #define	ASSERT3P(x, y, z)	VERIFY3P(x, y, z)
106 #else
107 #define	ASSERT3S(x, y, z)	((void)0)
108 #define	ASSERT3U(x, y, z)	((void)0)
109 #define	ASSERT3P(x, y, z)	((void)0)
110 #endif
111 
112 #ifdef	_KERNEL
113 
114 extern void abort_sequence_enter(char *);
115 extern void debug_enter(char *);
116 
117 #endif	/* _KERNEL */
118 
119 #ifdef MONITOR
120 #define	MONITOR(id, w1, w2, w3, w4) monitor(id, w1, w2, w3, w4)
121 #else
122 #define	MONITOR(id, w1, w2, w3, w4)
123 #endif
124 
125 #if defined(DEBUG) && !defined(__sun)
126 /* CSTYLED */
127 #define	STATIC
128 #else
129 /* CSTYLED */
130 #define	STATIC static
131 #endif
132 
133 #ifdef	__cplusplus
134 }
135 #endif
136 
137 #endif	/* _SYS_DEBUG_H */
138