summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRobert Ellison <[email protected]>2009-04-08 10:58:33 -0600
committerRobert Ellison <[email protected]>2009-04-08 11:10:46 -0600
commit23ad86cfb91c294ce85a3116d4b825aaa3988a6e (patch)
tree25070a2def0d17573f82633ae4b0a3a2b1570293 /src
parenta97c846d613c3d7ec962ee095fd8282fa3b84eea (diff)
Mesa: allow suppression of debug messages in a debug build
For testing, it's very useful to be able to test on a debug build, while suppressing the debug messages (messages that are by default suppressed in a release build), in order to see the same behavior that users of release builds will see. For example, the "piglit" test suite will flag an error on programs that produce unexpected output, which means that a debug build will always fail due to the extra debug messages. This change introduces a new value to the MESA_DEBUG environment variable. In a debug build, explicitly setting MESA_DEBUG to "0" will suppress all debug messages (both from _mesa_debug() and from _mesa_warning()). (The former behavior was that debug messages were never suppressed in debug builds.) Behavior of non-debug builds has not changed. In such a build, _mesa_debug() messages are always suppressed, and _mesa_warning() messages will be suppressed unless MESA_DEBUG is set *to any value*.
Diffstat (limited to 'src')
-rw-r--r--src/mesa/main/imports.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index 20b83420641..2ac93a52371 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -979,6 +979,35 @@ _mesa_vsprintf( char *str, const char *fmt, va_list args )
/** \name Diagnostics */
/*@{*/
+static void
+output_if_debug(const char *prefixString, const char *outputString)
+{
+ static int debug = -1;
+
+ /* Check the MESA_DEBUG environment variable if it hasn't
+ * been checked yet. We only have to check it once...
+ */
+ if (debug == -1) {
+ char *env = _mesa_getenv("MESA_DEBUG");
+
+ /* In a debug build, we print warning messages *unless*
+ * MESA_DEBUG is 0. In a non-debug build, we don't
+ * print warning messages *unless* MESA_DEBUG is
+ * set *to any value*.
+ */
+#ifdef DEBUG
+ debug = (env != NULL && _mesa_atoi(env) == 0) ? 0 : 1;
+#else
+ debug = (env != NULL) ? 1 : 0;
+#endif
+ }
+
+ /* Now only print the string if we're required to do so. */
+ if (debug) {
+ fprintf(stderr, "%s: %s\n", prefixString, outputString);
+ }
+}
+
/**
* Report a warning (a recoverable error condition) to stderr if
* either DEBUG is defined or the MESA_DEBUG env var is set.
@@ -989,21 +1018,14 @@ _mesa_vsprintf( char *str, const char *fmt, va_list args )
void
_mesa_warning( GLcontext *ctx, const char *fmtString, ... )
{
- GLboolean debug;
char str[MAXSTRING];
va_list args;
(void) ctx;
va_start( args, fmtString );
(void) vsnprintf( str, MAXSTRING, fmtString, args );
va_end( args );
-#ifdef DEBUG
- debug = GL_TRUE; /* always print warning */
-#else
- debug = _mesa_getenv("MESA_DEBUG") ? GL_TRUE : GL_FALSE;
-#endif
- if (debug) {
- fprintf(stderr, "Mesa warning: %s\n", str);
- }
+
+ output_if_debug("Mesa warning", str);
}
/**
@@ -1123,7 +1145,7 @@ _mesa_debug( const GLcontext *ctx, const char *fmtString, ... )
va_start(args, fmtString);
vsnprintf(s, MAXSTRING, fmtString, args);
va_end(args);
- fprintf(stderr, "Mesa: %s", s);
+ output_if_debug("Mesa", s);
#endif /* DEBUG */
(void) ctx;
(void) fmtString;