00001 #ifndef __LIB_DEBUG_H
00002
00003 #define __LIB_DEBUG_H
00004
00005
00006
00007
00008 #define UNUSED __attribute__ ((unused))
00009 #define NO_RETURN __attribute__ ((noreturn))
00010 #define NO_INLINE __attribute__ ((noinline))
00011 #define PRINTF_FORMAT(FMT, FIRST) __attribute__ ((format (printf, FMT, FIRST)))
00012
00013
00014
00015 #define PANIC(...) debug_panic (__FILE__, __LINE__, __func__, __VA_ARGS__)
00016
00017 void debug_panic (const char *file, int line, const char *function,
00018 const char *message, ...) PRINTF_FORMAT (4, 5) NO_RETURN;
00019 void debug_backtrace (void);
00020 void debug_backtrace_all (void);
00021
00022 #endif
00023
00024
00025
00026
00027
00028 #undef ASSERT
00029 #undef NOT_REACHED
00030
00031 #ifndef NDEBUG
00032 #define ASSERT(CONDITION) \
00033 if (CONDITION) { } else { \
00034 PANIC ("assertion `%s' failed.", #CONDITION); \
00035 }
00036 #define NOT_REACHED() PANIC ("executed an unreachable statement");
00037 #else
00038 #define ASSERT(CONDITION) ((void) 0)
00039 #define NOT_REACHED() for (;;)
00040 #endif