Add custom debug printing for your asserts

Being able to print custom debug information on assert trip
seems useful.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Paul Dagnelie <pcd@delphix.com>
Signed-off-by: Rich Ercolani <rincebrain@gmail.com>
Closes #15792
This commit is contained in:
Rich Ercolani
2024-04-10 16:30:25 -04:00
committed by GitHub
parent d98973dbdd
commit e5e2a5a3b8
4 changed files with 372 additions and 31 deletions
+97
View File
@@ -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)) || \