]> git.proxmox.com Git - mirror_spl-debian.git/blame - include/sys/debug.h
New upstream version 0.7.2
[mirror_spl-debian.git] / include / sys / debug.h
CommitLineData
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 33 * ASSERTV() - Wraps a variable declaration which is only used by ASSERT().
ec06701b 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.
80093b6f 38 * ASSERT0() - Assert value is zero, if not panic.
55abb092 39 * VERIFY() - Verify X is true, if not panic.
ec06701b 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.
80093b6f 44 * VERIFY0() - Verify value is zero, if not panic.
55abb092
BB
45 */
46
f4b37741 47#ifndef _SPL_DEBUG_H
10946b02 48#define _SPL_DEBUG_H
f4b37741 49
10946b02
AX
50/*
51 * Common DEBUG functionality.
52 */
53int spl_panic(const char *file, const char *func, int line,
54 const char *fmt, ...);
55void spl_dumpstack(void);
57d1b188 56
10946b02
AX
57#define PANIC(fmt, a...) \
58 spl_panic(__FILE__, __FUNCTION__, __LINE__, fmt, ## a)
57d1b188 59
10946b02 60#define VERIFY(cond) \
9e4fb5c2 61 (void)(unlikely(!(cond)) && \
10946b02
AX
62 spl_panic(__FILE__, __FUNCTION__, __LINE__, \
63 "%s", "VERIFY(" #cond ") failed\n"))
57d1b188 64
10946b02 65#define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE, FMT, CAST) \
9e4fb5c2 66 (void)((!((TYPE)(LEFT) OP (TYPE)(RIGHT))) && \
10946b02
AX
67 spl_panic(__FILE__, __FUNCTION__, __LINE__, \
68 "VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
69 "failed (" FMT " " #OP " " FMT ")\n", \
70 CAST (LEFT), CAST (RIGHT)))
57d1b188 71
ec06701b 72#define VERIFY3B(x,y,z) VERIFY3_IMPL(x, y, z, boolean_t, "%d", (boolean_t))
10946b02
AX
73#define VERIFY3S(x,y,z) VERIFY3_IMPL(x, y, z, int64_t, "%lld", (long long))
74#define VERIFY3U(x,y,z) VERIFY3_IMPL(x, y, z, uint64_t, "%llu", \
55abb092 75 (unsigned long long))
10946b02
AX
76#define VERIFY3P(x,y,z) VERIFY3_IMPL(x, y, z, uintptr_t, "%p", (void *))
77#define VERIFY0(x) VERIFY3_IMPL(0, ==, x, int64_t, "%lld", (long long))
57d1b188 78
10946b02
AX
79#define CTASSERT_GLOBAL(x) _CTASSERT(x, __LINE__)
80#define CTASSERT(x) { _CTASSERT(x, __LINE__); }
81#define _CTASSERT(x, y) __CTASSERT(x, y)
82#define __CTASSERT(x, y) \
83 typedef char __attribute__ ((unused)) \
84 __compile_time_assertion__ ## y[(x) ? 1 : -1]
9e4fb5c2
LG
85
86/*
10946b02 87 * Debugging disabled (--disable-debug)
9e4fb5c2 88 */
10946b02
AX
89#ifdef NDEBUG
90
91#define SPL_DEBUG_STR ""
92#define ASSERT(x) ((void)0)
93#define ASSERTV(x)
ec06701b 94#define ASSERT3B(x,y,z) ((void)0)
10946b02
AX
95#define ASSERT3S(x,y,z) ((void)0)
96#define ASSERT3U(x,y,z) ((void)0)
97#define ASSERT3P(x,y,z) ((void)0)
98#define ASSERT0(x) ((void)0)
f6188ddd
AX
99#define IMPLY(A, B) ((void)0)
100#define EQUIV(A, B) ((void)0)
9e4fb5c2
LG
101
102/*
10946b02 103 * Debugging enabled (--enable-debug)
9e4fb5c2 104 */
10946b02
AX
105#else
106
107#define SPL_DEBUG_STR " (DEBUG mode)"
108#define ASSERT(cond) VERIFY(cond)
109#define ASSERTV(x) x
ec06701b 110#define ASSERT3B(x,y,z) VERIFY3B(x, y, z)
10946b02
AX
111#define ASSERT3S(x,y,z) VERIFY3S(x, y, z)
112#define ASSERT3U(x,y,z) VERIFY3U(x, y, z)
113#define ASSERT3P(x,y,z) VERIFY3P(x, y, z)
114#define ASSERT0(x) VERIFY0(x)
f6188ddd
AX
115#define IMPLY(A, B) \
116 ((void)(((!(A)) || (B)) || \
117 spl_panic(__FILE__, __FUNCTION__, __LINE__, \
118 "(" #A ") implies (" #B ")")))
119#define EQUIV(A, B) \
120 ((void)((!!(A) == !!(B)) || \
121 spl_panic(__FILE__, __FUNCTION__, __LINE__, \
122 "(" #A ") is equivalent to (" #B ")")))
10946b02
AX
123
124#endif /* NDEBUG */
9e4fb5c2 125
f4b37741 126#endif /* SPL_DEBUG_H */