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