icinga2/lib/base/debug.hpp

50 lines
1.2 KiB
C++
Raw Normal View History

/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2013-08-28 08:18:58 +02:00
#ifndef DEBUG_H
#define DEBUG_H
2014-05-25 16:23:35 +02:00
#include "i2-base.hpp"
2013-08-28 08:18:58 +02:00
2014-12-19 12:19:28 +01:00
#ifndef I2_DEBUG
2013-08-29 09:04:33 +02:00
# define ASSERT(expr) ((void)0)
2014-12-19 12:19:28 +01:00
#else /* I2_DEBUG */
2013-08-28 16:49:58 +02:00
# define ASSERT(expr) ((expr) ? 0 : icinga_assert_fail(#expr, __FILE__, __LINE__))
2014-12-19 12:19:28 +01:00
#endif /* I2_DEBUG */
2013-08-28 08:18:58 +02:00
#define VERIFY(expr) ((expr) ? 0 : icinga_assert_fail(#expr, __FILE__, __LINE__))
2013-10-26 09:41:45 +02:00
#ifdef _MSC_VER
# define NORETURNPRE __declspec(noreturn)
#else /* _MSC_VER */
# define NORETURNPRE
#endif /* _MSC_VER */
2013-09-01 06:01:27 +02:00
#ifdef __GNUC__
2013-10-26 09:41:45 +02:00
# define NORETURNPOST __attribute__((noreturn))
2013-09-01 06:01:27 +02:00
#else /* __GNUC__ */
2013-10-26 09:41:45 +02:00
# define NORETURNPOST
2013-09-01 06:01:27 +02:00
#endif /* __GNUC__ */
2013-10-26 09:41:45 +02:00
NORETURNPRE int icinga_assert_fail(const char *expr, const char *file, int line) NORETURNPOST;
#ifdef _MSC_VER
# pragma warning( push )
# pragma warning( disable : 4646 ) /* function declared with __declspec(noreturn) has non-void return type */
#endif /* _MSC_VER */
2013-08-28 16:49:58 +02:00
inline int icinga_assert_fail(const char *expr, const char *file, int line)
2013-08-28 08:18:58 +02:00
{
fprintf(stderr, "%s:%d: assertion failed: %s\n", file, line, expr);
std::abort();
2013-09-01 06:01:27 +02:00
2013-10-26 09:41:45 +02:00
#if !defined(__GNUC__) && !defined(_MSC_VER)
2013-09-01 06:01:27 +02:00
return 0;
2013-10-26 09:41:45 +02:00
#endif /* !defined(__GNUC__) && !defined(_MSC_VER) */
2013-08-28 08:18:58 +02:00
}
2013-10-26 09:41:45 +02:00
#ifdef _MSC_VER
# pragma warning( pop )
#endif /* _MSC_VER */
2013-08-28 08:18:58 +02:00
#endif /* DEBUG_H */