]> git.proxmox.com Git - mirror_spl-debian.git/blob - include/sys/debug.h
Imported Upstream version 0.6.2
[mirror_spl-debian.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://zfsonlinux.org/>.
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 * ASSERT0() - Assert value is zero, if not panic.
39 * VERIFY() - Verify X is true, if not panic.
40 * VERIFY3S() - Verify signed X OP Y is true, if not panic.
41 * VERIFY3U() - Verify unsigned X OP Y is true, if not panic.
42 * VERIFY3P() - Verify pointer X OP Y is true, if not panic.
43 * VERIFY0() - Verify value is zero, if not panic.
44 */
45
46 #ifndef _SPL_DEBUG_H
47 #define _SPL_DEBUG_H
48
49 #include <spl-debug.h>
50
51 #ifdef NDEBUG /* Debugging Disabled */
52
53 /* Define SPL_DEBUG_STR to make clear which ASSERT definitions are used */
54 #define SPL_DEBUG_STR ""
55
56 #define PANIC(fmt, a...) \
57 do { \
58 printk(KERN_EMERG fmt, ## a); \
59 spl_debug_bug(__FILE__, __FUNCTION__, __LINE__, 0); \
60 } while (0)
61
62 #define __ASSERT(x) ((void)0)
63 #define ASSERT(x) ((void)0)
64 #define ASSERTF(x, y, z...) ((void)0)
65 #define ASSERTV(x)
66 #define VERIFY(cond) \
67 do { \
68 if (unlikely(!(cond))) \
69 PANIC("VERIFY(" #cond ") failed\n"); \
70 } while (0)
71
72 #define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE, FMT, CAST) \
73 do { \
74 if (!((TYPE)(LEFT) OP (TYPE)(RIGHT))) \
75 PANIC("VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
76 "failed (" FMT " " #OP " " FMT ")\n", \
77 CAST (LEFT), CAST (RIGHT)); \
78 } while (0)
79
80 #define VERIFY3S(x,y,z) VERIFY3_IMPL(x, y, z, int64_t, "%lld", (long long))
81 #define VERIFY3U(x,y,z) VERIFY3_IMPL(x, y, z, uint64_t, "%llu", \
82 (unsigned long long))
83 #define VERIFY3P(x,y,z) VERIFY3_IMPL(x, y, z, uintptr_t, "%p", (void *))
84 #define VERIFY0(x) VERIFY3_IMPL(0, ==, x, int64_t, "%lld", (long long))
85
86 #define ASSERT3S(x,y,z) ((void)0)
87 #define ASSERT3U(x,y,z) ((void)0)
88 #define ASSERT3P(x,y,z) ((void)0)
89 #define ASSERT0(x) ((void)0)
90
91 #else /* Debugging Enabled */
92
93 /* Define SPL_DEBUG_STR to make clear which ASSERT definitions are used */
94 #define SPL_DEBUG_STR " (DEBUG mode)"
95
96 #define PANIC(fmt, a...) \
97 do { \
98 spl_debug_msg(NULL, 0, 0, \
99 __FILE__, __FUNCTION__, __LINE__, fmt, ## a); \
100 spl_debug_bug(__FILE__, __FUNCTION__, __LINE__, 0); \
101 } while (0)
102
103 /* ASSERTION that is safe to use within the debug system */
104 #define __ASSERT(cond) \
105 do { \
106 if (unlikely(!(cond))) { \
107 printk(KERN_EMERG "ASSERTION(" #cond ") failed\n"); \
108 BUG(); \
109 } \
110 } while (0)
111
112 /* ASSERTION that will debug log used outside the debug sysytem */
113 #define ASSERT(cond) \
114 do { \
115 if (unlikely(!(cond))) \
116 PANIC("ASSERTION(" #cond ") failed\n"); \
117 } while (0)
118
119 #define ASSERTF(cond, fmt, a...) \
120 do { \
121 if (unlikely(!(cond))) \
122 PANIC("ASSERTION(" #cond ") failed: " fmt, ## a); \
123 } while (0)
124
125 #define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE, FMT, CAST) \
126 do { \
127 if (!((TYPE)(LEFT) OP (TYPE)(RIGHT))) \
128 PANIC("VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
129 "failed (" FMT " " #OP " " FMT ")\n", \
130 CAST (LEFT), CAST (RIGHT)); \
131 } while (0)
132
133 #define VERIFY3S(x,y,z) VERIFY3_IMPL(x, y, z, int64_t, "%lld", (long long))
134 #define VERIFY3U(x,y,z) VERIFY3_IMPL(x, y, z, uint64_t, "%llu", \
135 (unsigned long long))
136 #define VERIFY3P(x,y,z) VERIFY3_IMPL(x, y, z, uintptr_t, "%p", (void *))
137 #define VERIFY0(x) VERIFY3_IMPL(0, ==, x, int64_t, "%lld", (long long))
138
139 #define ASSERT3S(x,y,z) VERIFY3S(x, y, z)
140 #define ASSERT3U(x,y,z) VERIFY3U(x, y, z)
141 #define ASSERT3P(x,y,z) VERIFY3P(x, y, z)
142 #define ASSERT0(x) VERIFY0(x)
143
144 #define ASSERTV(x) x
145 #define VERIFY(x) ASSERT(x)
146
147 #endif /* NDEBUG */
148 #endif /* SPL_DEBUG_H */