usermode/library/common/debug.h

00001 #ifndef _M_DEBUG_H
00002 #define _M_DEBUG_H
00003 
00004 #include <stdio.h>
00005 #include <assert.h>
00006 
00007 #ifdef __cplusplus
00008 extern "C" {
00009 #endif
00010 
00011 
00012 /* Debugging levels per module */
00013 
00014 #define M_DEBUG_MODULEX     m_runtime_settings.debug_moduleX
00015 
00016 #define M_DEBUG_OUT      stderr
00017 
00018 
00019 /* Operations on timevals */
00020 #define timevalclear(tvp)      ((tvp)->tv_sec = (tvp)->tv_usec = 0)
00021 #define timevaladd(vvp, uvp)                                                \
00022     do {                                                                    \
00023         (vvp)->tv_sec += (uvp)->tv_sec;                                     \
00024         (vvp)->tv_usec += (uvp)->tv_usec;                                   \
00025         if ((vvp)->tv_usec >= 1000000) {                                    \
00026             (vvp)->tv_sec++;                                                \
00027             (vvp)->tv_usec -= 1000000;                                      \
00028         }                                                                   \
00029     } while (0)
00030 
00031 #define timevalsub(vvp, uvp)                                                \
00032     do {                                                                    \
00033         (vvp)->tv_sec -= (uvp)->tv_sec;                                     \
00034         (vvp)->tv_usec -= (uvp)->tv_usec;                                   \
00035         if ((vvp)->tv_usec < 0) {                                           \
00036             (vvp)->tv_sec--;                                                \
00037             (vvp)->tv_usec += 1000000;                                      \
00038         }                                                                   \
00039     } while (0)
00040 
00041 
00042 #define M_INTERNALERROR(msg, ...)                                           \
00043     m_debug_print(__FILE__, __LINE__, 1, "Internal Error: ",                \
00044                   msg, ##__VA_ARGS__ )
00045 
00046 #define M_ERROR(msg, ...)                                                   \
00047     m_debug_print(NULL, 0, 1, "Error",  msg, ##__VA_ARGS__ )
00048 
00049 
00050 #ifdef _M_BUILD_DEBUG
00051 
00052 # define M_WARNING(msg, ...)                                                \
00053     m_debug_print(NULL, 0, 0, "Warning",        msg, ##__VA_ARGS__ )
00054 
00055 
00056 # define M_DEBUG_PRINT(debug_level, msg, ...)                               \
00057     m_debug_print_L(debug_level,        msg, ##__VA_ARGS__ )
00058 
00059 # define M_ASSERT(condition) assert(condition) 
00060 
00061 #else /* !_M_BUILD_DEBUG */
00062 
00063 # define M_WARNING(msg, ...)                   ((void) 0)
00064 # define M_DEBUG_PRINT(debug_level, msg, ...)  ((void) 0)
00065 # define M_ASSERT(condition)                   ((void) 0)
00066 
00067 #endif /* !_M_BUILD_DEBUG */
00068 
00069 
00070 /* Interface functions */
00071 
00072 void m_debug_print(char *file, int line, int fatal, const char *prefix, const char *strformat, ...); 
00073 void m_debug_print_L(int debug_level, const char *strformat, ...); 
00074 void m_print_trace (void);
00075 
00076 #ifdef __cplusplus
00077 }
00078 #endif
00079 
00080 #endif /* _M_DEBUG_H */

Generated on Sat Apr 23 11:43:35 2011 for Mnemosyne by  doxygen 1.4.7