X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Ferrors.c;h=f720de316e4d6588cede7d9c14a61caa7ecdb3f8;hb=73a9a1539a85ae8fe22e11b4064105d588597736;hp=43e8adfc1c0637b691a4d6a92f8f828c1fa075a1;hpb=135b8c65305c05c1ea9145141bad670003270c41;p=mesa.git diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c index 43e8adfc1c0..f720de316e4 100644 --- a/src/mesa/main/errors.c +++ b/src/mesa/main/errors.c @@ -29,6 +29,7 @@ #include +#include #include "errors.h" #include "enums.h" #include "imports.h" @@ -38,6 +39,7 @@ #include "mtypes.h" #include "version.h" #include "util/hash_table.h" +#include "util/simple_list.h" static mtx_t DynamicIDMutex = _MTX_INITIALIZER_NP; static GLuint NextDynamicID = 1; @@ -137,7 +139,7 @@ gl_enum_to_debug_source(GLenum e) { unsigned i; - for (i = 0; i < Elements(debug_source_enums); i++) { + for (i = 0; i < ARRAY_SIZE(debug_source_enums); i++) { if (debug_source_enums[i] == e) break; } @@ -149,7 +151,7 @@ gl_enum_to_debug_type(GLenum e) { unsigned i; - for (i = 0; i < Elements(debug_type_enums); i++) { + for (i = 0; i < ARRAY_SIZE(debug_type_enums); i++) { if (debug_type_enums[i] == e) break; } @@ -161,7 +163,7 @@ gl_enum_to_debug_severity(GLenum e) { unsigned i; - for (i = 0; i < Elements(debug_severity_enums); i++) { + for (i = 0; i < ARRAY_SIZE(debug_severity_enums); i++) { if (debug_severity_enums[i] == e) break; } @@ -1231,12 +1233,14 @@ _mesa_free_errors_data(struct gl_context *ctx) /** \name Diagnostics */ /*@{*/ +static FILE *LogFile = NULL; + + static void output_if_debug(const char *prefixString, const char *outputString, GLboolean newline) { static int debug = -1; - static FILE *fout = NULL; /* Init the local 'debug' var once. * Note: the _mesa_init_debug() function should have been called @@ -1248,9 +1252,9 @@ output_if_debug(const char *prefixString, const char *outputString, */ const char *logFile = getenv("MESA_LOG_FILE"); if (logFile) - fout = fopen(logFile, "w"); - if (!fout) - fout = stderr; + LogFile = fopen(logFile, "w"); + if (!LogFile) + LogFile = stderr; #ifdef DEBUG /* in debug builds, print messages unless MESA_DEBUG="silent" */ if (MESA_DEBUG_FLAGS & DEBUG_SILENT) @@ -1265,10 +1269,13 @@ output_if_debug(const char *prefixString, const char *outputString, /* Now only print the string if we're required to do so. */ if (debug) { - fprintf(fout, "%s: %s", prefixString, outputString); + if (prefixString) + fprintf(LogFile, "%s: %s", prefixString, outputString); + else + fprintf(LogFile, "%s", outputString); if (newline) - fprintf(fout, "\n"); - fflush(fout); + fprintf(LogFile, "\n"); + fflush(LogFile); #if defined(_WIN32) /* stderr from windows applications without console is not usually @@ -1283,6 +1290,18 @@ output_if_debug(const char *prefixString, const char *outputString, } +/** + * Return the file handle to use for debug/logging. Defaults to stderr + * unless MESA_LOG_FILE is defined. + */ +FILE * +_mesa_get_log_file(void) +{ + assert(LogFile); + return LogFile; +} + + /** * When a new type of error is recorded, print a message describing * previous errors which were accumulated. @@ -1295,7 +1314,7 @@ flush_delayed_errors( struct gl_context *ctx ) if (ctx->ErrorDebugCount) { _mesa_snprintf(s, MAX_DEBUG_MESSAGE_LENGTH, "%d similar %s errors", ctx->ErrorDebugCount, - _mesa_lookup_enum_by_nr(ctx->ErrorValue)); + _mesa_enum_to_string(ctx->ErrorValue)); output_if_debug("Mesa", s, GL_TRUE); @@ -1393,6 +1412,26 @@ should_output(struct gl_context *ctx, GLenum error, const char *fmtString) } +void +_mesa_gl_vdebug(struct gl_context *ctx, + GLuint *id, + enum mesa_debug_source source, + enum mesa_debug_type type, + enum mesa_debug_severity severity, + const char *fmtString, + va_list args) +{ + char s[MAX_DEBUG_MESSAGE_LENGTH]; + int len; + + debug_get_id(id); + + len = _mesa_vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args); + + log_msg(ctx, source, type, *id, severity, len, s); +} + + void _mesa_gl_debug(struct gl_context *ctx, GLuint *id, @@ -1401,17 +1440,10 @@ _mesa_gl_debug(struct gl_context *ctx, enum mesa_debug_severity severity, const char *fmtString, ...) { - char s[MAX_DEBUG_MESSAGE_LENGTH]; - int len; va_list args; - - debug_get_id(id); - va_start(args, fmtString); - len = _mesa_vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args); + _mesa_gl_vdebug(ctx, id, source, type, severity, fmtString, args); va_end(args); - - log_msg(ctx, source, type, *id, severity, len, s); } @@ -1471,7 +1503,7 @@ _mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... ) } len = _mesa_snprintf(s2, MAX_DEBUG_MESSAGE_LENGTH, "%s in %s", - _mesa_lookup_enum_by_nr(error), s); + _mesa_enum_to_string(error), s); if (len >= MAX_DEBUG_MESSAGE_LENGTH) { /* Same as above. */ assert(0); @@ -1524,6 +1556,18 @@ _mesa_debug( const struct gl_context *ctx, const char *fmtString, ... ) } +void +_mesa_log(const char *fmtString, ...) +{ + char s[MAX_DEBUG_MESSAGE_LENGTH]; + va_list args; + va_start(args, fmtString); + _mesa_vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args); + va_end(args); + output_if_debug("", s, GL_FALSE); +} + + /** * Report debug information from the shader compiler via GL_ARB_debug_output. *