aboutsummaryrefslogtreecommitdiffstats
path: root/include/sys/debug.h
diff options
context:
space:
mode:
authorTim Chase <[email protected]>2014-06-18 15:22:50 -0500
committerBrian Behlendorf <[email protected]>2014-07-01 15:14:43 -0700
commitf6a869614e5bdf9a3819a845f7a90d8c9ede0fc3 (patch)
tree654e11a1b882e9f8346f3398215e0285fb3c74b5 /include/sys/debug.h
parent31cb5383bff0fddc5058973e32a6f2c446d45e59 (diff)
Safer debugging and assertion macros.
Spl's debugging and assertion macros macro used the typical do/while(0) form for if/else friendliness, however, this limits their use in contexts where a do loop is not valid; such as within another multi-statement style macro. The following macros have been converted to not use do/while(0): PANIC, ASSERT, ASSERTF, VERIFY, VERIFY3_IMPL PANIC has been converted to a wrapper around the new spl_PANIC() function. The other macros have been converted to use the "&&" operator for the branch-predicition conditional and also to use spl_PANIC(). The __ASSERT() macro was not touched. It is only used by the debugging infrastructure and that code, including this macro, will be retired when the tracepoint patches are merged. Signed-off-by: Tim Chase <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #367
Diffstat (limited to 'include/sys/debug.h')
-rw-r--r--include/sys/debug.h56
1 files changed, 25 insertions, 31 deletions
diff --git a/include/sys/debug.h b/include/sys/debug.h
index 9fa2653d4..3a4b1352f 100644
--- a/include/sys/debug.h
+++ b/include/sys/debug.h
@@ -54,28 +54,23 @@
#define SPL_DEBUG_STR ""
#define PANIC(fmt, a...) \
-do { \
- printk(KERN_EMERG fmt, ## a); \
- spl_debug_bug(__FILE__, __FUNCTION__, __LINE__, 0); \
-} while (0)
+ spl_PANIC(__FILE__, __FUNCTION__, __LINE__, fmt, ## a)
#define __ASSERT(x) ((void)0)
#define ASSERT(x) ((void)0)
#define ASSERTF(x, y, z...) ((void)0)
#define ASSERTV(x)
#define VERIFY(cond) \
-do { \
- if (unlikely(!(cond))) \
- PANIC("VERIFY(" #cond ") failed\n"); \
-} while (0)
+ (void)(unlikely(!(cond)) && \
+ spl_PANIC(__FILE__, __FUNCTION__, __LINE__, \
+ "%s", "VERIFY(" #cond ") failed\n"))
#define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE, FMT, CAST) \
-do { \
- if (!((TYPE)(LEFT) OP (TYPE)(RIGHT))) \
- PANIC("VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
+ (void)((!((TYPE)(LEFT) OP (TYPE)(RIGHT))) && \
+ spl_PANIC(__FILE__, __FUNCTION__, __LINE__, \
+ "VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
"failed (" FMT " " #OP " " FMT ")\n", \
- CAST (LEFT), CAST (RIGHT)); \
-} while (0)
+ CAST (LEFT), CAST (RIGHT)))
#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", \
@@ -94,11 +89,7 @@ do { \
#define SPL_DEBUG_STR " (DEBUG mode)"
#define PANIC(fmt, a...) \
-do { \
- spl_debug_msg(NULL, 0, 0, \
- __FILE__, __FUNCTION__, __LINE__, fmt, ## a); \
- spl_debug_bug(__FILE__, __FUNCTION__, __LINE__, 0); \
-} while (0)
+ spl_PANIC(__FILE__, __FUNCTION__, __LINE__, fmt, ## a)
/* ASSERTION that is safe to use within the debug system */
#define __ASSERT(cond) \
@@ -111,24 +102,21 @@ do { \
/* ASSERTION that will debug log used outside the debug sysytem */
#define ASSERT(cond) \
-do { \
- if (unlikely(!(cond))) \
- PANIC("ASSERTION(" #cond ") failed\n"); \
-} while (0)
+ (void)(unlikely(!(cond)) && \
+ spl_PANIC(__FILE__, __FUNCTION__, __LINE__, \
+ "%s", "ASSERTION(" #cond ") failed\n"))
#define ASSERTF(cond, fmt, a...) \
-do { \
- if (unlikely(!(cond))) \
- PANIC("ASSERTION(" #cond ") failed: " fmt, ## a); \
-} while (0)
+ (void)(unlikely(!(cond)) && \
+ spl_PANIC(__FILE__, __FUNCTION__, __LINE__, \
+ "ASSERTION(" #cond ") failed: " fmt, ## a))
#define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE, FMT, CAST) \
-do { \
- if (!((TYPE)(LEFT) OP (TYPE)(RIGHT))) \
- PANIC("VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
+ (void)((!((TYPE)(LEFT) OP (TYPE)(RIGHT))) && \
+ spl_PANIC(__FILE__, __FUNCTION__, __LINE__, \
+ "VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
"failed (" FMT " " #OP " " FMT ")\n", \
- CAST (LEFT), CAST (RIGHT)); \
-} while (0)
+ CAST (LEFT), CAST (RIGHT)))
#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", \
@@ -147,6 +135,12 @@ do { \
#endif /* NDEBUG */
/*
+ * Helpers for the Solaris debug macros above
+ */
+extern int spl_PANIC(char *filename, const char *functionname,
+ int lineno, const char *fmt, ...);
+
+/*
* Compile-time assertion. The condition 'x' must be constant.
*/
#define CTASSERT_GLOBAL(x) _CTASSERT(x, __LINE__)