]> granicus.if.org Git - icinga2/blob - lib/base/debug.hpp
Merge pull request #7185 from Icinga/bugfix/gelfwriter-wrong-log-facility
[icinga2] / lib / base / debug.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef DEBUG_H
4 #define DEBUG_H
5
6 #include "i2-base.hpp"
7
8 #ifndef I2_DEBUG
9 #       define ASSERT(expr) ((void)0)
10 #else /* I2_DEBUG */
11 #       define ASSERT(expr) ((expr) ? 0 : icinga_assert_fail(#expr, __FILE__, __LINE__))
12 #endif /* I2_DEBUG */
13
14 #define VERIFY(expr) ((expr) ? 0 : icinga_assert_fail(#expr, __FILE__, __LINE__))
15
16 #ifdef _MSC_VER
17 #       define NORETURNPRE __declspec(noreturn)
18 #else /* _MSC_VER */
19 #       define NORETURNPRE
20 #endif /* _MSC_VER */
21
22 #ifdef __GNUC__
23 #       define NORETURNPOST __attribute__((noreturn))
24 #else /* __GNUC__ */
25 #       define NORETURNPOST
26 #endif /* __GNUC__ */
27
28 NORETURNPRE int icinga_assert_fail(const char *expr, const char *file, int line) NORETURNPOST;
29
30 #ifdef _MSC_VER
31 #       pragma warning( push )
32 #       pragma warning( disable : 4646 ) /* function declared with __declspec(noreturn) has non-void return type */
33 #endif /* _MSC_VER */
34
35 inline int icinga_assert_fail(const char *expr, const char *file, int line)
36 {
37         fprintf(stderr, "%s:%d: assertion failed: %s\n", file, line, expr);
38         std::abort();
39
40 #if !defined(__GNUC__) && !defined(_MSC_VER)
41         return 0;
42 #endif /* !defined(__GNUC__) && !defined(_MSC_VER) */
43 }
44
45 #ifdef _MSC_VER
46 #       pragma warning( pop )
47 #endif /* _MSC_VER */
48
49 #endif /* DEBUG_H */