From 0d5d67a050b757ef7cfebd1e6f6e8ef897a78ae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 7 Sep 2017 10:34:32 +0300 Subject: [PATCH] Use SIGABRT for debug assertions Raising the signal directly keeps the stack trace smaller. It also makes sure that the assertion works even if NDEBUG is defined. The debug assertions are now also printed to stderr to make sure that they are caught even when running MaxScale directly. --- include/maxscale/debug.h | 54 ++++++---------------------------------- 1 file changed, 7 insertions(+), 47 deletions(-) diff --git a/include/maxscale/debug.h b/include/maxscale/debug.h index 284bddb02..b7c4c512b 100644 --- a/include/maxscale/debug.h +++ b/include/maxscale/debug.h @@ -13,8 +13,8 @@ */ #include -#include #include +#include #include #include #include @@ -23,61 +23,21 @@ MXS_BEGIN_DECLS #if defined(SS_DEBUG) -# define SS_PROF -#endif - -#if defined(SS_DEBUG) || defined(SS_PROF) -# define ss_prof(exp) exp -#else -# define ss_prof(exp) -#endif /* SS_DEBUG || SS_PROF */ - -#if defined(SS_DEBUG) && defined(LOG_ASSERT) #include # define ss_dassert(exp) do { if(!(exp)){\ const char *debug_expr = #exp; /** The MXS_ERROR marco doesn't seem to like stringification */ \ - MXS_ERROR("debug assert at %s:%d failed: %s\n", (char*)__FILE__, __LINE__, debug_expr);\ - mxs_log_flush_sync(); assert(exp);} } while (false) + MXS_ERROR("debug assert at %s:%d failed: %s\n", (char*)__FILE__, __LINE__, debug_expr); \ + fprintf(stderr, "debug assert at %s:%d failed: %s\n", (char*)__FILE__, __LINE__, debug_expr); \ + mxs_log_flush_sync(); raise(SIGABRT);} } while (false) #define ss_info_dassert(exp,info) do { if(!(exp)){\ const char *debug_expr = #exp; \ - MXS_ERROR("debug assert at %s:%d failed: %s (%s)\n", (char*)__FILE__, __LINE__, info, debug_expr);\ - mxs_log_flush_sync();assert(exp);} } while (false) + MXS_ERROR("debug assert at %s:%d failed: %s (%s)\n", (char*)__FILE__, __LINE__, info, debug_expr); \ + fprintf(stderr, "debug assert at %s:%d failed: %s (%s)\n", (char*)__FILE__, __LINE__, info, debug_expr); \ + mxs_log_flush_sync();raise(SIGABRT);} } while (false) # define ss_debug(exp) exp # define ss_dfprintf fprintf # define ss_dfflush fflush # define ss_dfwrite fwrite -#elif defined(SS_DEBUG) - -# define ss_debug(exp) exp -# define ss_dfprintf fprintf -# define ss_dfflush fflush -# define ss_dfwrite fwrite - -# define ss_dassert(exp) \ - { \ - if (!(exp)) { \ - ss_dfprintf(stderr, \ - "debug assert %s:%d \n", \ - (char*)__FILE__, \ - __LINE__); \ - ss_dfflush(stderr); \ - assert(exp); \ - } \ - } - - -# define ss_info_dassert(exp, info) \ - { \ - if (!(exp)) { \ - ss_dfprintf(stderr, "debug assert %s:%d, %s\n", \ - (char *)__FILE__, \ - __LINE__, \ - info); \ - ss_dfflush(stderr); \ - assert((exp)); \ - } \ - } - #else /* SS_DEBUG */ # define ss_debug(exp)