aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libspl/include/assert.h
diff options
context:
space:
mode:
authorRich Ercolani <[email protected]>2024-04-10 16:30:25 -0400
committerGitHub <[email protected]>2024-04-10 13:30:25 -0700
commite5e2a5a3b872e618af585f1a8cec4782c6f2cfe1 (patch)
treede1a840176790334edc599f3a348f6d141e4d70c /lib/libspl/include/assert.h
parentd98973dbdd5a85b6c8a8556d5bd5c9903e2d2ee6 (diff)
Add custom debug printing for your asserts
Being able to print custom debug information on assert trip seems useful. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Paul Dagnelie <[email protected]> Signed-off-by: Rich Ercolani <[email protected]> Closes #15792
Diffstat (limited to 'lib/libspl/include/assert.h')
-rw-r--r--lib/libspl/include/assert.h97
1 files changed, 97 insertions, 0 deletions
diff --git a/lib/libspl/include/assert.h b/lib/libspl/include/assert.h
index 57f5719c1..155bbab30 100644
--- a/lib/libspl/include/assert.h
+++ b/lib/libspl/include/assert.h
@@ -70,6 +70,15 @@ libspl_assert(const char *buf, const char *file, const char *func, int line)
#define VERIFY(cond) \
(void) ((!(cond)) && \
libspl_assert(#cond, __FILE__, __FUNCTION__, __LINE__))
+
+#define VERIFYF(cond, STR, ...) \
+do { \
+ if (!(cond)) \
+ libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
+ "%s " STR, #cond, \
+ __VA_ARGS__); \
+} while (0)
+
#define verify(cond) \
(void) ((!(cond)) && \
libspl_assert(#cond, __FILE__, __FUNCTION__, __LINE__))
@@ -132,6 +141,79 @@ do { \
(void *)__left); \
} while (0)
+/*
+ * This is just here because cstyle gets upset about #LEFT
+ * on a newline.
+ */
+
+/* BEGIN CSTYLED */
+#define VERIFY3BF(LEFT, OP, RIGHT, STR, ...) \
+do { \
+ const boolean_t __left = (boolean_t)(LEFT); \
+ const boolean_t __right = (boolean_t)(RIGHT); \
+ if (!(__left OP __right)) \
+ libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
+ "%s %s %s (0x%llx %s 0x%llx) " STR, \
+ #LEFT, #OP, #RIGHT, \
+ (u_longlong_t)__left, #OP, (u_longlong_t)__right, \
+ __VA_ARGS__); \
+} while (0)
+
+#define VERIFY3SF(LEFT, OP, RIGHT, STR, ...) \
+do { \
+ const int64_t __left = (int64_t)(LEFT); \
+ const int64_t __right = (int64_t)(RIGHT); \
+ if (!(__left OP __right)) \
+ libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
+ "%s %s %s (0x%llx %s 0x%llx) " STR, \
+ #LEFT, #OP, #RIGHT, \
+ (u_longlong_t)__left, #OP, (u_longlong_t)__right, \
+ __VA_ARGS__); \
+} while (0)
+
+#define VERIFY3UF(LEFT, OP, RIGHT, STR, ...) \
+do { \
+ const uint64_t __left = (uint64_t)(LEFT); \
+ const uint64_t __right = (uint64_t)(RIGHT); \
+ if (!(__left OP __right)) \
+ libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
+ "%s %s %s (0x%llx %s 0x%llx) " STR, \
+ #LEFT, #OP, #RIGHT, \
+ (u_longlong_t)__left, #OP, (u_longlong_t)__right, \
+ __VA_ARGS__); \
+} while (0)
+
+#define VERIFY3PF(LEFT, OP, RIGHT, STR, ...) \
+do { \
+ const uintptr_t __left = (uintptr_t)(LEFT); \
+ const uintptr_t __right = (uintptr_t)(RIGHT); \
+ if (!(__left OP __right)) \
+ libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
+ "%s %s %s (0x%llx %s 0x%llx) " STR, \
+ #LEFT, #OP, #RIGHT, \
+ (u_longlong_t)__left, #OP, (u_longlong_t)__right, \
+ __VA_ARGS__); \
+} while (0)
+/* END CSTYLED */
+
+#define VERIFY0F(LEFT, STR, ...) \
+do { \
+ const uint64_t __left = (uint64_t)(LEFT); \
+ if (!(__left == 0)) \
+ libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
+ "%s == 0 (0x%llx == 0) " STR, #LEFT, \
+ (u_longlong_t)__left, __VA_ARGS__); \
+} while (0)
+
+#define VERIFY0PF(LEFT, STR, ...) \
+do { \
+ const uintptr_t __left = (uintptr_t)(LEFT); \
+ if (!(__left == 0)) \
+ libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
+ "%s == 0 (%p == 0) " STR, #LEFT, \
+ (u_longlong_t)__left, __VA_ARGS__); \
+} while (0)
+
#ifdef assert
#undef assert
#endif
@@ -147,7 +229,15 @@ do { \
((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z)))
#define ASSERT0(x) ((void) sizeof ((uintptr_t)(x)))
#define ASSERT0P(x) ((void) sizeof ((uintptr_t)(x)))
+#define ASSERT3BF(x, y, z, str, ...) ASSERT3B(x, y, z)
+#define ASSERT3SF(x, y, z, str, ...) ASSERT3S(x, y, z)
+#define ASSERT3UF(x, y, z, str, ...) ASSERT3U(x, y, z)
+#define ASSERT3PF(x, y, z, str, ...) ASSERT3P(x, y, z)
+#define ASSERT0P(x) ((void) sizeof ((uintptr_t)(x)))
+#define ASSERT0PF(x, str, ...) ASSERT0P(x)
+#define ASSERT0F(x, str, ...) ASSERT0(x)
#define ASSERT(x) ((void) sizeof ((uintptr_t)(x)))
+#define ASSERTF(x, str, ...) ASSERT(x)
#define assert(x) ((void) sizeof ((uintptr_t)(x)))
#define IMPLY(A, B) \
((void) sizeof ((uintptr_t)(A)), (void) sizeof ((uintptr_t)(B)))
@@ -160,7 +250,14 @@ do { \
#define ASSERT3P VERIFY3P
#define ASSERT0 VERIFY0
#define ASSERT0P VERIFY0P
+#define ASSERT3BF VERIFY3BF
+#define ASSERT3SF VERIFY3SF
+#define ASSERT3UF VERIFY3UF
+#define ASSERT3PF VERIFY3PF
+#define ASSERT0PF VERIFY0PF
+#define ASSERT0F VERIFY0F
#define ASSERT VERIFY
+#define ASSERTF VERIFYF
#define assert VERIFY
#define IMPLY(A, B) \
((void)(((!(A)) || (B)) || \