]> git.proxmox.com Git - mirror_spl-debian.git/blame - include/sys/debug.h
Imported Upstream version 0.6.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.
33 * ASSERTF() - Assert X is true, if not panic and print message.
34 * ASSERTV() - Wraps a variable declaration which is only used by ASSERT().
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
BB
39 * VERIFY() - Verify X is true, if not panic.
40 * VERIFY3S() - Verify signed X OP Y is true, if not panic.
41 * VERIFY3U() - Verify unsigned X OP Y is true, if not panic.
42 * VERIFY3P() - Verify pointer X OP Y is true, if not panic.
80093b6f 43 * VERIFY0() - Verify value is zero, if not panic.
55abb092
BB
44 */
45
f4b37741 46#ifndef _SPL_DEBUG_H
47#define _SPL_DEBUG_H
48
4b2220f0
BB
49#include <spl-debug.h>
50
55abb092 51#ifdef NDEBUG /* Debugging Disabled */
cc7449cc 52
81672c01
RC
53/* Define SPL_DEBUG_STR to make clear which ASSERT definitions are used */
54#define SPL_DEBUG_STR ""
55
55abb092
BB
56#define PANIC(fmt, a...) \
57do { \
58 printk(KERN_EMERG fmt, ## a); \
59 spl_debug_bug(__FILE__, __FUNCTION__, __LINE__, 0); \
60} while (0)
cc7449cc 61
62#define __ASSERT(x) ((void)0)
cc7449cc 63#define ASSERT(x) ((void)0)
51117639 64#define ASSERTF(x, y, z...) ((void)0)
3a68dc53 65#define ASSERTV(x)
55abb092
BB
66#define VERIFY(cond) \
67do { \
68 if (unlikely(!(cond))) \
69 PANIC("VERIFY(" #cond ") failed\n"); \
c8e60837 70} while (0)
cc7449cc 71
55abb092
BB
72#define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE, FMT, CAST) \
73do { \
74 if (!((TYPE)(LEFT) OP (TYPE)(RIGHT))) \
75 PANIC("VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
76 "failed (" FMT " " #OP " " FMT ")\n", \
77 CAST (LEFT), CAST (RIGHT)); \
c8e60837 78} while (0)
cc7449cc 79
55abb092
BB
80#define VERIFY3S(x,y,z) VERIFY3_IMPL(x, y, z, int64_t, "%lld", (long long))
81#define VERIFY3U(x,y,z) VERIFY3_IMPL(x, y, z, uint64_t, "%llu", \
82 (unsigned long long))
83#define VERIFY3P(x,y,z) VERIFY3_IMPL(x, y, z, uintptr_t, "%p", (void *))
80093b6f 84#define VERIFY0(x) VERIFY3_IMPL(0, ==, x, int64_t, "%lld", (long long))
cc7449cc 85
55abb092
BB
86#define ASSERT3S(x,y,z) ((void)0)
87#define ASSERT3U(x,y,z) ((void)0)
88#define ASSERT3P(x,y,z) ((void)0)
80093b6f 89#define ASSERT0(x) ((void)0)
cc7449cc 90
55abb092 91#else /* Debugging Enabled */
cc7449cc 92
81672c01
RC
93/* Define SPL_DEBUG_STR to make clear which ASSERT definitions are used */
94#define SPL_DEBUG_STR " (DEBUG mode)"
95
55abb092
BB
96#define PANIC(fmt, a...) \
97do { \
98 spl_debug_msg(NULL, 0, 0, \
99 __FILE__, __FUNCTION__, __LINE__, fmt, ## a); \
100 spl_debug_bug(__FILE__, __FUNCTION__, __LINE__, 0); \
937879f1 101} while (0)
102
57d1b188 103/* ASSERTION that is safe to use within the debug system */
55abb092
BB
104#define __ASSERT(cond) \
105do { \
106 if (unlikely(!(cond))) { \
107 printk(KERN_EMERG "ASSERTION(" #cond ") failed\n"); \
108 BUG(); \
109 } \
57d1b188 110} while (0)
111
57d1b188 112/* ASSERTION that will debug log used outside the debug sysytem */
55abb092
BB
113#define ASSERT(cond) \
114do { \
115 if (unlikely(!(cond))) \
116 PANIC("ASSERTION(" #cond ") failed\n"); \
57d1b188 117} while (0)
118
55abb092
BB
119#define ASSERTF(cond, fmt, a...) \
120do { \
121 if (unlikely(!(cond))) \
122 PANIC("ASSERTION(" #cond ") failed: " fmt, ## a); \
57d1b188 123} while (0)
124
55abb092
BB
125#define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE, FMT, CAST) \
126do { \
127 if (!((TYPE)(LEFT) OP (TYPE)(RIGHT))) \
128 PANIC("VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
129 "failed (" FMT " " #OP " " FMT ")\n", \
130 CAST (LEFT), CAST (RIGHT)); \
57d1b188 131} while (0)
132
55abb092
BB
133#define VERIFY3S(x,y,z) VERIFY3_IMPL(x, y, z, int64_t, "%lld", (long long))
134#define VERIFY3U(x,y,z) VERIFY3_IMPL(x, y, z, uint64_t, "%llu", \
135 (unsigned long long))
136#define VERIFY3P(x,y,z) VERIFY3_IMPL(x, y, z, uintptr_t, "%p", (void *))
80093b6f 137#define VERIFY0(x) VERIFY3_IMPL(0, ==, x, int64_t, "%lld", (long long))
57d1b188 138
55abb092
BB
139#define ASSERT3S(x,y,z) VERIFY3S(x, y, z)
140#define ASSERT3U(x,y,z) VERIFY3U(x, y, z)
141#define ASSERT3P(x,y,z) VERIFY3P(x, y, z)
80093b6f 142#define ASSERT0(x) VERIFY0(x)
57d1b188 143
55abb092
BB
144#define ASSERTV(x) x
145#define VERIFY(x) ASSERT(x)
57d1b188 146
cc7449cc 147#endif /* NDEBUG */
f4b37741 148#endif /* SPL_DEBUG_H */