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