xref: /illumos-gate/usr/src/uts/common/io/sfxge/sfxge_debug.h (revision 49ef7e0638c8b771d8a136eae78b1c0f99acc8e0)
1*49ef7e06SGarrett D'Amore /*
2*49ef7e06SGarrett D'Amore  * Copyright (c) 2008-2016 Solarflare Communications Inc.
3*49ef7e06SGarrett D'Amore  * All rights reserved.
4*49ef7e06SGarrett D'Amore  *
5*49ef7e06SGarrett D'Amore  * Redistribution and use in source and binary forms, with or without
6*49ef7e06SGarrett D'Amore  * modification, are permitted provided that the following conditions are met:
7*49ef7e06SGarrett D'Amore  *
8*49ef7e06SGarrett D'Amore  * 1. Redistributions of source code must retain the above copyright notice,
9*49ef7e06SGarrett D'Amore  *    this list of conditions and the following disclaimer.
10*49ef7e06SGarrett D'Amore  * 2. Redistributions in binary form must reproduce the above copyright notice,
11*49ef7e06SGarrett D'Amore  *    this list of conditions and the following disclaimer in the documentation
12*49ef7e06SGarrett D'Amore  *    and/or other materials provided with the distribution.
13*49ef7e06SGarrett D'Amore  *
14*49ef7e06SGarrett D'Amore  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15*49ef7e06SGarrett D'Amore  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16*49ef7e06SGarrett D'Amore  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17*49ef7e06SGarrett D'Amore  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18*49ef7e06SGarrett D'Amore  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19*49ef7e06SGarrett D'Amore  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20*49ef7e06SGarrett D'Amore  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21*49ef7e06SGarrett D'Amore  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22*49ef7e06SGarrett D'Amore  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23*49ef7e06SGarrett D'Amore  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24*49ef7e06SGarrett D'Amore  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*49ef7e06SGarrett D'Amore  *
26*49ef7e06SGarrett D'Amore  * The views and conclusions contained in the software and documentation are
27*49ef7e06SGarrett D'Amore  * those of the authors and should not be interpreted as representing official
28*49ef7e06SGarrett D'Amore  * policies, either expressed or implied, of the FreeBSD Project.
29*49ef7e06SGarrett D'Amore  */
30*49ef7e06SGarrett D'Amore 
31*49ef7e06SGarrett D'Amore #ifndef	_SYS_SFXGE_DEBUG_H
32*49ef7e06SGarrett D'Amore #define	_SYS_SFXGE_DEBUG_H
33*49ef7e06SGarrett D'Amore 
34*49ef7e06SGarrett D'Amore #include <sys/types.h>
35*49ef7e06SGarrett D'Amore 
36*49ef7e06SGarrett D'Amore #ifdef	__cplusplus
37*49ef7e06SGarrett D'Amore extern "C" {
38*49ef7e06SGarrett D'Amore #endif
39*49ef7e06SGarrett D'Amore 
40*49ef7e06SGarrett D'Amore #ifdef	DEBUG
41*49ef7e06SGarrett D'Amore 
42*49ef7e06SGarrett D'Amore extern boolean_t sfxge_aask;
43*49ef7e06SGarrett D'Amore 
44*49ef7e06SGarrett D'Amore #define	SFXGE_OBJ_CHECK(_objp, _type)					\
45*49ef7e06SGarrett D'Amore 	do {								\
46*49ef7e06SGarrett D'Amore 		uint8_t *p = (uint8_t *)(_objp);			\
47*49ef7e06SGarrett D'Amore 		size_t off;						\
48*49ef7e06SGarrett D'Amore 									\
49*49ef7e06SGarrett D'Amore 		for (off = 0; off < sizeof (_type); off++) {		\
50*49ef7e06SGarrett D'Amore 			char buf[MAXNAMELEN];				\
51*49ef7e06SGarrett D'Amore 									\
52*49ef7e06SGarrett D'Amore 			if (*p++ == 0)					\
53*49ef7e06SGarrett D'Amore 				continue;				\
54*49ef7e06SGarrett D'Amore 									\
55*49ef7e06SGarrett D'Amore 			(void) snprintf(buf, MAXNAMELEN - 1,		\
56*49ef7e06SGarrett D'Amore 			    "%s[%d]: non-zero byte found in %s "	\
57*49ef7e06SGarrett D'Amore 			    "at 0x%p+%lx", __FILE__, __LINE__, #_type,	\
58*49ef7e06SGarrett D'Amore 			    (void *)(_objp), off);			\
59*49ef7e06SGarrett D'Amore 									\
60*49ef7e06SGarrett D'Amore 			if (sfxge_aask)					\
61*49ef7e06SGarrett D'Amore 				debug_enter(buf);			\
62*49ef7e06SGarrett D'Amore 			break;						\
63*49ef7e06SGarrett D'Amore 		}							\
64*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
65*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
66*49ef7e06SGarrett D'Amore 
67*49ef7e06SGarrett D'Amore /* Log cmn_err(9F) messages to console and system log */
68*49ef7e06SGarrett D'Amore #define	SFXGE_CMN_ERR	""
69*49ef7e06SGarrett D'Amore 
70*49ef7e06SGarrett D'Amore #else	/* DEBUG */
71*49ef7e06SGarrett D'Amore 
72*49ef7e06SGarrett D'Amore #define	SFXGE_OBJ_CHECK(_objp, _type)
73*49ef7e06SGarrett D'Amore 
74*49ef7e06SGarrett D'Amore /* Log cmn_err(9F) messages to system log only */
75*49ef7e06SGarrett D'Amore #define	SFXGE_CMN_ERR	"!"
76*49ef7e06SGarrett D'Amore 
77*49ef7e06SGarrett D'Amore #endif	/* DEBUG */
78*49ef7e06SGarrett D'Amore 
79*49ef7e06SGarrett D'Amore #ifdef	__cplusplus
80*49ef7e06SGarrett D'Amore }
81*49ef7e06SGarrett D'Amore #endif
82*49ef7e06SGarrett D'Amore 
83*49ef7e06SGarrett D'Amore #endif	/* _SYS_SFXGE_DEBUG_H */
84