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.
This commit is contained in:
Markus Mäkelä 2017-09-07 10:34:32 +03:00
parent c34bc24a8b
commit 0d5d67a050

View File

@ -13,8 +13,8 @@
*/
#include <maxscale/cdefs.h>
#include <assert.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
@ -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 <maxscale/log_manager.h>
# 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)