]>
Commit | Line | Data |
---|---|---|
716154c5 BB |
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>. | |
715f6251 | 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 | 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 BB |
22 | * with the SPL. If not, see <http://www.gnu.org/licenses/>. |
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 BB |
33 | * ASSERTV() - Wraps a variable declaration which is only used by ASSERT(). |
34 | * ASSERT3S() - Assert signed X OP Y is true, if not panic. | |
35 | * ASSERT3U() - Assert unsigned X OP Y is true, if not panic. | |
36 | * ASSERT3P() - Assert pointer X OP Y is true, if not panic. | |
80093b6f | 37 | * ASSERT0() - Assert value is zero, if not panic. |
55abb092 BB |
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. | |
80093b6f | 42 | * VERIFY0() - Verify value is zero, if not panic. |
55abb092 BB |
43 | */ |
44 | ||
f4b37741 | 45 | #ifndef _SPL_DEBUG_H |
10946b02 | 46 | #define _SPL_DEBUG_H |
f4b37741 | 47 | |
10946b02 AX |
48 | /* |
49 | * Common DEBUG functionality. | |
50 | */ | |
51 | int spl_panic(const char *file, const char *func, int line, | |
52 | const char *fmt, ...); | |
53 | void spl_dumpstack(void); | |
57d1b188 | 54 | |
10946b02 AX |
55 | #define PANIC(fmt, a...) \ |
56 | spl_panic(__FILE__, __FUNCTION__, __LINE__, fmt, ## a) | |
57d1b188 | 57 | |
10946b02 | 58 | #define VERIFY(cond) \ |
9e4fb5c2 | 59 | (void)(unlikely(!(cond)) && \ |
10946b02 AX |
60 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ |
61 | "%s", "VERIFY(" #cond ") failed\n")) | |
57d1b188 | 62 | |
10946b02 | 63 | #define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE, FMT, CAST) \ |
9e4fb5c2 | 64 | (void)((!((TYPE)(LEFT) OP (TYPE)(RIGHT))) && \ |
10946b02 AX |
65 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ |
66 | "VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \ | |
67 | "failed (" FMT " " #OP " " FMT ")\n", \ | |
68 | CAST (LEFT), CAST (RIGHT))) | |
57d1b188 | 69 | |
10946b02 AX |
70 | #define VERIFY3S(x,y,z) VERIFY3_IMPL(x, y, z, int64_t, "%lld", (long long)) |
71 | #define VERIFY3U(x,y,z) VERIFY3_IMPL(x, y, z, uint64_t, "%llu", \ | |
55abb092 | 72 | (unsigned long long)) |
10946b02 AX |
73 | #define VERIFY3P(x,y,z) VERIFY3_IMPL(x, y, z, uintptr_t, "%p", (void *)) |
74 | #define VERIFY0(x) VERIFY3_IMPL(0, ==, x, int64_t, "%lld", (long long)) | |
57d1b188 | 75 | |
10946b02 AX |
76 | #define CTASSERT_GLOBAL(x) _CTASSERT(x, __LINE__) |
77 | #define CTASSERT(x) { _CTASSERT(x, __LINE__); } | |
78 | #define _CTASSERT(x, y) __CTASSERT(x, y) | |
79 | #define __CTASSERT(x, y) \ | |
80 | typedef char __attribute__ ((unused)) \ | |
81 | __compile_time_assertion__ ## y[(x) ? 1 : -1] | |
9e4fb5c2 LG |
82 | |
83 | /* | |
10946b02 | 84 | * Debugging disabled (--disable-debug) |
9e4fb5c2 | 85 | */ |
10946b02 AX |
86 | #ifdef NDEBUG |
87 | ||
88 | #define SPL_DEBUG_STR "" | |
89 | #define ASSERT(x) ((void)0) | |
90 | #define ASSERTV(x) | |
91 | #define ASSERT3S(x,y,z) ((void)0) | |
92 | #define ASSERT3U(x,y,z) ((void)0) | |
93 | #define ASSERT3P(x,y,z) ((void)0) | |
94 | #define ASSERT0(x) ((void)0) | |
8095473b AX |
95 | #define IMPLY(A, B) ((void)0) |
96 | #define EQUIV(A, B) ((void)0) | |
9e4fb5c2 LG |
97 | |
98 | /* | |
10946b02 | 99 | * Debugging enabled (--enable-debug) |
9e4fb5c2 | 100 | */ |
10946b02 AX |
101 | #else |
102 | ||
103 | #define SPL_DEBUG_STR " (DEBUG mode)" | |
104 | #define ASSERT(cond) VERIFY(cond) | |
105 | #define ASSERTV(x) x | |
106 | #define ASSERT3S(x,y,z) VERIFY3S(x, y, z) | |
107 | #define ASSERT3U(x,y,z) VERIFY3U(x, y, z) | |
108 | #define ASSERT3P(x,y,z) VERIFY3P(x, y, z) | |
109 | #define ASSERT0(x) VERIFY0(x) | |
8095473b AX |
110 | #define IMPLY(A, B) \ |
111 | ((void)(((!(A)) || (B)) || \ | |
112 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ | |
113 | "(" #A ") implies (" #B ")"))) | |
114 | #define EQUIV(A, B) \ | |
115 | ((void)((!!(A) == !!(B)) || \ | |
116 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ | |
117 | "(" #A ") is equivalent to (" #B ")"))) | |
10946b02 AX |
118 | |
119 | #endif /* NDEBUG */ | |
9e4fb5c2 | 120 | |
f4b37741 | 121 | #endif /* SPL_DEBUG_H */ |