Merge remote branch 'origin/master' into nv50-compiler
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_debug.h
index 445217474c104f538209c3427d091ff4ecbc757e..ef8b9671ac96835758cb3a977553171eaf40ef3d 100644 (file)
@@ -30,8 +30,7 @@
 #ifndef RADEON_DEBUG_H_INCLUDED
 #define RADEON_DEBUG_H_INCLUDED
 
-#include <stdarg.h>
-#include <stdio.h>
+#include <stdlib.h>
 
 typedef enum radeon_debug_levels {
        RADEON_CRITICAL  = 0, /* Only errors */
@@ -43,9 +42,16 @@ typedef enum radeon_debug_levels {
 
 /**
  * Compile time option to change level of debugging compiled to dri driver.
+ * Selecting critical level is not recommended because perfromance gains are
+ * going to minimal but you will lose a lot of important warnings in case of
+ * errors.
  */
 #ifndef RADEON_DEBUG_LEVEL
-#define RADEON_DEBUG_LEVEL RADEON_NORMAL
+# ifdef DEBUG
+#  define RADEON_DEBUG_LEVEL RADEON_TRACE
+# else
+#  define RADEON_DEBUG_LEVEL RADEON_VERBOSE
+# endif
 #endif
 
 typedef enum radeon_debug_types {
@@ -68,6 +74,13 @@ typedef enum radeon_debug_types {
        RADEON_GENERAL   = 0x10000   /* Used for errors and warnings */
 } radeon_debug_type_t;
 
+#define RADEON_MAX_INDENT 5
+
+struct radeon_debug {
+       size_t indent_depth;
+       char indent[RADEON_MAX_INDENT];
+};
+
 extern radeon_debug_type_t radeon_enabled_debug_types;
 
 /**
@@ -78,7 +91,7 @@ extern radeon_debug_type_t radeon_enabled_debug_types;
 static inline int radeon_is_debug_enabled(const radeon_debug_type_t type,
           const radeon_debug_level_t level)
 {
-       return RADEON_DEBUG_LEVEL <= level
+       return RADEON_DEBUG_LEVEL >= level
                && (type & radeon_enabled_debug_types);
 }
 /*
@@ -88,75 +101,74 @@ static inline int radeon_is_debug_enabled(const radeon_debug_type_t type,
 #define  __attribute__(x)  /*empty*/
 #endif
 
-/**
- * Format attribute requires declaration for setting it. Don't ask me why!
- */
-static inline void radeon_print(const radeon_debug_type_t type,
+
+extern void _radeon_print(const radeon_debug_type_t type,
           const radeon_debug_level_t level,
           const char* message,
-          ...) __attribute__((format(printf,3,4)));
-
+          ...)  __attribute__((format(printf,3,4)));
 /**
  * Print out debug message if channel specified by type is enabled
  * and compile time debugging level is at least as high as level parameter
  */
-static inline void radeon_print(const radeon_debug_type_t type,
-          const radeon_debug_level_t level,
-          const char* message,
-          ...)
-{
-       /* Compile out if level of message is too high */
-       if (radeon_is_debug_enabled(type, level)) {
-
-               va_list values;
-               va_start( values, message );
-               vfprintf(stderr, message, values);
-               va_end( values );
-       }
-}
+#define radeon_print(type, level, message, ...) do {           \
+       const radeon_debug_level_t _debug_level = (level);      \
+       const radeon_debug_type_t _debug_type = (type);         \
+       /* Compile out if level of message is too high */       \
+       if (radeon_is_debug_enabled(type, level)) {             \
+               _radeon_print(_debug_type, _debug_level,        \
+                       (message), ## __VA_ARGS__);             \
+       }                                                       \
+} while(0)
 
-static inline void radeon_error(const char* message, ...)  __attribute__((format(printf,1,2)));
 /**
  * printf style function for writing error messages.
  */
-static inline void radeon_error(const char* message, ...)
-{
-       va_list values;
-       va_start( values, message );
-       radeon_print(RADEON_GENERAL, RADEON_CRITICAL, message, values);
-       va_end( values );
-}
+#define radeon_error(message, ...) do {                                \
+       radeon_print(RADEON_GENERAL, RADEON_CRITICAL,           \
+               (message), ## __VA_ARGS__);                     \
+} while(0)
 
-static inline void radeon_warning(const char* message, ...)  __attribute__((format(printf,1,2)));
 /**
  * printf style function for writing warnings.
  */
-static inline void radeon_warning(const char* message, ...)
+#define radeon_warning(message, ...) do {                      \
+       radeon_print(RADEON_GENERAL, RADEON_IMPORTANT,          \
+               (message), ## __VA_ARGS__);                     \
+} while(0)
+
+extern void radeon_init_debug(void);
+extern void _radeon_debug_add_indent(void);
+extern void _radeon_debug_remove_indent(void);
+
+static inline void radeon_debug_add_indent(void)
 {
-       va_list values;
-       va_start( values, message );
-       radeon_print(RADEON_GENERAL, RADEON_IMPORTANT, message, values);
-       va_end( values );
+       if (RADEON_DEBUG_LEVEL >= RADEON_VERBOSE) {
+             _radeon_debug_add_indent();
+       }
+}
+static inline void radeon_debug_remove_indent(void)
+{
+       if (RADEON_DEBUG_LEVEL >= RADEON_VERBOSE) {
+             _radeon_debug_remove_indent();
+       }
 }
 
 
-extern void radeon_init_debug(void);
-
 /* From http://gcc. gnu.org/onlinedocs/gcc-3.2.3/gcc/Variadic-Macros.html .
    I suppose we could inline this and use macro to fetch out __LINE__ and stuff in case we run into trouble
    with other compilers ... GLUE!
 */
-#define WARN_ONCE(a, ...)      { \
-       static int warn##__LINE__=1; \
-       if(warn##__LINE__){ \
+#define WARN_ONCE(a, ...)      do { \
+       static int __warn_once=1; \
+       if(__warn_once){ \
                radeon_warning("*********************************WARN_ONCE*********************************\n"); \
                radeon_warning("File %s function %s line %d\n", \
                        __FILE__, __FUNCTION__, __LINE__); \
                radeon_warning(  (a), ## __VA_ARGS__);\
                radeon_warning("***************************************************************************\n"); \
-               warn##__LINE__=0;\
+               __warn_once=0;\
                } \
-       }
+       } while(0)
 
 
 #endif