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 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 23*789Sahrens * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*789Sahrens /* All Rights Reserved */ 290Sstevel@tonic-gate 300Sstevel@tonic-gate 310Sstevel@tonic-gate #ifndef _SYS_DEBUG_H 320Sstevel@tonic-gate #define _SYS_DEBUG_H 330Sstevel@tonic-gate 340Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 350Sstevel@tonic-gate 360Sstevel@tonic-gate #include <sys/isa_defs.h> 37*789Sahrens #include <sys/types.h> 380Sstevel@tonic-gate 390Sstevel@tonic-gate #ifdef __cplusplus 400Sstevel@tonic-gate extern "C" { 410Sstevel@tonic-gate #endif 420Sstevel@tonic-gate 430Sstevel@tonic-gate /* 440Sstevel@tonic-gate * ASSERT(ex) causes a panic or debugger entry if expression ex is not 450Sstevel@tonic-gate * true. ASSERT() is included only for debugging, and is a no-op in 460Sstevel@tonic-gate * production kernels. VERIFY(ex), on the other hand, behaves like 47*789Sahrens * ASSERT and is evaluated on both debug and non-debug kernels. 480Sstevel@tonic-gate */ 490Sstevel@tonic-gate 500Sstevel@tonic-gate #if defined(__STDC__) 510Sstevel@tonic-gate extern int assfail(const char *, const char *, int); 52*789Sahrens #define VERIFY(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__))) 530Sstevel@tonic-gate #if DEBUG 54*789Sahrens #define ASSERT(EX) VERIFY(EX) 550Sstevel@tonic-gate #else 560Sstevel@tonic-gate #define ASSERT(x) ((void)0) 570Sstevel@tonic-gate #endif 580Sstevel@tonic-gate #else /* defined(__STDC__) */ 590Sstevel@tonic-gate extern int assfail(); 60*789Sahrens #define VERIFY(EX) ((void)((EX) || assfail("EX", __FILE__, __LINE__))) 610Sstevel@tonic-gate #if DEBUG 62*789Sahrens #define ASSERT(EX) VERIFY(EX) 630Sstevel@tonic-gate #else 640Sstevel@tonic-gate #define ASSERT(x) ((void)0) 650Sstevel@tonic-gate #endif 660Sstevel@tonic-gate #endif /* defined(__STDC__) */ 670Sstevel@tonic-gate 680Sstevel@tonic-gate /* 690Sstevel@tonic-gate * Assertion variants sensitive to the compilation data model 700Sstevel@tonic-gate */ 710Sstevel@tonic-gate #if defined(_LP64) 720Sstevel@tonic-gate #define ASSERT64(x) ASSERT(x) 730Sstevel@tonic-gate #define ASSERT32(x) 740Sstevel@tonic-gate #else 750Sstevel@tonic-gate #define ASSERT64(x) 760Sstevel@tonic-gate #define ASSERT32(x) ASSERT(x) 770Sstevel@tonic-gate #endif 780Sstevel@tonic-gate 79*789Sahrens /* 80*789Sahrens * ASSERT3() behaves like ASSERT() except that it is an explicit conditional, 81*789Sahrens * and prints out the values of the left and right hand expressions as part of 82*789Sahrens * the panic message to ease debugging. The three variants imply the type 83*789Sahrens * of their arguments. ASSERT3S() is for signed data types, ASSERT3U() is 84*789Sahrens * for unsigned, and ASSERT3P() is for pointers. The VERIFY3*() macros 85*789Sahrens * have the same relationship as above. 86*789Sahrens */ 87*789Sahrens extern void assfail3(const char *, uintmax_t, const char *, uintmax_t, 88*789Sahrens const char *, int); 89*789Sahrens #define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \ 90*789Sahrens const TYPE __left = (TYPE)(LEFT); \ 91*789Sahrens const TYPE __right = (TYPE)(RIGHT); \ 92*789Sahrens if (!(__left OP __right)) \ 93*789Sahrens assfail3(#LEFT " " #OP " " #RIGHT, \ 94*789Sahrens (uintmax_t)__left, #OP, (uintmax_t)__right, \ 95*789Sahrens __FILE__, __LINE__); \ 96*789Sahrens _NOTE(CONSTCOND) } while (0) 97*789Sahrens 98*789Sahrens 99*789Sahrens #define VERIFY3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t) 100*789Sahrens #define VERIFY3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t) 101*789Sahrens #define VERIFY3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t) 102*789Sahrens #if DEBUG 103*789Sahrens #define ASSERT3S(x, y, z) VERIFY3S(x, y, z) 104*789Sahrens #define ASSERT3U(x, y, z) VERIFY3U(x, y, z) 105*789Sahrens #define ASSERT3P(x, y, z) VERIFY3P(x, y, z) 106*789Sahrens #else 107*789Sahrens #define ASSERT3S(x, y, z) ((void)0) 108*789Sahrens #define ASSERT3U(x, y, z) ((void)0) 109*789Sahrens #define ASSERT3P(x, y, z) ((void)0) 110*789Sahrens #endif 111*789Sahrens 1120Sstevel@tonic-gate #ifdef _KERNEL 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate extern void abort_sequence_enter(char *); 1150Sstevel@tonic-gate extern void debug_enter(char *); 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate #endif /* _KERNEL */ 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate #ifdef MONITOR 1200Sstevel@tonic-gate #define MONITOR(id, w1, w2, w3, w4) monitor(id, w1, w2, w3, w4) 1210Sstevel@tonic-gate #else 1220Sstevel@tonic-gate #define MONITOR(id, w1, w2, w3, w4) 1230Sstevel@tonic-gate #endif 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate #if defined(DEBUG) && !defined(__sun) 1260Sstevel@tonic-gate /* CSTYLED */ 1270Sstevel@tonic-gate #define STATIC 1280Sstevel@tonic-gate #else 1290Sstevel@tonic-gate /* CSTYLED */ 1300Sstevel@tonic-gate #define STATIC static 1310Sstevel@tonic-gate #endif 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate #ifdef __cplusplus 1340Sstevel@tonic-gate } 1350Sstevel@tonic-gate #endif 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate #endif /* _SYS_DEBUG_H */ 138