Print this page
Test of DTrace assert probes

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/sys/debug.h
          +++ new/usr/src/uts/common/sys/debug.h
↓ open down ↓ 32 lines elided ↑ open up ↑
  33   33  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  34   34  /*        All Rights Reserved   */
  35   35  
  36   36  #ifndef _SYS_DEBUG_H
  37   37  #define _SYS_DEBUG_H
  38   38  
  39   39  #include <sys/isa_defs.h>
  40   40  #include <sys/types.h>
  41   41  #include <sys/note.h>
  42   42  
       43 +#ifdef KEBE
       44 +#include <sys/sdt.h>
       45 +#endif  /* KEBE */
       46 +
  43   47  #ifdef  __cplusplus
  44   48  extern "C" {
  45   49  #endif
  46   50  
  47   51  /*
  48   52   * ASSERT(ex) causes a panic or debugger entry if expression ex is not
  49   53   * true.  ASSERT() is included only for debugging, and is a no-op in
  50   54   * production kernels.  VERIFY(ex), on the other hand, behaves like
  51   55   * ASSERT and is evaluated on both debug and non-debug kernels.
       56 + *
       57 + * KEBE SAYS if "KEBE" is defined on a non-DEBUG kernel, the ASSERT() will
       58 + * form an SDT probe of the form sdt:module:function:assert-<lineno>, with
       59 + * probe arguments:
       60 + *
       61 + * arg0 -> file name
       62 + * arg1 -> line number
       63 + * arg2 -> EX
  52   64   */
  53   65  
       66 +#ifdef KEBE
       67 +/* XXX KEBE HOPES that __LINE__ evaluates the same, but isn't sure. */
       68 +#define ASSERTDTSTRBASE(x, y)   x ## y
       69 +#define ASSERTDTSTR(x, y)       ASSERTDTSTRBASE(x, y)
       70 +#define ASSERTDT(EX)    do { \
       71 +        extern void ASSERTDTSTR(__dtrace_probe_assert__, __LINE__)(uintptr_t, \
       72 +            uintptr_t, uintptr_t);                                      \
       73 +        if (!(EX))                                                      \
       74 +                ASSERTDTSTR(__dtrace_probe_assert__, __LINE__)          \
       75 +                    ((uintptr_t)__FILE__,                               \
       76 +                    (uintptr_t)__LINE__, (uintptr_t)#EX);               \
       77 +_NOTE(CONSTCOND) } while (0)
       78 +#endif  /* KEBE */
       79 +
       80 +
  54   81  extern int assfail(const char *, const char *, int);
  55   82  #define VERIFY(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__)))
  56   83  #if DEBUG
  57   84  #define ASSERT(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__)))
  58   85  #else
       86 +#ifdef KEBE
       87 +#define ASSERT(EX)      ASSERTDT(EX)
       88 +#else
  59   89  #define ASSERT(x)  ((void)0)
  60      -#endif
       90 +#endif /* KEBE */
       91 +#endif /* DEBUG */
  61   92  
  62   93  /*
  63   94   * Assertion variants sensitive to the compilation data model
  64   95   */
  65   96  #if defined(_LP64)
  66   97  #define ASSERT64(x)     ASSERT(x)
  67   98  #define ASSERT32(x)
  68   99  #else
  69  100  #define ASSERT64(x)
  70  101  #define ASSERT32(x)     ASSERT(x)
↓ open down ↓ 21 lines elided ↑ open up ↑
  92  123  /*
  93  124   * ASSERT3() behaves like ASSERT() except that it is an explicit conditional,
  94  125   * and prints out the values of the left and right hand expressions as part of
  95  126   * the panic message to ease debugging.  The three variants imply the type
  96  127   * of their arguments.  ASSERT3S() is for signed data types, ASSERT3U() is
  97  128   * for unsigned, and ASSERT3P() is for pointers.  The VERIFY3*() macros
  98  129   * have the same relationship as above.
  99  130   */
 100  131  extern void assfail3(const char *, uintmax_t, const char *, uintmax_t,
 101  132      const char *, int);
      133 +
      134 +#ifdef KEBE
      135 +/*
      136 + * KEBE SAYS, for the sdt:module:function:assert3-<lineno> will have more
      137 + * probe arguments:
      138 + *
      139 + * arg0 -> file name
      140 + * arg1 -> line number
      141 + * arg2 -> EX
      142 + * arg3 -> "left" boolean
      143 + * arg4 -> "OP" string
      144 + * arg5 -> "right" boolean
      145 + */
      146 +#define KEBE3_IMPL(LEFT, OP, RIGHT, TYPE)       do { \
      147 +        extern void ASSERTDTSTR(__dtrace_probe_assert3__, __LINE__)(   \
      148 +            uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t,      \
      149 +            uintptr_t);                                                 \
      150 +        const TYPE __left = (TYPE)(LEFT);                               \
      151 +        const TYPE __right = (TYPE)(RIGHT);                             \
      152 +        if (!(__left OP __right))                                       \
      153 +                ASSERTDTSTR(__dtrace_probe_assert3__, __LINE__)         \
      154 +                    ((uintptr_t)__FILE__,                               \
      155 +                    (uintptr_t)__LINE__,                                \
      156 +                    (uintptr_t)(#LEFT " " #OP " " #RIGHT),              \
      157 +                    (uintptr_t)__left, (uintptr_t)#OP,                  \
      158 +                    (uintptr_t)__right);                                \
      159 +_NOTE(CONSTCOND) } while (0)
      160 +#endif  /* KEBE */
      161 +
 102  162  #define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \
 103  163          const TYPE __left = (TYPE)(LEFT); \
 104  164          const TYPE __right = (TYPE)(RIGHT); \
 105  165          if (!(__left OP __right)) \
 106  166                  assfail3(#LEFT " " #OP " " #RIGHT, \
 107  167                          (uintmax_t)__left, #OP, (uintmax_t)__right, \
 108  168                          __FILE__, __LINE__); \
 109  169  _NOTE(CONSTCOND) } while (0)
 110  170  
 111  171  #define VERIFY3S(x, y, z)       VERIFY3_IMPL(x, y, z, int64_t)
 112  172  #define VERIFY3U(x, y, z)       VERIFY3_IMPL(x, y, z, uint64_t)
 113  173  #define VERIFY3P(x, y, z)       VERIFY3_IMPL(x, y, z, uintptr_t)
 114  174  #define VERIFY0(x)              VERIFY3_IMPL(x, ==, 0, uintmax_t)
 115  175  
 116  176  #if DEBUG
 117  177  #define ASSERT3S(x, y, z)       VERIFY3_IMPL(x, y, z, int64_t)
 118  178  #define ASSERT3U(x, y, z)       VERIFY3_IMPL(x, y, z, uint64_t)
 119  179  #define ASSERT3P(x, y, z)       VERIFY3_IMPL(x, y, z, uintptr_t)
 120  180  #define ASSERT0(x)              VERIFY3_IMPL(x, ==, 0, uintmax_t)
 121  181  #else
      182 +#ifdef KEBE
      183 +#define ASSERT3S(x, y, z)       KEBE3_IMPL(x, y, z, int64_t)
      184 +#define ASSERT3U(x, y, z)       KEBE3_IMPL(x, y, z, uint64_t)
      185 +#define ASSERT3P(x, y, z)       KEBE3_IMPL(x, y, z, uintptr_t)
      186 +#define ASSERT0(x)              KEBE3_IMPL(x, ==, 0, uintmax_t)
      187 +#else
 122  188  #define ASSERT3S(x, y, z)       ((void)0)
 123  189  #define ASSERT3U(x, y, z)       ((void)0)
 124  190  #define ASSERT3P(x, y, z)       ((void)0)
 125  191  #define ASSERT0(x)              ((void)0)
      192 +#endif /* KEBE */
 126  193  #endif
 127  194  
 128  195  /*
 129  196   * Compile-time assertion. The condition 'x' must be constant.
 130  197   */
 131  198  #define CTASSERT(x)             _CTASSERT(x, __LINE__)
 132  199  #define _CTASSERT(x, y)         __CTASSERT(x, y)
 133  200  #define __CTASSERT(x, y) \
 134  201          typedef char __compile_time_assertion__ ## y [(x) ? 1 : -1]
 135  202  
↓ open down ↓ 20 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX