]>
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. |
3d6af2dd | 9 | * For details, see <http://zfsonlinux.org/>. |
716154c5 BB |
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. | |
715f6251 | 15 | * |
716154c5 | 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT |
715f6251 BB |
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 | |
716154c5 | 22 | * with the SPL. If not, see <http://www.gnu.org/licenses/>. |
4b393c50 | 23 | */ |
715f6251 | 24 | |
55abb092 BB |
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. | |
55abb092 | 33 | * ASSERTV() - Wraps a variable declaration which is only used by ASSERT(). |
dfbd813e | 34 | * ASSERT3B() - Assert boolean X OP Y is true, if not panic. |
55abb092 BB |
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. | |
1c6d149f | 38 | * ASSERT0() - Assert value is zero, if not panic. |
55abb092 | 39 | * VERIFY() - Verify X is true, if not panic. |
dfbd813e | 40 | * VERIFY3B() - Verify boolean X OP Y is true, if not panic. |
55abb092 BB |
41 | * VERIFY3S() - Verify signed X OP Y is true, if not panic. |
42 | * VERIFY3U() - Verify unsigned X OP Y is true, if not panic. | |
43 | * VERIFY3P() - Verify pointer X OP Y is true, if not panic. | |
1c6d149f | 44 | * VERIFY0() - Verify value is zero, if not panic. |
55abb092 BB |
45 | */ |
46 | ||
f4b37741 | 47 | #ifndef _SPL_DEBUG_H |
8d9a23e8 | 48 | #define _SPL_DEBUG_H |
f4b37741 | 49 | |
8d9a23e8 BB |
50 | /* |
51 | * Common DEBUG functionality. | |
52 | */ | |
53 | int spl_panic(const char *file, const char *func, int line, | |
54 | const char *fmt, ...); | |
55 | void spl_dumpstack(void); | |
57d1b188 | 56 | |
5461eefe | 57 | /* BEGIN CSTYLED */ |
8d9a23e8 BB |
58 | #define PANIC(fmt, a...) \ |
59 | spl_panic(__FILE__, __FUNCTION__, __LINE__, fmt, ## a) | |
57d1b188 | 60 | |
8d9a23e8 | 61 | #define VERIFY(cond) \ |
5461eefe | 62 | (void) (unlikely(!(cond)) && \ |
8d9a23e8 BB |
63 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ |
64 | "%s", "VERIFY(" #cond ") failed\n")) | |
57d1b188 | 65 | |
6e8b2688 PD |
66 | #define VERIFY3B(LEFT, OP, RIGHT) do { \ |
67 | boolean_t _verify3_left = (boolean_t)(LEFT); \ | |
68 | boolean_t _verify3_right = (boolean_t)(RIGHT); \ | |
2b5cd599 D |
69 | if (!(_verify3_left OP _verify3_right)) \ |
70 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ | |
6e8b2688 PD |
71 | "VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \ |
72 | "failed (%d " #OP " %d)\n", \ | |
73 | (boolean_t) (_verify3_left), \ | |
74 | (boolean_t) (_verify3_right)); \ | |
2b5cd599 | 75 | } while (0) |
57d1b188 | 76 | |
6e8b2688 PD |
77 | #define VERIFY3S(LEFT, OP, RIGHT) do { \ |
78 | int64_t _verify3_left = (int64_t)(LEFT); \ | |
79 | int64_t _verify3_right = (int64_t)(RIGHT); \ | |
80 | if (!(_verify3_left OP _verify3_right)) \ | |
81 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ | |
82 | "VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \ | |
83 | "failed (%lld " #OP " %lld)\n", \ | |
84 | (long long) (_verify3_left), \ | |
85 | (long long) (_verify3_right)); \ | |
86 | } while (0) | |
87 | ||
88 | #define VERIFY3U(LEFT, OP, RIGHT) do { \ | |
89 | uint64_t _verify3_left = (uint64_t)(LEFT); \ | |
90 | uint64_t _verify3_right = (uint64_t)(RIGHT); \ | |
91 | if (!(_verify3_left OP _verify3_right)) \ | |
92 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ | |
93 | "VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \ | |
94 | "failed (%llu " #OP " %llu)\n", \ | |
95 | (unsigned long long) (_verify3_left), \ | |
96 | (unsigned long long) (_verify3_right)); \ | |
97 | } while (0) | |
98 | ||
99 | #define VERIFY3P(LEFT, OP, RIGHT) do { \ | |
100 | uintptr_t _verify3_left = (uintptr_t)(LEFT); \ | |
101 | uintptr_t _verify3_right = (uintptr_t)(RIGHT); \ | |
102 | if (!(_verify3_left OP _verify3_right)) \ | |
103 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ | |
104 | "VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \ | |
a887d653 | 105 | "failed (%px" #OP " %px)\n", \ |
6e8b2688 PD |
106 | (void *) (_verify3_left), \ |
107 | (void *) (_verify3_right)); \ | |
108 | } while (0) | |
109 | ||
110 | #define VERIFY0(RIGHT) do { \ | |
111 | int64_t _verify3_left = (int64_t)(0); \ | |
112 | int64_t _verify3_right = (int64_t)(RIGHT); \ | |
113 | if (!(_verify3_left == _verify3_right)) \ | |
114 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ | |
115 | "VERIFY3(0 == " #RIGHT ") " \ | |
116 | "failed (0 == %lld)\n", \ | |
117 | (long long) (_verify3_right)); \ | |
118 | } while (0) | |
57d1b188 | 119 | |
8d9a23e8 BB |
120 | #define CTASSERT_GLOBAL(x) _CTASSERT(x, __LINE__) |
121 | #define CTASSERT(x) { _CTASSERT(x, __LINE__); } | |
122 | #define _CTASSERT(x, y) __CTASSERT(x, y) | |
123 | #define __CTASSERT(x, y) \ | |
124 | typedef char __attribute__ ((unused)) \ | |
125 | __compile_time_assertion__ ## y[(x) ? 1 : -1] | |
6c48cd8a | 126 | |
f6a86961 | 127 | /* |
8d9a23e8 | 128 | * Debugging disabled (--disable-debug) |
f6a86961 | 129 | */ |
8d9a23e8 BB |
130 | #ifdef NDEBUG |
131 | ||
8d9a23e8 BB |
132 | #define ASSERT(x) ((void)0) |
133 | #define ASSERTV(x) | |
dfbd813e | 134 | #define ASSERT3B(x,y,z) ((void)0) |
8d9a23e8 BB |
135 | #define ASSERT3S(x,y,z) ((void)0) |
136 | #define ASSERT3U(x,y,z) ((void)0) | |
137 | #define ASSERT3P(x,y,z) ((void)0) | |
138 | #define ASSERT0(x) ((void)0) | |
5acb2307 BB |
139 | #define IMPLY(A, B) ((void)0) |
140 | #define EQUIV(A, B) ((void)0) | |
f6a86961 | 141 | |
6c48cd8a | 142 | /* |
8d9a23e8 | 143 | * Debugging enabled (--enable-debug) |
6c48cd8a | 144 | */ |
8d9a23e8 BB |
145 | #else |
146 | ||
6e8b2688 PD |
147 | #define ASSERT3B VERIFY3B |
148 | #define ASSERT3S VERIFY3S | |
149 | #define ASSERT3U VERIFY3U | |
150 | #define ASSERT3P VERIFY3P | |
151 | #define ASSERT0 VERIFY0 | |
152 | #define ASSERT VERIFY | |
8d9a23e8 | 153 | #define ASSERTV(x) x |
5acb2307 BB |
154 | #define IMPLY(A, B) \ |
155 | ((void)(((!(A)) || (B)) || \ | |
156 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ | |
157 | "(" #A ") implies (" #B ")"))) | |
158 | #define EQUIV(A, B) \ | |
159 | ((void)((!!(A) == !!(B)) || \ | |
160 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ | |
161 | "(" #A ") is equivalent to (" #B ")"))) | |
5461eefe | 162 | /* END CSTYLED */ |
8d9a23e8 BB |
163 | |
164 | #endif /* NDEBUG */ | |
6c48cd8a | 165 | |
f4b37741 | 166 | #endif /* SPL_DEBUG_H */ |