12 #define FUNCTION_NAME __FUNCTION__
14 #define FUNCTION_NAME __PRETTY_FUNCTION__
19#define EXPR_BOOL(expr) ((expr) ? 1 : 0)
20#if defined(__GNUC__) || defined(__clang__)
21 #define COLD_FUNC __attribute__((cold, noinline))
22 #define LIKELY(expr) (__builtin_expect(EXPR_BOOL(expr), 1))
23 #define UNLIKELY(expr) (__builtin_expect(EXPR_BOOL(expr), 0))
24#elif defined(_MSC_VER)
27 #define COLD_FUNC __declspec(noinline)
28 #define LIKELY(expr) EXPR_BOOL(expr)
29 #define UNLIKELY(expr) EXPR_BOOL(expr)
32 #define LIKELY(expr) EXPR_BOOL(expr)
33 #define UNLIKELY(expr) EXPR_BOOL(expr)
40 #define CATCH_UNHANDLED_EXCEPTIONS 1
42 #define CATCH_UNHANDLED_EXCEPTIONS 0
48 const char *msg,
const char *file,
49 unsigned int line,
const char *function);
51#define FATAL_ERROR(msg) \
52 fatal_error_fn((msg), __FILE__, __LINE__, FUNCTION_NAME)
54#define FATAL_ERROR_IF(expr, msg) \
56 ? fatal_error_fn((msg), __FILE__, __LINE__, FUNCTION_NAME) \
66 const char *assertion,
const char *file,
67 unsigned int line,
const char *function);
69#define SANITY_CHECK(expr) \
72 : sanity_check_fn(#expr, __FILE__, __LINE__, FUNCTION_NAME))
74#define sanity_check(expr) SANITY_CHECK(expr)
84#if CATCH_UNHANDLED_EXCEPTIONS == 1
85 #define BEGIN_DEBUG_EXCEPTION_HANDLER try {
86 #define END_DEBUG_EXCEPTION_HANDLER \
87 } catch (std::exception &e) { \
88 std::string e_descr = debug_describe_exc(e); \
89 errorstream << "An unhandled exception occurred: " \
90 << e_descr << std::endl; \
91 FATAL_ERROR(e_descr.c_str()); \
95 #define BEGIN_DEBUG_EXCEPTION_HANDLER
96 #define END_DEBUG_EXCEPTION_HANDLER
#define COLD_FUNC
Definition debug.h:31
COLD_FUNC void sanity_check_fn(const char *assertion, const char *file, unsigned int line, const char *function)
Definition debug.cpp:34
std::string debug_describe_exc(const std::exception &e)
Definition debug.cpp:64
void debug_set_exception_handler()
Definition debug.cpp:185
COLD_FUNC void fatal_error_fn(const char *msg, const char *file, unsigned int line, const char *function)
Definition debug.cpp:49