]>
Commit | Line | Data |
---|---|---|
4b393c50 | 1 | /* |
716154c5 BB |
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>. | |
715f6251 BB |
6 | * UCRL-CODE-235197 |
7 | * | |
716154c5 | 8 | * This file is part of the SPL, Solaris Porting Layer. |
716154c5 BB |
9 | * |
10 | * The SPL is free software; you can redistribute it and/or modify it | |
11 | * under the terms of the GNU General Public License as published by the | |
12 | * Free Software Foundation; either version 2 of the License, or (at your | |
13 | * option) any later version. | |
715f6251 | 14 | * |
716154c5 | 15 | * The SPL is distributed in the hope that it will be useful, but WITHOUT |
715f6251 BB |
16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
18 | * for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License along | |
716154c5 | 21 | * with the SPL. If not, see <http://www.gnu.org/licenses/>. |
4b393c50 | 22 | */ |
715f6251 | 23 | |
55abb092 BB |
24 | /* |
25 | * Available Solaris debug functions. All of the ASSERT() macros will be | |
26 | * compiled out when NDEBUG is defined, this is the default behavior for | |
27 | * the SPL. To enable assertions use the --enable-debug with configure. | |
28 | * The VERIFY() functions are never compiled out and cannot be disabled. | |
29 | * | |
30 | * PANIC() - Panic the node and print message. | |
31 | * ASSERT() - Assert X is true, if not panic. | |
dfbd813e | 32 | * ASSERT3B() - Assert boolean X OP Y is true, if not panic. |
55abb092 BB |
33 | * ASSERT3S() - Assert signed X OP Y is true, if not panic. |
34 | * ASSERT3U() - Assert unsigned X OP Y is true, if not panic. | |
35 | * ASSERT3P() - Assert pointer X OP Y is true, if not panic. | |
1c6d149f | 36 | * ASSERT0() - Assert value is zero, if not panic. |
55abb092 | 37 | * VERIFY() - Verify X is true, if not panic. |
dfbd813e | 38 | * VERIFY3B() - Verify boolean X OP Y is true, if not panic. |
55abb092 BB |
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. | |
1c6d149f | 42 | * VERIFY0() - Verify value is zero, if not panic. |
55abb092 BB |
43 | */ |
44 | ||
f4b37741 | 45 | #ifndef _SPL_DEBUG_H |
8d9a23e8 | 46 | #define _SPL_DEBUG_H |
f4b37741 | 47 | |
8d9a23e8 BB |
48 | /* |
49 | * Common DEBUG functionality. | |
50 | */ | |
74756182 MM |
51 | #define __printflike(a, b) __printf(a, b) |
52 | ||
2a8ba608 MM |
53 | #ifndef __maybe_unused |
54 | #define __maybe_unused __attribute__((unused)) | |
55 | #endif | |
56 | ||
8d9a23e8 BB |
57 | int spl_panic(const char *file, const char *func, int line, |
58 | const char *fmt, ...); | |
59 | void spl_dumpstack(void); | |
57d1b188 | 60 | |
8d9a23e8 BB |
61 | #define PANIC(fmt, a...) \ |
62 | spl_panic(__FILE__, __FUNCTION__, __LINE__, fmt, ## a) | |
57d1b188 | 63 | |
7ada752a AZ |
64 | #define VERIFY(cond) \ |
65 | (void) (unlikely(!(cond)) && \ | |
8d9a23e8 BB |
66 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ |
67 | "%s", "VERIFY(" #cond ") failed\n")) | |
57d1b188 | 68 | |
7ada752a | 69 | #define VERIFY3B(LEFT, OP, RIGHT) do { \ |
c94d648b | 70 | const boolean_t _verify3_left = (boolean_t)(LEFT); \ |
7ada752a | 71 | const boolean_t _verify3_right = (boolean_t)(RIGHT); \ |
c94d648b | 72 | if (unlikely(!(_verify3_left OP _verify3_right))) \ |
2b5cd599 | 73 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ |
6e8b2688 | 74 | "VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \ |
7ada752a AZ |
75 | "failed (%d " #OP " %d)\n", \ |
76 | (boolean_t)(_verify3_left), \ | |
77 | (boolean_t)(_verify3_right)); \ | |
2b5cd599 | 78 | } while (0) |
57d1b188 | 79 | |
7ada752a | 80 | #define VERIFY3S(LEFT, OP, RIGHT) do { \ |
c94d648b AM |
81 | const int64_t _verify3_left = (int64_t)(LEFT); \ |
82 | const int64_t _verify3_right = (int64_t)(RIGHT); \ | |
83 | if (unlikely(!(_verify3_left OP _verify3_right))) \ | |
6e8b2688 PD |
84 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ |
85 | "VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \ | |
7ada752a AZ |
86 | "failed (%lld " #OP " %lld)\n", \ |
87 | (long long)(_verify3_left), \ | |
88 | (long long)(_verify3_right)); \ | |
6e8b2688 PD |
89 | } while (0) |
90 | ||
7ada752a | 91 | #define VERIFY3U(LEFT, OP, RIGHT) do { \ |
c94d648b AM |
92 | const uint64_t _verify3_left = (uint64_t)(LEFT); \ |
93 | const uint64_t _verify3_right = (uint64_t)(RIGHT); \ | |
94 | if (unlikely(!(_verify3_left OP _verify3_right))) \ | |
6e8b2688 PD |
95 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ |
96 | "VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \ | |
7ada752a AZ |
97 | "failed (%llu " #OP " %llu)\n", \ |
98 | (unsigned long long)(_verify3_left), \ | |
99 | (unsigned long long)(_verify3_right)); \ | |
6e8b2688 PD |
100 | } while (0) |
101 | ||
7ada752a | 102 | #define VERIFY3P(LEFT, OP, RIGHT) do { \ |
c94d648b | 103 | const uintptr_t _verify3_left = (uintptr_t)(LEFT); \ |
7ada752a | 104 | const uintptr_t _verify3_right = (uintptr_t)(RIGHT); \ |
c94d648b | 105 | if (unlikely(!(_verify3_left OP _verify3_right))) \ |
6e8b2688 PD |
106 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ |
107 | "VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \ | |
7ada752a AZ |
108 | "failed (%px " #OP " %px)\n", \ |
109 | (void *) (_verify3_left), \ | |
110 | (void *) (_verify3_right)); \ | |
6e8b2688 PD |
111 | } while (0) |
112 | ||
7ada752a AZ |
113 | #define VERIFY0(RIGHT) do { \ |
114 | const int64_t _verify3_left = (int64_t)(0); \ | |
c94d648b AM |
115 | const int64_t _verify3_right = (int64_t)(RIGHT); \ |
116 | if (unlikely(!(_verify3_left == _verify3_right))) \ | |
6e8b2688 | 117 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ |
7ada752a AZ |
118 | "VERIFY3(0 == " #RIGHT ") " \ |
119 | "failed (0 == %lld)\n", \ | |
120 | (long long) (_verify3_right)); \ | |
6e8b2688 | 121 | } while (0) |
57d1b188 | 122 | |
8d9a23e8 BB |
123 | #define CTASSERT_GLOBAL(x) _CTASSERT(x, __LINE__) |
124 | #define CTASSERT(x) { _CTASSERT(x, __LINE__); } | |
125 | #define _CTASSERT(x, y) __CTASSERT(x, y) | |
126 | #define __CTASSERT(x, y) \ | |
7ada752a | 127 | typedef char __attribute__((unused)) \ |
8d9a23e8 | 128 | __compile_time_assertion__ ## y[(x) ? 1 : -1] |
6c48cd8a | 129 | |
f6a86961 | 130 | /* |
8d9a23e8 | 131 | * Debugging disabled (--disable-debug) |
f6a86961 | 132 | */ |
8d9a23e8 BB |
133 | #ifdef NDEBUG |
134 | ||
a9e2788f AZ |
135 | #define ASSERT(x) ((void) sizeof ((uintptr_t)(x))) |
136 | #define ASSERT3B(x, y, z) \ | |
137 | ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z))) | |
138 | #define ASSERT3S(x, y, z) \ | |
139 | ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z))) | |
140 | #define ASSERT3U(x, y, z) \ | |
141 | ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z))) | |
142 | #define ASSERT3P(x, y, z) \ | |
143 | ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z))) | |
144 | #define ASSERT0(x) ((void) sizeof ((uintptr_t)(x))) | |
145 | #define IMPLY(A, B) \ | |
146 | ((void) sizeof ((uintptr_t)(A)), (void) sizeof ((uintptr_t)(B))) | |
147 | #define EQUIV(A, B) \ | |
148 | ((void) sizeof ((uintptr_t)(A)), (void) sizeof ((uintptr_t)(B))) | |
f6a86961 | 149 | |
6c48cd8a | 150 | /* |
8d9a23e8 | 151 | * Debugging enabled (--enable-debug) |
6c48cd8a | 152 | */ |
8d9a23e8 BB |
153 | #else |
154 | ||
6e8b2688 PD |
155 | #define ASSERT3B VERIFY3B |
156 | #define ASSERT3S VERIFY3S | |
157 | #define ASSERT3U VERIFY3U | |
158 | #define ASSERT3P VERIFY3P | |
159 | #define ASSERT0 VERIFY0 | |
160 | #define ASSERT VERIFY | |
5acb2307 | 161 | #define IMPLY(A, B) \ |
c94d648b | 162 | ((void)(likely((!(A)) || (B)) || \ |
5acb2307 BB |
163 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ |
164 | "(" #A ") implies (" #B ")"))) | |
165 | #define EQUIV(A, B) \ | |
c94d648b | 166 | ((void)(likely(!!(A) == !!(B)) || \ |
5acb2307 BB |
167 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ |
168 | "(" #A ") is equivalent to (" #B ")"))) | |
8d9a23e8 BB |
169 | |
170 | #endif /* NDEBUG */ | |
6c48cd8a | 171 | |
f4b37741 | 172 | #endif /* SPL_DEBUG_H */ |