]> git.proxmox.com Git - mirror_spl.git/blob - include/sys/debug.h
Split <sys/debug.h> header
[mirror_spl.git] / include / sys / debug.h
1 /*****************************************************************************\
2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
6 * UCRL-CODE-235197
7 *
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://github.com/behlendorf/spl/>.
10 *
11 * The SPL is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23 \*****************************************************************************/
24
25 /*
26 * Available Solaris debug functions. All of the ASSERT() macros will be
27 * compiled out when NDEBUG is defined, this is the default behavior for
28 * the SPL. To enable assertions use the --enable-debug with configure.
29 * The VERIFY() functions are never compiled out and cannot be disabled.
30 *
31 * PANIC() - Panic the node and print message.
32 * ASSERT() - Assert X is true, if not panic.
33 * ASSERTF() - Assert X is true, if not panic and print message.
34 * ASSERTV() - Wraps a variable declaration which is only used by ASSERT().
35 * ASSERT3S() - Assert signed X OP Y is true, if not panic.
36 * ASSERT3U() - Assert unsigned X OP Y is true, if not panic.
37 * ASSERT3P() - Assert pointer X OP Y is true, if not panic.
38 * VERIFY() - Verify X is true, if not panic.
39 * VERIFY3S() - Verify signed X OP Y is true, if not panic.
40 * VERIFY3U() - Verify unsigned X OP Y is true, if not panic.
41 * VERIFY3P() - Verify pointer X OP Y is true, if not panic.
42 */
43
44 #ifndef _SPL_DEBUG_H
45 #define _SPL_DEBUG_H
46
47 #ifdef NDEBUG /* Debugging Disabled */
48
49 #define PANIC(fmt, a...) \
50 do { \
51 printk(KERN_EMERG fmt, ## a); \
52 spl_debug_bug(__FILE__, __FUNCTION__, __LINE__, 0); \
53 } while (0)
54
55 #define __ASSERT(x) ((void)0)
56 #define ASSERT(x) ((void)0)
57 #define ASSERTF(x, y, z...) ((void)0)
58 #define ASSERTV(x)
59 #define VERIFY(cond) \
60 do { \
61 if (unlikely(!(cond))) \
62 PANIC("VERIFY(" #cond ") failed\n"); \
63 } while (0)
64
65 #define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE, FMT, CAST) \
66 do { \
67 if (!((TYPE)(LEFT) OP (TYPE)(RIGHT))) \
68 PANIC("VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
69 "failed (" FMT " " #OP " " FMT ")\n", \
70 CAST (LEFT), CAST (RIGHT)); \
71 } while (0)
72
73 #define VERIFY3S(x,y,z) VERIFY3_IMPL(x, y, z, int64_t, "%lld", (long long))
74 #define VERIFY3U(x,y,z) VERIFY3_IMPL(x, y, z, uint64_t, "%llu", \
75 (unsigned long long))
76 #define VERIFY3P(x,y,z) VERIFY3_IMPL(x, y, z, uintptr_t, "%p", (void *))
77
78 #define ASSERT3S(x,y,z) ((void)0)
79 #define ASSERT3U(x,y,z) ((void)0)
80 #define ASSERT3P(x,y,z) ((void)0)
81
82 #else /* Debugging Enabled */
83
84 #define PANIC(fmt, a...) \
85 do { \
86 spl_debug_msg(NULL, 0, 0, \
87 __FILE__, __FUNCTION__, __LINE__, fmt, ## a); \
88 spl_debug_bug(__FILE__, __FUNCTION__, __LINE__, 0); \
89 } while (0)
90
91 /* ASSERTION that is safe to use within the debug system */
92 #define __ASSERT(cond) \
93 do { \
94 if (unlikely(!(cond))) { \
95 printk(KERN_EMERG "ASSERTION(" #cond ") failed\n"); \
96 BUG(); \
97 } \
98 } while (0)
99
100 /* ASSERTION that will debug log used outside the debug sysytem */
101 #define ASSERT(cond) \
102 do { \
103 if (unlikely(!(cond))) \
104 PANIC("ASSERTION(" #cond ") failed\n"); \
105 } while (0)
106
107 #define ASSERTF(cond, fmt, a...) \
108 do { \
109 if (unlikely(!(cond))) \
110 PANIC("ASSERTION(" #cond ") failed: " fmt, ## a); \
111 } while (0)
112
113 #define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE, FMT, CAST) \
114 do { \
115 if (!((TYPE)(LEFT) OP (TYPE)(RIGHT))) \
116 PANIC("VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
117 "failed (" FMT " " #OP " " FMT ")\n", \
118 CAST (LEFT), CAST (RIGHT)); \
119 } while (0)
120
121 #define VERIFY3S(x,y,z) VERIFY3_IMPL(x, y, z, int64_t, "%lld", (long long))
122 #define VERIFY3U(x,y,z) VERIFY3_IMPL(x, y, z, uint64_t, "%llu", \
123 (unsigned long long))
124 #define VERIFY3P(x,y,z) VERIFY3_IMPL(x, y, z, uintptr_t, "%p", (void *))
125
126 #define ASSERT3S(x,y,z) VERIFY3S(x, y, z)
127 #define ASSERT3U(x,y,z) VERIFY3U(x, y, z)
128 #define ASSERT3P(x,y,z) VERIFY3P(x, y, z)
129
130 #define ASSERTV(x) x
131 #define VERIFY(x) ASSERT(x)
132
133 #endif /* NDEBUG */
134
135 extern void spl_debug_bug(char *file, const char *fn, const int line, int fl);
136 extern int spl_debug_msg(void *arg, int subsys, int mask, const char *file,
137 const char *fn, const int line, const char *format, ...);
138
139 #endif /* SPL_DEBUG_H */