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 /*
  23  * Copyright 2008-2013 Solarflare Communications Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #ifndef _SYS_SFXGE_DEBUG_H
  28 #define _SYS_SFXGE_DEBUG_H
  29 
  30 #include <sys/types.h>
  31 
  32 #ifdef  __cplusplus
  33 extern "C" {
  34 #endif
  35 
  36 #ifdef  DEBUG
  37 
  38 extern boolean_t sfxge_aask;
  39 
  40 #define SFXGE_OBJ_CHECK(_objp, _type)                                   \
  41         do {                                                            \
  42                 uint8_t *p = (uint8_t *)(_objp);                        \
  43                 size_t off;                                             \
  44                                                                         \
  45                 for (off = 0; off < sizeof (_type); off++) {         \
  46                         char buf[MAXNAMELEN];                           \
  47                                                                         \
  48                         if (*p++ == 0)                                  \
  49                                 continue;                               \
  50                                                                         \
  51                         (void) snprintf(buf, MAXNAMELEN - 1,            \
  52                             "%s[%d]: non-zero byte found in %s "        \
  53                             "at 0x%p+%lx", __FILE__, __LINE__, #_type,  \
  54                             (void *)(_objp), off);                      \
  55                                                                         \
  56                         if (sfxge_aask)                                 \
  57                                 debug_enter(buf);                       \
  58                         break;                                          \
  59                 }                                                       \
  60         _NOTE(CONSTANTCONDITION)                                        \
  61         } while (B_FALSE)
  62 
  63 /* Log cmn_err(9F) messages to console and system log */
  64 #define SFXGE_CMN_ERR   ""
  65 
  66 #else   /* DEBUG */
  67 
  68 #define SFXGE_OBJ_CHECK(_objp, _type)
  69 
  70 /* Log cmn_err(9F) messages to system log only */
  71 #define SFXGE_CMN_ERR   "!"
  72 
  73 #endif  /* DEBUG */
  74 
  75 #ifdef  __cplusplus
  76 }
  77 #endif
  78 
  79 #endif  /* _SYS_SFXGE_DEBUG_H */