Print this page
    
3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/uts/common/sys/debug.h
          +++ new/usr/src/uts/common/sys/debug.h
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License (the "License").
   6    6   * You may not use this file except in compliance with the License.
   7    7   *
   8    8   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9    9   * or http://www.opensolaris.org/os/licensing.
  10   10   * See the License for the specific language governing permissions
  11   11   * and limitations under the License.
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  
    | 
      ↓ open down ↓ | 
    15 lines elided | 
    
      ↑ open up ↑ | 
  
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
  25   25  
       26 +/*
       27 + * Copyright (c) 2012 by Delphix. All rights reserved.
       28 + */
       29 +
  26   30  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  27   31  /*        All Rights Reserved   */
  28   32  
  29   33  #ifndef _SYS_DEBUG_H
  30   34  #define _SYS_DEBUG_H
  31   35  
  32   36  #include <sys/isa_defs.h>
  33   37  #include <sys/types.h>
  34   38  #include <sys/note.h>
  35   39  
  36   40  #ifdef  __cplusplus
  37   41  extern "C" {
  38   42  #endif
  39   43  
  40   44  /*
  41   45   * ASSERT(ex) causes a panic or debugger entry if expression ex is not
  42   46   * true.  ASSERT() is included only for debugging, and is a no-op in
  43   47   * production kernels.  VERIFY(ex), on the other hand, behaves like
  44   48   * ASSERT and is evaluated on both debug and non-debug kernels.
  45   49   */
  46   50  
  47   51  #if defined(__STDC__)
  48   52  extern int assfail(const char *, const char *, int);
  49   53  #define VERIFY(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__)))
  50   54  #if DEBUG
  51   55  #define ASSERT(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__)))
  52   56  #else
  53   57  #define ASSERT(x)  ((void)0)
  54   58  #endif
  55   59  #else   /* defined(__STDC__) */
  56   60  extern int assfail();
  57   61  #define VERIFY(EX) ((void)((EX) || assfail("EX", __FILE__, __LINE__)))
  58   62  #if DEBUG
  59   63  #define ASSERT(EX) ((void)((EX) || assfail("EX", __FILE__, __LINE__)))
  60   64  #else
  61   65  #define ASSERT(x)  ((void)0)
  62   66  #endif
  63   67  #endif  /* defined(__STDC__) */
  64   68  
  65   69  /*
  66   70   * Assertion variants sensitive to the compilation data model
  67   71   */
  68   72  #if defined(_LP64)
  69   73  #define ASSERT64(x)     ASSERT(x)
  70   74  #define ASSERT32(x)
  71   75  #else
  72   76  #define ASSERT64(x)
  73   77  #define ASSERT32(x)     ASSERT(x)
  74   78  #endif
  75   79  
  76   80  /*
  77   81   * IMPLY and EQUIV are assertions of the form:
  78   82   *
  79   83   *      if (a) then (b)
  80   84   * and
  81   85   *      if (a) then (b) *AND* if (b) then (a)
  82   86   */
  83   87  #if DEBUG
  84   88  #define IMPLY(A, B) \
  85   89          ((void)(((!(A)) || (B)) || \
  86   90              assfail("(" #A ") implies (" #B ")", __FILE__, __LINE__)))
  87   91  #define EQUIV(A, B) \
  88   92          ((void)((!!(A) == !!(B)) || \
  89   93              assfail("(" #A ") is equivalent to (" #B ")", __FILE__, __LINE__)))
  90   94  #else
  91   95  #define IMPLY(A, B) ((void)0)
  92   96  #define EQUIV(A, B) ((void)0)
  93   97  #endif
  94   98  
  95   99  /*
  96  100   * ASSERT3() behaves like ASSERT() except that it is an explicit conditional,
  97  101   * and prints out the values of the left and right hand expressions as part of
  98  102   * the panic message to ease debugging.  The three variants imply the type
  99  103   * of their arguments.  ASSERT3S() is for signed data types, ASSERT3U() is
 100  104   * for unsigned, and ASSERT3P() is for pointers.  The VERIFY3*() macros
 101  105   * have the same relationship as above.
 102  106   */
 103  107  extern void assfail3(const char *, uintmax_t, const char *, uintmax_t,
 104  108      const char *, int);
 105  109  #define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \
 106  110          const TYPE __left = (TYPE)(LEFT); \
  
    | 
      ↓ open down ↓ | 
    71 lines elided | 
    
      ↑ open up ↑ | 
  
 107  111          const TYPE __right = (TYPE)(RIGHT); \
 108  112          if (!(__left OP __right)) \
 109  113                  assfail3(#LEFT " " #OP " " #RIGHT, \
 110  114                          (uintmax_t)__left, #OP, (uintmax_t)__right, \
 111  115                          __FILE__, __LINE__); \
 112  116  _NOTE(CONSTCOND) } while (0)
 113  117  
 114  118  #define VERIFY3S(x, y, z)       VERIFY3_IMPL(x, y, z, int64_t)
 115  119  #define VERIFY3U(x, y, z)       VERIFY3_IMPL(x, y, z, uint64_t)
 116  120  #define VERIFY3P(x, y, z)       VERIFY3_IMPL(x, y, z, uintptr_t)
      121 +#define VERIFY0(x)              VERIFY3_IMPL(x, ==, 0, uintmax_t)
      122 +
 117  123  #if DEBUG
 118  124  #define ASSERT3S(x, y, z)       VERIFY3_IMPL(x, y, z, int64_t)
 119  125  #define ASSERT3U(x, y, z)       VERIFY3_IMPL(x, y, z, uint64_t)
 120  126  #define ASSERT3P(x, y, z)       VERIFY3_IMPL(x, y, z, uintptr_t)
      127 +#define ASSERT0(x)              VERIFY3_IMPL(x, ==, 0, uintmax_t)
 121  128  #else
 122  129  #define ASSERT3S(x, y, z)       ((void)0)
 123  130  #define ASSERT3U(x, y, z)       ((void)0)
 124  131  #define ASSERT3P(x, y, z)       ((void)0)
      132 +#define ASSERT0(x)              ((void)0)
 125  133  #endif
 126  134  
 127  135  #ifdef  _KERNEL
 128  136  
 129  137  extern void abort_sequence_enter(char *);
 130  138  extern void debug_enter(char *);
 131  139  
 132  140  #endif  /* _KERNEL */
 133  141  
 134  142  #if defined(DEBUG) && !defined(__sun)
 135  143  /* CSTYLED */
 136  144  #define STATIC
 137  145  #else
 138  146  /* CSTYLED */
 139  147  #define STATIC static
 140  148  #endif
 141  149  
 142  150  #ifdef  __cplusplus
 143  151  }
 144  152  #endif
 145  153  
 146  154  #endif  /* _SYS_DEBUG_H */
  
    | 
      ↓ open down ↓ | 
    12 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX