debug.h revision 168404
1168404Spjd/* 2168404Spjd * CDDL HEADER START 3168404Spjd * 4168404Spjd * The contents of this file are subject to the terms of the 5168404Spjd * Common Development and Distribution License, Version 1.0 only 6168404Spjd * (the "License"). You may not use this file except in compliance 7168404Spjd * with the License. 8168404Spjd * 9168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10168404Spjd * or http://www.opensolaris.org/os/licensing. 11168404Spjd * See the License for the specific language governing permissions 12168404Spjd * and limitations under the License. 13168404Spjd * 14168404Spjd * When distributing Covered Code, include this CDDL HEADER in each 15168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16168404Spjd * If applicable, add the following below this CDDL HEADER, with the 17168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying 18168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner] 19168404Spjd * 20168404Spjd * CDDL HEADER END 21168404Spjd */ 22168404Spjd/* 23168404Spjd * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24168404Spjd * Use is subject to license terms. 25168404Spjd */ 26168404Spjd 27168404Spjd/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28168404Spjd/* All Rights Reserved */ 29168404Spjd 30168404Spjd 31168404Spjd#ifndef _SYS_DEBUG_H 32168404Spjd#define _SYS_DEBUG_H 33168404Spjd 34168404Spjd#pragma ident "%Z%%M% %I% %E% SMI" 35168404Spjd 36168404Spjd#include <sys/types.h> 37168404Spjd 38168404Spjd#ifdef __cplusplus 39168404Spjdextern "C" { 40168404Spjd#endif 41168404Spjd 42168404Spjd/* 43168404Spjd * ASSERT(ex) causes a panic or debugger entry if expression ex is not 44168404Spjd * true. ASSERT() is included only for debugging, and is a no-op in 45168404Spjd * production kernels. VERIFY(ex), on the other hand, behaves like 46168404Spjd * ASSERT and is evaluated on both debug and non-debug kernels. 47168404Spjd */ 48168404Spjd 49168404Spjd#if defined(__STDC__) 50168404Spjdextern int assfail(const char *, const char *, int); 51168404Spjd#define VERIFY(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__))) 52168404Spjd#if DEBUG 53168404Spjd#define ASSERT(EX) VERIFY(EX) 54168404Spjd#else 55168404Spjd#define ASSERT(x) ((void)0) 56168404Spjd#endif 57168404Spjd#else /* defined(__STDC__) */ 58168404Spjdextern int assfail(); 59168404Spjd#define VERIFY(EX) ((void)((EX) || assfail("EX", __FILE__, __LINE__))) 60168404Spjd#if DEBUG 61168404Spjd#define ASSERT(EX) VERIFY(EX) 62168404Spjd#else 63168404Spjd#define ASSERT(x) ((void)0) 64168404Spjd#endif 65168404Spjd#endif /* defined(__STDC__) */ 66168404Spjd 67168404Spjd/* 68168404Spjd * Assertion variants sensitive to the compilation data model 69168404Spjd */ 70168404Spjd#if defined(_LP64) 71168404Spjd#define ASSERT64(x) ASSERT(x) 72168404Spjd#define ASSERT32(x) 73168404Spjd#else 74168404Spjd#define ASSERT64(x) 75168404Spjd#define ASSERT32(x) ASSERT(x) 76168404Spjd#endif 77168404Spjd 78168404Spjd/* 79168404Spjd * ASSERT3() behaves like ASSERT() except that it is an explicit conditional, 80168404Spjd * and prints out the values of the left and right hand expressions as part of 81168404Spjd * the panic message to ease debugging. The three variants imply the type 82168404Spjd * of their arguments. ASSERT3S() is for signed data types, ASSERT3U() is 83168404Spjd * for unsigned, and ASSERT3P() is for pointers. The VERIFY3*() macros 84168404Spjd * have the same relationship as above. 85168404Spjd */ 86168404Spjdextern void assfail3(const char *, uintmax_t, const char *, uintmax_t, 87168404Spjd const char *, int); 88168404Spjd#define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \ 89168404Spjd const TYPE __left = (TYPE)(LEFT); \ 90168404Spjd const TYPE __right = (TYPE)(RIGHT); \ 91168404Spjd if (!(__left OP __right)) \ 92168404Spjd assfail3(#LEFT " " #OP " " #RIGHT, \ 93168404Spjd (uintmax_t)__left, #OP, (uintmax_t)__right, \ 94168404Spjd __FILE__, __LINE__); \ 95168404Spjd_NOTE(CONSTCOND) } while (0) 96168404Spjd 97168404Spjd#define VERIFY3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t) 98168404Spjd#define VERIFY3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t) 99168404Spjd#define VERIFY3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t) 100168404Spjd#if DEBUG 101168404Spjd#define ASSERT3S(x, y, z) VERIFY3S(x, y, z) 102168404Spjd#define ASSERT3U(x, y, z) VERIFY3U(x, y, z) 103168404Spjd#define ASSERT3P(x, y, z) VERIFY3P(x, y, z) 104168404Spjd#else 105168404Spjd#define ASSERT3S(x, y, z) ((void)0) 106168404Spjd#define ASSERT3U(x, y, z) ((void)0) 107168404Spjd#define ASSERT3P(x, y, z) ((void)0) 108168404Spjd#endif 109168404Spjd 110168404Spjd#ifdef _KERNEL 111168404Spjd 112168404Spjdextern void abort_sequence_enter(char *); 113168404Spjdextern void debug_enter(char *); 114168404Spjd 115168404Spjd#endif /* _KERNEL */ 116168404Spjd 117168404Spjd#if defined(DEBUG) && !defined(__sun) 118168404Spjd/* CSTYLED */ 119168404Spjd#define STATIC 120168404Spjd#else 121168404Spjd/* CSTYLED */ 122168404Spjd#define STATIC static 123168404Spjd#endif 124168404Spjd 125168404Spjd#ifdef __cplusplus 126168404Spjd} 127168404Spjd#endif 128168404Spjd 129168404Spjd#endif /* _SYS_DEBUG_H */ 130