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