2010-05-17 22:18:00 +00:00
|
|
|
/*****************************************************************************\
|
|
|
|
* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
|
|
|
|
* Copyright (C) 2007 The Regents of the University of California.
|
|
|
|
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
|
|
|
|
* Written by Brian Behlendorf <behlendorf1@llnl.gov>.
|
2008-05-26 04:38:26 +00:00
|
|
|
* UCRL-CODE-235197
|
|
|
|
*
|
2010-05-17 22:18:00 +00:00
|
|
|
* This file is part of the SPL, Solaris Porting Layer.
|
2013-03-05 01:26:55 +00:00
|
|
|
* For details, see <http://zfsonlinux.org/>.
|
2010-05-17 22:18:00 +00:00
|
|
|
*
|
|
|
|
* The SPL is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
2008-05-26 04:38:26 +00:00
|
|
|
*
|
2010-05-17 22:18:00 +00:00
|
|
|
* The SPL is distributed in the hope that it will be useful, but WITHOUT
|
2008-05-26 04:38:26 +00:00
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2010-05-17 22:18:00 +00:00
|
|
|
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
\*****************************************************************************/
|
2008-05-26 04:38:26 +00:00
|
|
|
|
2010-07-19 21:16:05 +00:00
|
|
|
/*
|
|
|
|
* Available Solaris debug functions. All of the ASSERT() macros will be
|
|
|
|
* compiled out when NDEBUG is defined, this is the default behavior for
|
|
|
|
* the SPL. To enable assertions use the --enable-debug with configure.
|
|
|
|
* The VERIFY() functions are never compiled out and cannot be disabled.
|
|
|
|
*
|
|
|
|
* PANIC() - Panic the node and print message.
|
|
|
|
* ASSERT() - Assert X is true, if not panic.
|
|
|
|
* ASSERTF() - Assert X is true, if not panic and print message.
|
|
|
|
* ASSERTV() - Wraps a variable declaration which is only used by ASSERT().
|
|
|
|
* ASSERT3S() - Assert signed X OP Y is true, if not panic.
|
|
|
|
* ASSERT3U() - Assert unsigned X OP Y is true, if not panic.
|
|
|
|
* ASSERT3P() - Assert pointer X OP Y is true, if not panic.
|
|
|
|
* VERIFY() - Verify X is true, if not panic.
|
|
|
|
* VERIFY3S() - Verify signed X OP Y is true, if not panic.
|
|
|
|
* VERIFY3U() - Verify unsigned X OP Y is true, if not panic.
|
|
|
|
* VERIFY3P() - Verify pointer X OP Y is true, if not panic.
|
|
|
|
*/
|
|
|
|
|
2008-03-01 00:45:59 +00:00
|
|
|
#ifndef _SPL_DEBUG_H
|
|
|
|
#define _SPL_DEBUG_H
|
|
|
|
|
2012-01-21 00:39:12 +00:00
|
|
|
#include <spl-debug.h>
|
|
|
|
|
2010-07-19 21:16:05 +00:00
|
|
|
#ifdef NDEBUG /* Debugging Disabled */
|
2008-05-19 02:49:12 +00:00
|
|
|
|
2010-07-20 22:25:45 +00:00
|
|
|
/* Define SPL_DEBUG_STR to make clear which ASSERT definitions are used */
|
|
|
|
#define SPL_DEBUG_STR ""
|
|
|
|
|
2010-07-19 21:16:05 +00:00
|
|
|
#define PANIC(fmt, a...) \
|
|
|
|
do { \
|
|
|
|
printk(KERN_EMERG fmt, ## a); \
|
|
|
|
spl_debug_bug(__FILE__, __FUNCTION__, __LINE__, 0); \
|
|
|
|
} while (0)
|
2008-05-19 02:49:12 +00:00
|
|
|
|
|
|
|
#define __ASSERT(x) ((void)0)
|
|
|
|
#define ASSERT(x) ((void)0)
|
2009-01-22 17:41:47 +00:00
|
|
|
#define ASSERTF(x, y, z...) ((void)0)
|
2009-07-09 19:15:23 +00:00
|
|
|
#define ASSERTV(x)
|
2010-07-19 21:16:05 +00:00
|
|
|
#define VERIFY(cond) \
|
|
|
|
do { \
|
|
|
|
if (unlikely(!(cond))) \
|
|
|
|
PANIC("VERIFY(" #cond ") failed\n"); \
|
2008-11-03 22:02:15 +00:00
|
|
|
} while (0)
|
2008-05-19 02:49:12 +00:00
|
|
|
|
2010-07-19 21:16:05 +00:00
|
|
|
#define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE, FMT, CAST) \
|
|
|
|
do { \
|
|
|
|
if (!((TYPE)(LEFT) OP (TYPE)(RIGHT))) \
|
|
|
|
PANIC("VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
|
|
|
|
"failed (" FMT " " #OP " " FMT ")\n", \
|
|
|
|
CAST (LEFT), CAST (RIGHT)); \
|
2008-11-03 22:02:15 +00:00
|
|
|
} while (0)
|
2008-05-19 02:49:12 +00:00
|
|
|
|
2010-07-19 21:16:05 +00:00
|
|
|
#define VERIFY3S(x,y,z) VERIFY3_IMPL(x, y, z, int64_t, "%lld", (long long))
|
|
|
|
#define VERIFY3U(x,y,z) VERIFY3_IMPL(x, y, z, uint64_t, "%llu", \
|
|
|
|
(unsigned long long))
|
|
|
|
#define VERIFY3P(x,y,z) VERIFY3_IMPL(x, y, z, uintptr_t, "%p", (void *))
|
2008-05-19 02:49:12 +00:00
|
|
|
|
2010-07-19 21:16:05 +00:00
|
|
|
#define ASSERT3S(x,y,z) ((void)0)
|
|
|
|
#define ASSERT3U(x,y,z) ((void)0)
|
|
|
|
#define ASSERT3P(x,y,z) ((void)0)
|
2008-05-19 02:49:12 +00:00
|
|
|
|
2010-07-19 21:16:05 +00:00
|
|
|
#else /* Debugging Enabled */
|
2008-05-19 02:49:12 +00:00
|
|
|
|
2010-07-20 22:25:45 +00:00
|
|
|
/* Define SPL_DEBUG_STR to make clear which ASSERT definitions are used */
|
|
|
|
#define SPL_DEBUG_STR " (DEBUG mode)"
|
|
|
|
|
2010-07-19 21:16:05 +00:00
|
|
|
#define PANIC(fmt, a...) \
|
|
|
|
do { \
|
|
|
|
spl_debug_msg(NULL, 0, 0, \
|
|
|
|
__FILE__, __FUNCTION__, __LINE__, fmt, ## a); \
|
|
|
|
spl_debug_bug(__FILE__, __FUNCTION__, __LINE__, 0); \
|
2008-04-21 17:29:47 +00:00
|
|
|
} while (0)
|
|
|
|
|
2008-04-18 23:39:58 +00:00
|
|
|
/* ASSERTION that is safe to use within the debug system */
|
2010-07-19 21:16:05 +00:00
|
|
|
#define __ASSERT(cond) \
|
|
|
|
do { \
|
|
|
|
if (unlikely(!(cond))) { \
|
|
|
|
printk(KERN_EMERG "ASSERTION(" #cond ") failed\n"); \
|
|
|
|
BUG(); \
|
|
|
|
} \
|
2008-04-18 23:39:58 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* ASSERTION that will debug log used outside the debug sysytem */
|
2010-07-19 21:16:05 +00:00
|
|
|
#define ASSERT(cond) \
|
|
|
|
do { \
|
|
|
|
if (unlikely(!(cond))) \
|
|
|
|
PANIC("ASSERTION(" #cond ") failed\n"); \
|
2008-04-18 23:39:58 +00:00
|
|
|
} while (0)
|
|
|
|
|
2010-07-19 21:16:05 +00:00
|
|
|
#define ASSERTF(cond, fmt, a...) \
|
|
|
|
do { \
|
|
|
|
if (unlikely(!(cond))) \
|
|
|
|
PANIC("ASSERTION(" #cond ") failed: " fmt, ## a); \
|
2008-04-18 23:39:58 +00:00
|
|
|
} while (0)
|
|
|
|
|
2010-07-19 21:16:05 +00:00
|
|
|
#define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE, FMT, CAST) \
|
|
|
|
do { \
|
|
|
|
if (!((TYPE)(LEFT) OP (TYPE)(RIGHT))) \
|
|
|
|
PANIC("VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
|
|
|
|
"failed (" FMT " " #OP " " FMT ")\n", \
|
|
|
|
CAST (LEFT), CAST (RIGHT)); \
|
2008-04-18 23:39:58 +00:00
|
|
|
} while (0)
|
|
|
|
|
2010-07-19 21:16:05 +00:00
|
|
|
#define VERIFY3S(x,y,z) VERIFY3_IMPL(x, y, z, int64_t, "%lld", (long long))
|
|
|
|
#define VERIFY3U(x,y,z) VERIFY3_IMPL(x, y, z, uint64_t, "%llu", \
|
|
|
|
(unsigned long long))
|
|
|
|
#define VERIFY3P(x,y,z) VERIFY3_IMPL(x, y, z, uintptr_t, "%p", (void *))
|
2008-04-18 23:39:58 +00:00
|
|
|
|
2010-07-19 21:16:05 +00:00
|
|
|
#define ASSERT3S(x,y,z) VERIFY3S(x, y, z)
|
|
|
|
#define ASSERT3U(x,y,z) VERIFY3U(x, y, z)
|
|
|
|
#define ASSERT3P(x,y,z) VERIFY3P(x, y, z)
|
2008-04-18 23:39:58 +00:00
|
|
|
|
2010-07-19 21:16:05 +00:00
|
|
|
#define ASSERTV(x) x
|
|
|
|
#define VERIFY(x) ASSERT(x)
|
2008-04-18 23:39:58 +00:00
|
|
|
|
2008-05-19 02:49:12 +00:00
|
|
|
#endif /* NDEBUG */
|
2008-03-01 00:45:59 +00:00
|
|
|
#endif /* SPL_DEBUG_H */
|