xref: /minix3/sys/ufs/chfs/debug.h (revision d65f6f70097893d1dfe5e389f081f247bf3df183)
1*d65f6f70SBen Gras /*	$NetBSD: debug.h,v 1.1 2011/11/24 15:51:32 ahoka Exp $	*/
2*d65f6f70SBen Gras 
3*d65f6f70SBen Gras /*-
4*d65f6f70SBen Gras  * Copyright (c) 2010 Department of Software Engineering,
5*d65f6f70SBen Gras  *		      University of Szeged, Hungary
6*d65f6f70SBen Gras  * All rights reserved.
7*d65f6f70SBen Gras  *
8*d65f6f70SBen Gras  * This code is derived from software contributed to The NetBSD Foundation
9*d65f6f70SBen Gras  * by the Department of Software Engineering, University of Szeged, Hungary
10*d65f6f70SBen Gras  *
11*d65f6f70SBen Gras  * Redistribution and use in source and binary forms, with or without
12*d65f6f70SBen Gras  * modification, are permitted provided that the following conditions
13*d65f6f70SBen Gras  * are met:
14*d65f6f70SBen Gras  * 1. Redistributions of source code must retain the above copyright
15*d65f6f70SBen Gras  *    notice, this list of conditions and the following disclaimer.
16*d65f6f70SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
17*d65f6f70SBen Gras  *    notice, this list of conditions and the following disclaimer in the
18*d65f6f70SBen Gras  *    documentation and/or other materials provided with the distribution.
19*d65f6f70SBen Gras  *
20*d65f6f70SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21*d65f6f70SBen Gras  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22*d65f6f70SBen Gras  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23*d65f6f70SBen Gras  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24*d65f6f70SBen Gras  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25*d65f6f70SBen Gras  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26*d65f6f70SBen Gras  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27*d65f6f70SBen Gras  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28*d65f6f70SBen Gras  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29*d65f6f70SBen Gras  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30*d65f6f70SBen Gras  * SUCH DAMAGE.
31*d65f6f70SBen Gras  */
32*d65f6f70SBen Gras 
33*d65f6f70SBen Gras /*
34*d65f6f70SBen Gras  * XipFFS -- Xip Flash File System
35*d65f6f70SBen Gras  *
36*d65f6f70SBen Gras  * Copyright (C) 2009  Ferenc Havasi <havasi@inf.u-szeged.hu>,
37*d65f6f70SBen Gras  *                     Zoltan Sogor <weth@inf.u-szeged.hu>,
38*d65f6f70SBen Gras  *                     ...
39*d65f6f70SBen Gras  *                     University of Szeged, Hungary
40*d65f6f70SBen Gras  *
41*d65f6f70SBen Gras  *
42*d65f6f70SBen Gras  * For licensing information, see the file 'LICENCE' in this directory.
43*d65f6f70SBen Gras  *
44*d65f6f70SBen Gras  */
45*d65f6f70SBen Gras 
46*d65f6f70SBen Gras #ifndef __CHFS_DEBUG_H__
47*d65f6f70SBen Gras #define __CHFS_DEBUG_H__
48*d65f6f70SBen Gras 
49*d65f6f70SBen Gras #define CHFS_ERROR_PREFIX	"[CHFS ERROR]"
50*d65f6f70SBen Gras #define CHFS_WARNING_PREFIX	"[CHFS WARNING]"
51*d65f6f70SBen Gras #define CHFS_NOTICE_PREFIX	"[CHFS NOTICE]"
52*d65f6f70SBen Gras #define CHFS_DBG_PREFIX	"[CHFS DBG]"
53*d65f6f70SBen Gras #define CHFS_DBG2_PREFIX	"[CHFS DBG2]"
54*d65f6f70SBen Gras #define CHFS_DBG_EBH_PREFIX	"[CHFS DBG EBH]"
55*d65f6f70SBen Gras #define CHFS_DBG_GC_PREFIX	"[CHFS_GC DBG]"
56*d65f6f70SBen Gras 
57*d65f6f70SBen Gras #define unlikely(x) __builtin_expect ((x), 0)
58*d65f6f70SBen Gras 
59*d65f6f70SBen Gras 
60*d65f6f70SBen Gras 
61*d65f6f70SBen Gras #define debug_msg(pref, fmt, ...)                                              \
62*d65f6f70SBen Gras 	do {                                                                   \
63*d65f6f70SBen Gras 		printf(pref                                                    \
64*d65f6f70SBen Gras 			" %s: " fmt, __FUNCTION__ , ##__VA_ARGS__);            \
65*d65f6f70SBen Gras 	} while(0)
66*d65f6f70SBen Gras 
67*d65f6f70SBen Gras #define chfs_assert(expr) do {                                               \
68*d65f6f70SBen Gras 	if (unlikely(!(expr))) {                                               \
69*d65f6f70SBen Gras 		printf("CHFS assert failed in %s at %u\n", \
70*d65f6f70SBen Gras 			__func__, __LINE__);                     \
71*d65f6f70SBen Gras 		/*dump_stack();*/                                                  \
72*d65f6f70SBen Gras 	}                                                                      \
73*d65f6f70SBen Gras } while (0)
74*d65f6f70SBen Gras 
75*d65f6f70SBen Gras #ifdef DBG_MSG
76*d65f6f70SBen Gras 	#define chfs_err(fmt, ...) debug_msg(CHFS_ERROR_PREFIX, fmt, ##__VA_ARGS__)
77*d65f6f70SBen Gras 	#define chfs_warn(fmt, ...) debug_msg(CHFS_WARNING_PREFIX, fmt, ##__VA_ARGS__)
78*d65f6f70SBen Gras 	#define chfs_noti(fmt, ...) debug_msg(CHFS_NOTICE_PREFIX, fmt, ##__VA_ARGS__)
79*d65f6f70SBen Gras 	#define dbg(fmt, ...) debug_msg(CHFS_DBG_PREFIX, fmt, ##__VA_ARGS__)
80*d65f6f70SBen Gras 	#define dbg2(fmt, ...) debug_msg(CHFS_DBG2_PREFIX(fmt, ##__VA_ARGS__)
81*d65f6f70SBen Gras 	#define dbg_ebh(fmt, ...) debug_msg(CHFS_DBG_EBH_PREFIX, fmt, ##__VA_ARGS__)
82*d65f6f70SBen Gras #else
83*d65f6f70SBen Gras 	#define chfs_err(fmt, ...) debug_msg(CHFS_ERROR_PREFIX, fmt, ##__VA_ARGS__)
84*d65f6f70SBen Gras 	#define chfs_warn(fmt, ...) debug_msg(CHFS_WARNING_PREFIX, fmt, ##__VA_ARGS__)
85*d65f6f70SBen Gras 	#define chfs_noti(fmt, ...) debug_msg(CHFS_NOTICE_PREFIX, fmt, ##__VA_ARGS__)
86*d65f6f70SBen Gras 	#define dbg(fmt, ...)
87*d65f6f70SBen Gras 	#define dbg2(fmt, ...)
88*d65f6f70SBen Gras 	#define dbg_ebh(fmt, ...)
89*d65f6f70SBen Gras #endif
90*d65f6f70SBen Gras 
91*d65f6f70SBen Gras #ifdef DBG_MSG_GC
92*d65f6f70SBen Gras 	#define dbg_gc(fmt, ...) debug_msg(CHFS_DBG_GC_PREFIX, fmt, ##__VA_ARGS__)
93*d65f6f70SBen Gras #else
94*d65f6f70SBen Gras 	#define dbg_gc(fmt, ...)
95*d65f6f70SBen Gras #endif
96*d65f6f70SBen Gras 
97*d65f6f70SBen Gras #endif /* __CHFS_DEBUG_H__ */
98