]>
Commit | Line | Data |
---|---|---|
87d546d8 TG |
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 | * 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. | |
37 | * ASSERT0() - Assert value is zero, 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 | * VERIFY0() - Verify value is zero, if not panic. | |
43 | */ | |
44 | ||
45 | #ifndef _SPL_DEBUG_H | |
46 | #define _SPL_DEBUG_H | |
47 | ||
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); | |
54 | ||
55 | #define PANIC(fmt, a...) \ | |
56 | spl_panic(__FILE__, __FUNCTION__, __LINE__, fmt, ## a) | |
57 | ||
58 | #define VERIFY(cond) \ | |
59 | (void)(unlikely(!(cond)) && \ | |
60 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ | |
61 | "%s", "VERIFY(" #cond ") failed\n")) | |
62 | ||
63 | #define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE, FMT, CAST) \ | |
64 | (void)((!((TYPE)(LEFT) OP (TYPE)(RIGHT))) && \ | |
65 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ | |
66 | "VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \ | |
67 | "failed (" FMT " " #OP " " FMT ")\n", \ | |
68 | CAST (LEFT), CAST (RIGHT))) | |
69 | ||
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", \ | |
72 | (unsigned long long)) | |
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)) | |
75 | ||
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] | |
82 | ||
83 | /* | |
84 | * Debugging disabled (--disable-debug) | |
85 | */ | |
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) | |
95 | #define IMPLY(A, B) ((void)0) | |
96 | #define EQUIV(A, B) ((void)0) | |
97 | ||
98 | /* | |
99 | * Debugging enabled (--enable-debug) | |
100 | */ | |
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) | |
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 ")"))) | |
118 | ||
119 | #endif /* NDEBUG */ | |
120 | ||
121 | #endif /* SPL_DEBUG_H */ |