00001 #ifdef XASSERT_H_DEF
00002
00003 #undef XASSERT_H_DEF
00004 #undef assert_or_hang
00005 #undef HANG_HOURS
00006
00007 #endif
00008
00009 #include <stdio.h>
00010 #include <stdlib.h>
00011 #include <sys/types.h>
00012 #include <unistd.h>
00013
00014 #define XASSERT_H_DEF
00015
00016
00017
00018
00019 #define HANG_HOURS 12
00020 #define hang(hours) do { { int __i; int __h = (hours), __pid = (int)getpid(); \
00021 for (__i=0; __i<__h; __i++) { \
00022 fprintf(stderr, "PID %d: Waiting %d hours before " \
00023 "exiting. Run \"gdb; attach %d\" to attach debugger.\n", \
00024 __pid, __h-__i, __pid); \
00025 sleep(3600); \
00026 } \
00027 } } while(0)
00028
00029 #ifndef NDEBUG
00030 #define assert_or_hang(val) do { if (!(val)) { \
00031 fprintf(stderr, "%s, line %d: Assertion \"" \
00032 #val "\" failed.\n", __FILE__, __LINE__); \
00033 hang(HANG_HOURS); \
00034 exit(1); \
00035 } } while(0)
00036 #else
00037 #define assert_or_hang(val)
00038 #endif
00039
00040 #define XASSERT(code) assert_or_hang((code))
00041