xref: /onnv-gate/usr/src/uts/common/sys/debug.h (revision 11474:857f9db4ef05)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
58269SMark.Musante@Sun.COM  * Common Development and Distribution License (the "License").
68269SMark.Musante@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*11474SJonathan.Adams@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27789Sahrens /*	  All Rights Reserved	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #ifndef _SYS_DEBUG_H
300Sstevel@tonic-gate #define	_SYS_DEBUG_H
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/isa_defs.h>
33789Sahrens #include <sys/types.h>
3411173SJonathan.Adams@Sun.COM #include <sys/note.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #ifdef	__cplusplus
370Sstevel@tonic-gate extern "C" {
380Sstevel@tonic-gate #endif
390Sstevel@tonic-gate 
400Sstevel@tonic-gate /*
410Sstevel@tonic-gate  * ASSERT(ex) causes a panic or debugger entry if expression ex is not
420Sstevel@tonic-gate  * true.  ASSERT() is included only for debugging, and is a no-op in
430Sstevel@tonic-gate  * production kernels.  VERIFY(ex), on the other hand, behaves like
44789Sahrens  * ASSERT and is evaluated on both debug and non-debug kernels.
450Sstevel@tonic-gate  */
460Sstevel@tonic-gate 
470Sstevel@tonic-gate #if defined(__STDC__)
480Sstevel@tonic-gate extern int assfail(const char *, const char *, int);
49789Sahrens #define	VERIFY(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__)))
500Sstevel@tonic-gate #if DEBUG
518269SMark.Musante@Sun.COM #define	ASSERT(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__)))
520Sstevel@tonic-gate #else
530Sstevel@tonic-gate #define	ASSERT(x)  ((void)0)
540Sstevel@tonic-gate #endif
550Sstevel@tonic-gate #else	/* defined(__STDC__) */
560Sstevel@tonic-gate extern int assfail();
57789Sahrens #define	VERIFY(EX) ((void)((EX) || assfail("EX", __FILE__, __LINE__)))
580Sstevel@tonic-gate #if DEBUG
598269SMark.Musante@Sun.COM #define	ASSERT(EX) ((void)((EX) || assfail("EX", __FILE__, __LINE__)))
600Sstevel@tonic-gate #else
610Sstevel@tonic-gate #define	ASSERT(x)  ((void)0)
620Sstevel@tonic-gate #endif
630Sstevel@tonic-gate #endif	/* defined(__STDC__) */
640Sstevel@tonic-gate 
650Sstevel@tonic-gate /*
660Sstevel@tonic-gate  * Assertion variants sensitive to the compilation data model
670Sstevel@tonic-gate  */
680Sstevel@tonic-gate #if defined(_LP64)
690Sstevel@tonic-gate #define	ASSERT64(x)	ASSERT(x)
700Sstevel@tonic-gate #define	ASSERT32(x)
710Sstevel@tonic-gate #else
720Sstevel@tonic-gate #define	ASSERT64(x)
730Sstevel@tonic-gate #define	ASSERT32(x)	ASSERT(x)
740Sstevel@tonic-gate #endif
750Sstevel@tonic-gate 
76789Sahrens /*
77*11474SJonathan.Adams@Sun.COM  * IMPLY and EQUIV are assertions of the form:
78*11474SJonathan.Adams@Sun.COM  *
79*11474SJonathan.Adams@Sun.COM  *	if (a) then (b)
80*11474SJonathan.Adams@Sun.COM  * and
81*11474SJonathan.Adams@Sun.COM  *	if (a) then (b) *AND* if (b) then (a)
82*11474SJonathan.Adams@Sun.COM  */
83*11474SJonathan.Adams@Sun.COM #if DEBUG
84*11474SJonathan.Adams@Sun.COM #define	IMPLY(A, B) \
85*11474SJonathan.Adams@Sun.COM 	((void)(((!(A)) || (B)) || \
86*11474SJonathan.Adams@Sun.COM 	    assfail("(" #A ") implies (" #B ")", __FILE__, __LINE__)))
87*11474SJonathan.Adams@Sun.COM #define	EQUIV(A, B) \
88*11474SJonathan.Adams@Sun.COM 	((void)((!!(A) == !!(B)) || \
89*11474SJonathan.Adams@Sun.COM 	    assfail("(" #A ") is equivalent to (" #B ")", __FILE__, __LINE__)))
90*11474SJonathan.Adams@Sun.COM #else
91*11474SJonathan.Adams@Sun.COM #define	IMPLY(A, B) ((void)0)
92*11474SJonathan.Adams@Sun.COM #define	EQUIV(A, B) ((void)0)
93*11474SJonathan.Adams@Sun.COM #endif
94*11474SJonathan.Adams@Sun.COM 
95*11474SJonathan.Adams@Sun.COM /*
96789Sahrens  * ASSERT3() behaves like ASSERT() except that it is an explicit conditional,
97789Sahrens  * and prints out the values of the left and right hand expressions as part of
98789Sahrens  * the panic message to ease debugging.  The three variants imply the type
99789Sahrens  * of their arguments.  ASSERT3S() is for signed data types, ASSERT3U() is
100789Sahrens  * for unsigned, and ASSERT3P() is for pointers.  The VERIFY3*() macros
101789Sahrens  * have the same relationship as above.
102789Sahrens  */
103789Sahrens extern void assfail3(const char *, uintmax_t, const char *, uintmax_t,
104789Sahrens     const char *, int);
105789Sahrens #define	VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \
106789Sahrens 	const TYPE __left = (TYPE)(LEFT); \
107789Sahrens 	const TYPE __right = (TYPE)(RIGHT); \
108789Sahrens 	if (!(__left OP __right)) \
109789Sahrens 		assfail3(#LEFT " " #OP " " #RIGHT, \
110789Sahrens 			(uintmax_t)__left, #OP, (uintmax_t)__right, \
111789Sahrens 			__FILE__, __LINE__); \
112789Sahrens _NOTE(CONSTCOND) } while (0)
113789Sahrens 
114789Sahrens #define	VERIFY3S(x, y, z)	VERIFY3_IMPL(x, y, z, int64_t)
115789Sahrens #define	VERIFY3U(x, y, z)	VERIFY3_IMPL(x, y, z, uint64_t)
116789Sahrens #define	VERIFY3P(x, y, z)	VERIFY3_IMPL(x, y, z, uintptr_t)
117789Sahrens #if DEBUG
1188269SMark.Musante@Sun.COM #define	ASSERT3S(x, y, z)	VERIFY3_IMPL(x, y, z, int64_t)
1198269SMark.Musante@Sun.COM #define	ASSERT3U(x, y, z)	VERIFY3_IMPL(x, y, z, uint64_t)
1208269SMark.Musante@Sun.COM #define	ASSERT3P(x, y, z)	VERIFY3_IMPL(x, y, z, uintptr_t)
121789Sahrens #else
122789Sahrens #define	ASSERT3S(x, y, z)	((void)0)
123789Sahrens #define	ASSERT3U(x, y, z)	((void)0)
124789Sahrens #define	ASSERT3P(x, y, z)	((void)0)
125789Sahrens #endif
126789Sahrens 
1270Sstevel@tonic-gate #ifdef	_KERNEL
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate extern void abort_sequence_enter(char *);
1300Sstevel@tonic-gate extern void debug_enter(char *);
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate #endif	/* _KERNEL */
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate #if defined(DEBUG) && !defined(__sun)
1350Sstevel@tonic-gate /* CSTYLED */
1360Sstevel@tonic-gate #define	STATIC
1370Sstevel@tonic-gate #else
1380Sstevel@tonic-gate /* CSTYLED */
1390Sstevel@tonic-gate #define	STATIC static
1400Sstevel@tonic-gate #endif
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate #ifdef	__cplusplus
1430Sstevel@tonic-gate }
1440Sstevel@tonic-gate #endif
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate #endif	/* _SYS_DEBUG_H */
147