Home | History | Annotate | Line # | Download | only in chfs
      1 /*	$NetBSD: debug.h,v 1.2 2012/04/12 15:31:01 ttoth 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 #ifndef __CHFS_DEBUG_H__
     34 #define __CHFS_DEBUG_H__
     35 
     36 #define CHFS_ERROR_PREFIX	"[CHFS ERROR]"
     37 #define CHFS_WARNING_PREFIX	"[CHFS WARNING]"
     38 #define CHFS_NOTICE_PREFIX	"[CHFS NOTICE]"
     39 #define CHFS_DBG_PREFIX	"[CHFS DBG]"
     40 #define CHFS_DBG2_PREFIX	"[CHFS DBG2]"
     41 #define CHFS_DBG_EBH_PREFIX	"[CHFS DBG EBH]"
     42 #define CHFS_DBG_GC_PREFIX	"[CHFS_GC DBG]"
     43 
     44 #define unlikely(x) __builtin_expect ((x), 0)
     45 
     46 
     47 
     48 #define debug_msg(pref, fmt, ...)                                              \
     49 	do {                                                                   \
     50 		printf(pref                                                    \
     51 			" %s: " fmt, __FUNCTION__ , ##__VA_ARGS__);            \
     52 	} while(0)
     53 
     54 #define chfs_assert(expr) do {                                               \
     55 	if (unlikely(!(expr))) {                                               \
     56 		printf("CHFS assert failed in %s at %u\n", \
     57 			__func__, __LINE__);                     \
     58 		/*dump_stack();*/                                                  \
     59 	}                                                                      \
     60 } while (0)
     61 
     62 #ifdef DBG_MSG
     63 	#define chfs_err(fmt, ...) debug_msg(CHFS_ERROR_PREFIX, fmt, ##__VA_ARGS__)
     64 	#define chfs_warn(fmt, ...) debug_msg(CHFS_WARNING_PREFIX, fmt, ##__VA_ARGS__)
     65 	#define chfs_noti(fmt, ...) debug_msg(CHFS_NOTICE_PREFIX, fmt, ##__VA_ARGS__)
     66 	#define dbg(fmt, ...) debug_msg(CHFS_DBG_PREFIX, fmt, ##__VA_ARGS__)
     67 	#define dbg2(fmt, ...) debug_msg(CHFS_DBG2_PREFIX(fmt, ##__VA_ARGS__)
     68 	#define dbg_ebh(fmt, ...) debug_msg(CHFS_DBG_EBH_PREFIX, fmt, ##__VA_ARGS__)
     69 #else
     70 	#define chfs_err(fmt, ...) debug_msg(CHFS_ERROR_PREFIX, fmt, ##__VA_ARGS__)
     71 	#define chfs_warn(fmt, ...) debug_msg(CHFS_WARNING_PREFIX, fmt, ##__VA_ARGS__)
     72 	#define chfs_noti(fmt, ...) debug_msg(CHFS_NOTICE_PREFIX, fmt, ##__VA_ARGS__)
     73 	#define dbg(fmt, ...)
     74 	#define dbg2(fmt, ...)
     75 	#define dbg_ebh(fmt, ...)
     76 #endif
     77 
     78 #ifdef DBG_MSG_GC
     79 	#define dbg_gc(fmt, ...) debug_msg(CHFS_DBG_GC_PREFIX, fmt, ##__VA_ARGS__)
     80 #else
     81 	#define dbg_gc(fmt, ...)
     82 #endif
     83 
     84 #endif /* __CHFS_DEBUG_H__ */
     85