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