diff --git a/include/os/linux/spl/sys/debug.h b/include/os/linux/spl/sys/debug.h index 81ef2ca0ea91..172e2b9b2239 100644 --- a/include/os/linux/spl/sys/debug.h +++ b/include/os/linux/spl/sys/debug.h @@ -105,6 +105,7 @@ spl_assert(const char *buf, const char *file, const char *func, int line) #ifdef NDEBUG #define VERIFY(cond) (void) ((!(cond))) +#define VERIFYF(cond) do { } while(0) #define VERIFY3B(LEFT, OP, RIGHT) \ do { \ diff --git a/lib/libspl/include/assert.h b/lib/libspl/include/assert.h index 27505295a3eb..b2b768b88838 100644 --- a/lib/libspl/include/assert.h +++ b/lib/libspl/include/assert.h @@ -63,77 +63,173 @@ libspl_assert(const char *buf, const char *file, const char *func, int line) #ifdef verify #undef verify #endif + #ifdef NDEBUG #define VERIFY(cond) (void) ((!(cond))) +#define VERIFYF(cond, STR, ...) do { } while(0) #define verify(cond) (void) ((!(cond))) #define PANIC(fmt, a...) \ - libspl_assertf(__FILE__, __FUNCTION__, __LINE__, fmt, ## a) + libspl_assertf("unknown", __FUNCTION__, __LINE__, fmt, ## a) #define VERIFY3B(LEFT, OP, RIGHT) \ do { \ - const boolean_t __left __attribute__((unused)) = \ - (boolean_t)(LEFT); \ - const boolean_t __right __attribute__((unused)) = \ - (boolean_t)(RIGHT); \ + const boolean_t __left = (boolean_t)(LEFT); \ + const boolean_t __right = (boolean_t)(RIGHT); \ + if (!(__left OP __right)) \ + libspl_assertf("unknown", __FUNCTION__, __LINE__, \ + "%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \ + (u_longlong_t)__left, #OP, (u_longlong_t)__right); \ } while (0) #define VERIFY3S(LEFT, OP, RIGHT) \ do { \ - const int64_t __left __attribute__((unused)) = \ - (int64_t)(LEFT); \ - const int64_t __right __attribute__((unused)) = \ - (int64_t)(RIGHT); \ + const int64_t __left = (int64_t)(LEFT); \ + const int64_t __right = (int64_t)(RIGHT); \ + if (!(__left OP __right)) \ + libspl_assertf("unknown", __FUNCTION__, __LINE__, \ + "%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \ + (u_longlong_t)__left, #OP, (u_longlong_t)__right); \ } while (0) #define VERIFY3U(LEFT, OP, RIGHT) \ do { \ - const uint64_t __left __attribute__((unused)) = \ - (uint64_t)(LEFT); \ - const uint64_t __right __attribute__((unused)) = \ - (uint64_t)(RIGHT); \ + const uint64_t __left = (uint64_t)(LEFT); \ + const uint64_t __right = (uint64_t)(RIGHT); \ + if (!(__left OP __right)) \ + libspl_assertf("unknown", __FUNCTION__, __LINE__, \ + "%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \ + (u_longlong_t)__left, #OP, (u_longlong_t)__right); \ } while (0) #define VERIFY3P(LEFT, OP, RIGHT) \ do { \ - const uintptr_t __left __attribute__((unused)) = \ - (uintptr_t)(LEFT); \ - const uintptr_t __right __attribute__((unused)) = \ - (uintptr_t)(RIGHT); \ + const uintptr_t __left = (uintptr_t)(LEFT); \ + const uintptr_t __right = (uintptr_t)(RIGHT); \ + if (!(__left OP __right)) \ + libspl_assertf("unknown", __FUNCTION__, __LINE__, \ + "%s %s %s (%p %s %p)", #LEFT, #OP, #RIGHT, \ + (void *)__left, #OP, (void *)__right); \ } while (0) #define VERIFY0(LEFT) \ do { \ - const uint64_t __left __attribute__((unused)) = \ - (uint64_t)(LEFT); \ + const uint64_t __left = (uint64_t)(LEFT); \ + if (!(__left == 0)) \ + libspl_assertf("unknown", __FUNCTION__, __LINE__, \ + "%s == 0 (0x%llx == 0)", #LEFT, \ + (u_longlong_t)__left); \ +} while (0) + +#define VERIFY0P(LEFT) \ +do { \ + const uintptr_t __left = (uintptr_t)(LEFT); \ + if (!(__left == 0)) \ + libspl_assertf("unknown", __FUNCTION__, __LINE__, \ + "%s == 0 (%p == 0)", #LEFT, \ + (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("unknown", __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("unknown", __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("unknown", __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("unknown", __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("unknown", __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("unknown", __FUNCTION__, __LINE__, \ + "%s == 0 (%p == 0) " STR, #LEFT, \ + (u_longlong_t)__left, __VA_ARGS__); \ +} while (0) + #else +#define PANIC(fmt, a...) \ + libspl_assertf(__FILE__, __FUNCTION__, __LINE__, fmt, ## a) + #define VERIFY(cond) \ (void) ((!(cond)) && \ - libspl_assert(#cond, "unknown", __FUNCTION__, __LINE__)) + libspl_assert(#cond, __FILE__, __FUNCTION__, __LINE__)) #define VERIFYF(cond, STR, ...) \ do { \ if (!(cond)) \ - libspl_assertf( "unknown", __FUNCTION__, __LINE__, \ + libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \ "%s " STR, #cond, \ __VA_ARGS__); \ } while (0) #define verify(cond) \ (void) ((!(cond)) && \ - libspl_assert(#cond, "unknown", __FUNCTION__, __LINE__)) - -#define PANIC(fmt, a...) \ - libspl_assertf("unknown", __FUNCTION__, __LINE__, fmt, ## a) + libspl_assert(#cond, __FILE__, __FUNCTION__, __LINE__)) #define VERIFY3B(LEFT, OP, RIGHT) \ do { \ const boolean_t __left = (boolean_t)(LEFT); \ const boolean_t __right = (boolean_t)(RIGHT); \ if (!(__left OP __right)) \ - libspl_assertf("unknown", __FUNCTION__, __LINE__, \ + libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \ "%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \ (u_longlong_t)__left, #OP, (u_longlong_t)__right); \ } while (0) @@ -143,7 +239,7 @@ do { \ const int64_t __left = (int64_t)(LEFT); \ const int64_t __right = (int64_t)(RIGHT); \ if (!(__left OP __right)) \ - libspl_assertf("unknown", __FUNCTION__, __LINE__, \ + libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \ "%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \ (u_longlong_t)__left, #OP, (u_longlong_t)__right); \ } while (0) @@ -153,7 +249,7 @@ do { \ const uint64_t __left = (uint64_t)(LEFT); \ const uint64_t __right = (uint64_t)(RIGHT); \ if (!(__left OP __right)) \ - libspl_assertf("unknown", __FUNCTION__, __LINE__, \ + libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \ "%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \ (u_longlong_t)__left, #OP, (u_longlong_t)__right); \ } while (0) @@ -163,7 +259,7 @@ do { \ const uintptr_t __left = (uintptr_t)(LEFT); \ const uintptr_t __right = (uintptr_t)(RIGHT); \ if (!(__left OP __right)) \ - libspl_assertf("unknown", __FUNCTION__, __LINE__, \ + libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \ "%s %s %s (%p %s %p)", #LEFT, #OP, #RIGHT, \ (void *)__left, #OP, (void *)__right); \ } while (0) @@ -172,7 +268,7 @@ do { \ do { \ const uint64_t __left = (uint64_t)(LEFT); \ if (!(__left == 0)) \ - libspl_assertf("unknown", __FUNCTION__, __LINE__, \ + libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \ "%s == 0 (0x%llx == 0)", #LEFT, \ (u_longlong_t)__left); \ } while (0) @@ -258,8 +354,8 @@ do { \ "%s == 0 (%p == 0) " STR, #LEFT, \ (u_longlong_t)__left, __VA_ARGS__); \ } while (0) -#endif +#endif #ifdef assert #undef assert #endif @@ -308,11 +404,11 @@ do { \ #define IMPLY(A, B) \ ((void)(((!(A)) || (B)) || \ libspl_assert("(" #A ") implies (" #B ")", \ - "unknown", __FUNCTION__, __LINE__))) + __FILE__, __FUNCTION__, __LINE__))) #define EQUIV(A, B) \ ((void)((!!(A) == !!(B)) || \ libspl_assert("(" #A ") is equivalent to (" #B ")", \ - "unknown", __FUNCTION__, __LINE__))) + __FILE__, __FUNCTION__, __LINE__))) #endif /* NDEBUG */