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