xref: /illumos-gate/usr/src/uts/common/sys/debug.h (revision fa9e4066f08beec538e775443c5be79dd423fcab)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*fa9e4066Sahrens  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*fa9e4066Sahrens /*	  All Rights Reserved	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifndef _SYS_DEBUG_H
327c478bd9Sstevel@tonic-gate #define	_SYS_DEBUG_H
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
37*fa9e4066Sahrens #include <sys/types.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
407c478bd9Sstevel@tonic-gate extern "C" {
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * ASSERT(ex) causes a panic or debugger entry if expression ex is not
457c478bd9Sstevel@tonic-gate  * true.  ASSERT() is included only for debugging, and is a no-op in
467c478bd9Sstevel@tonic-gate  * production kernels.  VERIFY(ex), on the other hand, behaves like
47*fa9e4066Sahrens  * ASSERT and is evaluated on both debug and non-debug kernels.
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #if defined(__STDC__)
517c478bd9Sstevel@tonic-gate extern int assfail(const char *, const char *, int);
52*fa9e4066Sahrens #define	VERIFY(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__)))
537c478bd9Sstevel@tonic-gate #if DEBUG
54*fa9e4066Sahrens #define	ASSERT(EX) VERIFY(EX)
557c478bd9Sstevel@tonic-gate #else
567c478bd9Sstevel@tonic-gate #define	ASSERT(x)  ((void)0)
577c478bd9Sstevel@tonic-gate #endif
587c478bd9Sstevel@tonic-gate #else	/* defined(__STDC__) */
597c478bd9Sstevel@tonic-gate extern int assfail();
60*fa9e4066Sahrens #define	VERIFY(EX) ((void)((EX) || assfail("EX", __FILE__, __LINE__)))
617c478bd9Sstevel@tonic-gate #if DEBUG
62*fa9e4066Sahrens #define	ASSERT(EX) VERIFY(EX)
637c478bd9Sstevel@tonic-gate #else
647c478bd9Sstevel@tonic-gate #define	ASSERT(x)  ((void)0)
657c478bd9Sstevel@tonic-gate #endif
667c478bd9Sstevel@tonic-gate #endif	/* defined(__STDC__) */
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * Assertion variants sensitive to the compilation data model
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate #if defined(_LP64)
727c478bd9Sstevel@tonic-gate #define	ASSERT64(x)	ASSERT(x)
737c478bd9Sstevel@tonic-gate #define	ASSERT32(x)
747c478bd9Sstevel@tonic-gate #else
757c478bd9Sstevel@tonic-gate #define	ASSERT64(x)
767c478bd9Sstevel@tonic-gate #define	ASSERT32(x)	ASSERT(x)
777c478bd9Sstevel@tonic-gate #endif
787c478bd9Sstevel@tonic-gate 
79*fa9e4066Sahrens /*
80*fa9e4066Sahrens  * ASSERT3() behaves like ASSERT() except that it is an explicit conditional,
81*fa9e4066Sahrens  * and prints out the values of the left and right hand expressions as part of
82*fa9e4066Sahrens  * the panic message to ease debugging.  The three variants imply the type
83*fa9e4066Sahrens  * of their arguments.  ASSERT3S() is for signed data types, ASSERT3U() is
84*fa9e4066Sahrens  * for unsigned, and ASSERT3P() is for pointers.  The VERIFY3*() macros
85*fa9e4066Sahrens  * have the same relationship as above.
86*fa9e4066Sahrens  */
87*fa9e4066Sahrens extern void assfail3(const char *, uintmax_t, const char *, uintmax_t,
88*fa9e4066Sahrens     const char *, int);
89*fa9e4066Sahrens #define	VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \
90*fa9e4066Sahrens 	const TYPE __left = (TYPE)(LEFT); \
91*fa9e4066Sahrens 	const TYPE __right = (TYPE)(RIGHT); \
92*fa9e4066Sahrens 	if (!(__left OP __right)) \
93*fa9e4066Sahrens 		assfail3(#LEFT " " #OP " " #RIGHT, \
94*fa9e4066Sahrens 			(uintmax_t)__left, #OP, (uintmax_t)__right, \
95*fa9e4066Sahrens 			__FILE__, __LINE__); \
96*fa9e4066Sahrens _NOTE(CONSTCOND) } while (0)
97*fa9e4066Sahrens 
98*fa9e4066Sahrens 
99*fa9e4066Sahrens #define	VERIFY3S(x, y, z)	VERIFY3_IMPL(x, y, z, int64_t)
100*fa9e4066Sahrens #define	VERIFY3U(x, y, z)	VERIFY3_IMPL(x, y, z, uint64_t)
101*fa9e4066Sahrens #define	VERIFY3P(x, y, z)	VERIFY3_IMPL(x, y, z, uintptr_t)
102*fa9e4066Sahrens #if DEBUG
103*fa9e4066Sahrens #define	ASSERT3S(x, y, z)	VERIFY3S(x, y, z)
104*fa9e4066Sahrens #define	ASSERT3U(x, y, z)	VERIFY3U(x, y, z)
105*fa9e4066Sahrens #define	ASSERT3P(x, y, z)	VERIFY3P(x, y, z)
106*fa9e4066Sahrens #else
107*fa9e4066Sahrens #define	ASSERT3S(x, y, z)	((void)0)
108*fa9e4066Sahrens #define	ASSERT3U(x, y, z)	((void)0)
109*fa9e4066Sahrens #define	ASSERT3P(x, y, z)	((void)0)
110*fa9e4066Sahrens #endif
111*fa9e4066Sahrens 
1127c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate extern void abort_sequence_enter(char *);
1157c478bd9Sstevel@tonic-gate extern void debug_enter(char *);
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #ifdef MONITOR
1207c478bd9Sstevel@tonic-gate #define	MONITOR(id, w1, w2, w3, w4) monitor(id, w1, w2, w3, w4)
1217c478bd9Sstevel@tonic-gate #else
1227c478bd9Sstevel@tonic-gate #define	MONITOR(id, w1, w2, w3, w4)
1237c478bd9Sstevel@tonic-gate #endif
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate #if defined(DEBUG) && !defined(__sun)
1267c478bd9Sstevel@tonic-gate /* CSTYLED */
1277c478bd9Sstevel@tonic-gate #define	STATIC
1287c478bd9Sstevel@tonic-gate #else
1297c478bd9Sstevel@tonic-gate /* CSTYLED */
1307c478bd9Sstevel@tonic-gate #define	STATIC static
1317c478bd9Sstevel@tonic-gate #endif
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate #endif
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate #endif	/* _SYS_DEBUG_H */
138