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 (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21/* 22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26/* 27 * Copyright (c) 2012 by Delphix. All rights reserved. 28 */ 29 30/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 31/* All Rights Reserved */ 32 33#ifndef _SYS_DEBUG_H 34#define _SYS_DEBUG_H 35 36#include <sys/types.h> 37#include <sys/note.h> 38 39#ifdef __cplusplus 40extern "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__) 51extern int assfail(const char *, const char *, int); 52#define VERIFY(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__))) 53#ifdef DEBUG 54#define ASSERT(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__))) 55#else 56#define ASSERT(x) ((void)0) 57#endif 58#else /* defined(__STDC__) */ 59extern int assfail(); 60#define VERIFY(EX) ((void)((EX) || assfail("EX", __FILE__, __LINE__))) 61#ifdef DEBUG 62#define ASSERT(EX) ((void)((EX) || assfail("EX", __FILE__, __LINE__))) 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 * IMPLY and EQUIV are assertions of the form: 81 * 82 * if (a) then (b) 83 * and 84 * if (a) then (b) *AND* if (b) then (a) 85 */ 86#ifdef DEBUG 87#define IMPLY(A, B) \ 88 ((void)(((!(A)) || (B)) || \ 89 assfail("(" #A ") implies (" #B ")", __FILE__, __LINE__))) 90#define EQUIV(A, B) \ 91 ((void)((!!(A) == !!(B)) || \ 92 assfail("(" #A ") is equivalent to (" #B ")", __FILE__, __LINE__))) 93#else 94#define IMPLY(A, B) ((void)0) 95#define EQUIV(A, B) ((void)0) 96#endif 97 98/* 99 * ASSERT3() behaves like ASSERT() except that it is an explicit conditional, 100 * and prints out the values of the left and right hand expressions as part of 101 * the panic message to ease debugging. The three variants imply the type 102 * of their arguments. ASSERT3S() is for signed data types, ASSERT3U() is 103 * for unsigned, and ASSERT3P() is for pointers. The VERIFY3*() macros 104 * have the same relationship as above. 105 */ 106extern void assfail3(const char *, uintmax_t, const char *, uintmax_t, 107 const char *, int); 108#define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \ 109 const TYPE __left = (TYPE)(LEFT); \ 110 const TYPE __right = (TYPE)(RIGHT); \ 111 if (!(__left OP __right)) \ 112 assfail3(#LEFT " " #OP " " #RIGHT, \ 113 (uintmax_t)__left, #OP, (uintmax_t)__right, \ 114 __FILE__, __LINE__); \ 115_NOTE(CONSTCOND) } while (0) 116 117#define VERIFY3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t) 118#define VERIFY3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t) 119#define VERIFY3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t) 120#define VERIFY0(x) VERIFY3_IMPL(x, ==, 0, uintmax_t) 121 122#ifdef DEBUG 123#define ASSERT3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t) 124#define ASSERT3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t) 125#define ASSERT3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t) 126#define ASSERT0(x) VERIFY3_IMPL(x, ==, 0, uintmax_t) 127#else 128#define ASSERT3S(x, y, z) ((void)0) 129#define ASSERT3U(x, y, z) ((void)0) 130#define ASSERT3P(x, y, z) ((void)0) 131#define ASSERT0(x) ((void)0) 132#endif 133 134#ifdef _KERNEL 135 136extern void abort_sequence_enter(char *); 137extern void debug_enter(char *); 138 139#endif /* _KERNEL */ 140 141#if defined(DEBUG) && !defined(__sun) 142/* CSTYLED */ 143#define STATIC 144#else 145/* CSTYLED */ 146#define STATIC static 147#endif 148 149#ifdef __cplusplus 150} 151#endif 152 153#endif /* _SYS_DEBUG_H */ 154