/** * @author Quarup Barreirinhas (qsb@andrew.cmu.edu) * @author Modified by Naju Mancheril (naju@cmu.edu) * * Some debug macros to make your life easier. * * Set VERBOSE to 1 to print messages, and to 0 for * silent (debug functions won't even be called. * * macros: PRINT_LOCATION(), DEBUG(), PANIC(), * PANICL(), ASSERT(), ASSERTL() * */ #ifndef __DEBUG_H__ #define __DEBUG_H__ #include /* required for variable length args */ #include #include /** debug on (1) or off (0) */ #define VERBOSE 1 /** debug level */ extern global_debug_level; /* if DEBUG is on, enable DEBUG (verbose) macros */ #if VERBOSE /** A function that prints to stdout and flushes the buffer */ void debug_(int level, char *filename, char *function_name, int line_no, const char *format, ...); #define PRINT_LOCATION() debug_(0, __FILE__, __FUNCTION__, __LINE__, "\n"); #define DEBUG(level,format,rest...) debug_(level,__FILE__,__FUNCTION__,__LINE__,format,##rest) #define PANIC(format, args...) { \ DEBUG(0, format, ## args); \ exit(0); \ } #define PANICL(level, format, args...) { \ if(level <= global_debug_level){ \ PANIC(format, ## args); \ } \ } #define ASSERT(x) { \ if (!(x)) { \ DEBUG(0, "Assertion failed!\n"); \ exit(0); \ } \ } #define ASSERTL(level, x) { \ if(level <= global_debug_level){ \ ASSERT(x); \ } \ } #else /* if !VERBOSE */ /* disable macros */ #define PRINT_LOCATION() #define DEBUG(level,format, args...) #define PANIC(format, args...) #define PANICL(level, format, args...) #define ASSERT(x) #define ASSERTL(x) #endif /* !DEBUG */ #endif /* ndef __DEBUG_H__ */