00001
00045 #ifndef DEBUG_H_INCLUDED
00046 #define DEBUG_H_INCLUDED
00047
00048 #include <compiler.h>
00049 #include <stdarg.h>
00050
00054 enum debug_level {
00055 DEBUG_NONE = 0,
00056 DEBUG_PANIC,
00057 DEBUG_ASSERT,
00058 DEBUG_ERROR,
00059 DEBUG_WARNING,
00060 DEBUG_INFO,
00061 DEBUG_VERBOSE,
00062 };
00063
00064 #ifndef CONFIG_DEBUG_CONSOLE
00065 # define dbg_init() do { } while (0)
00066 # undef DEBUG_LEVEL
00067 # define DEBUG_LEVEL DEBUG_NONE
00068 #else
00069 extern void dbg_init(void);
00070 # ifndef DEBUG_LEVEL
00071 # ifdef CONFIG_DEBUG_LEVEL
00072 # define DEBUG_LEVEL CONFIG_DEBUG_LEVEL
00073 # else
00074 # define DEBUG_LEVEL DEBUG_INFO
00075 # endif
00076 # endif
00077 #endif
00078
00079 extern int dbg_priv_vprintf(const char *format, va_list ap);
00080 extern int dbg_priv_printf(const char *format, ...) __printf_format(1, 2);
00081 extern int dbg_priv_putstr(const char *str);
00082 extern int dbg_priv_putchar(int c);
00083
00090 static inline int dbg_priv_retzero(void)
00091 {
00092 return 0;
00093 }
00094
00095 #define dbg_priv_check_level(level) \
00096 (DEBUG_LEVEL != DEBUG_NONE && (level) <= DEBUG_LEVEL)
00097
00112 #define dbg_vprintf_level(level, format, ap) \
00113 (dbg_priv_check_level(level) \
00114 ? dbg_priv_vprintf(format, ap) \
00115 : dbg_priv_retzero())
00116
00130 #define dbg_printf_level(level, ...) \
00131 (dbg_priv_check_level(level) \
00132 ? dbg_priv_printf(__VA_ARGS__) \
00133 : dbg_priv_retzero())
00134
00144 #define dbg_putstr_level(level, str) \
00145 (dbg_priv_check_level(level) \
00146 ? dbg_priv_putstr(str) \
00147 : dbg_priv_retzero())
00148
00158 #define dbg_putchar_level(level, c) \
00159 (dbg_priv_check_level(level) \
00160 ? dbg_priv_putchar(c) \
00161 : dbg_priv_retzero())
00162
00167 #define dbg_vprintf(format, ap) \
00168 dbg_vprintf_level(DEBUG_VERBOSE, format, ap)
00169
00173 #define dbg_printf(...) \
00174 dbg_printf_level(DEBUG_VERBOSE, __VA_ARGS__)
00175
00179 #define dbg_putstr(str) \
00180 dbg_putstr_level(DEBUG_VERBOSE, str)
00181
00185 #define dbg_putchar(c) \
00186 dbg_putchar_level(DEBUG_VERBOSE, c)
00187
00192 #define dbg_panic(...) \
00193 dbg_printf_level(DEBUG_PANIC, __VA_ARGS__)
00194
00198 #define dbg_error(...) \
00199 dbg_printf_level(DEBUG_ERROR, __VA_ARGS__)
00200
00204 #define dbg_warning(...) \
00205 dbg_printf_level(DEBUG_WARNING, __VA_ARGS__)
00206
00210 #define dbg_info(...) \
00211 dbg_printf_level(DEBUG_INFO, __VA_ARGS__)
00212
00216 #define dbg_verbose(...) \
00217 dbg_printf_level(DEBUG_VERBOSE, __VA_ARGS__)
00218
00219 #define WARN(condition, format, ...) ({ \
00220 int __ret_warn_on = !!(condition); \
00221 if (unlikely(__ret_warn_on)) \
00222 dbg_printf(format, __VA_ARGS__); \
00223 unlikely(__ret_warn_on); \
00224 })
00225
00226 #define WARN_ON(condition) \
00227 WARN(condition, "WARNING: " #condition " at %s:%u", \
00228 __file__, __line__)
00229
00230 #endif