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*11173SJonathan.Adams@Sun.COM * Copyright 2009 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> 34*11173SJonathan.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 /* 77789Sahrens * ASSERT3() behaves like ASSERT() except that it is an explicit conditional, 78789Sahrens * and prints out the values of the left and right hand expressions as part of 79789Sahrens * the panic message to ease debugging. The three variants imply the type 80789Sahrens * of their arguments. ASSERT3S() is for signed data types, ASSERT3U() is 81789Sahrens * for unsigned, and ASSERT3P() is for pointers. The VERIFY3*() macros 82789Sahrens * have the same relationship as above. 83789Sahrens */ 84789Sahrens extern void assfail3(const char *, uintmax_t, const char *, uintmax_t, 85789Sahrens const char *, int); 86789Sahrens #define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \ 87789Sahrens const TYPE __left = (TYPE)(LEFT); \ 88789Sahrens const TYPE __right = (TYPE)(RIGHT); \ 89789Sahrens if (!(__left OP __right)) \ 90789Sahrens assfail3(#LEFT " " #OP " " #RIGHT, \ 91789Sahrens (uintmax_t)__left, #OP, (uintmax_t)__right, \ 92789Sahrens __FILE__, __LINE__); \ 93789Sahrens _NOTE(CONSTCOND) } while (0) 94789Sahrens 95789Sahrens #define VERIFY3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t) 96789Sahrens #define VERIFY3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t) 97789Sahrens #define VERIFY3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t) 98789Sahrens #if DEBUG 998269SMark.Musante@Sun.COM #define ASSERT3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t) 1008269SMark.Musante@Sun.COM #define ASSERT3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t) 1018269SMark.Musante@Sun.COM #define ASSERT3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t) 102789Sahrens #else 103789Sahrens #define ASSERT3S(x, y, z) ((void)0) 104789Sahrens #define ASSERT3U(x, y, z) ((void)0) 105789Sahrens #define ASSERT3P(x, y, z) ((void)0) 106789Sahrens #endif 107789Sahrens 1080Sstevel@tonic-gate #ifdef _KERNEL 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate extern void abort_sequence_enter(char *); 1110Sstevel@tonic-gate extern void debug_enter(char *); 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate #endif /* _KERNEL */ 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate #if defined(DEBUG) && !defined(__sun) 1160Sstevel@tonic-gate /* CSTYLED */ 1170Sstevel@tonic-gate #define STATIC 1180Sstevel@tonic-gate #else 1190Sstevel@tonic-gate /* CSTYLED */ 1200Sstevel@tonic-gate #define STATIC static 1210Sstevel@tonic-gate #endif 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate #ifdef __cplusplus 1240Sstevel@tonic-gate } 1250Sstevel@tonic-gate #endif 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate #endif /* _SYS_DEBUG_H */ 128