Commit c1e60dcf by Sean Risser

Log instead of warn of unsupported extensions

Currently we produce a warning every time an unsupported extension is used. The original bug (b/139528538) called for logging these structs silently unless a debugger's attached. So I've replaced all of our warnings for unsupported structs with calls to LOG_TRAP. This is an update to TRACE_ASSERT. LOG_TRAP will never emit to the debug log, instead it will only print to a file if writing to files is enabled for logv. Bug: b/148415347 Change-Id: Ib4ad2b20b3dffce4fac597c891b2f5ee23e032c4 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/41348Tested-by: 's avatarSean Risser <srisser@google.com> Presubmit-Ready: Sean Risser <srisser@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent b1dd9aca
......@@ -98,11 +98,13 @@ bool IsUnderDebugger()
enum class Level
{
Verbose,
Debug,
Info,
Warn,
Error,
Fatal,
Disabled,
};
#ifdef __ANDROID__
......@@ -125,6 +127,8 @@ void logv_android(Level level, const char *msg)
case Level::Fatal:
__android_log_write(ANDROID_LOG_FATAL, "SwiftShader", msg);
break;
default:
break;
}
}
#else
......@@ -141,32 +145,32 @@ void logv_std(Level level, const char *msg)
case Level::Fatal:
fprintf(stderr, "%s", msg);
break;
default:
break;
}
}
#endif
void logv(Level level, const char *format, va_list args)
{
if(static_cast<int>(level) < static_cast<int>(Level::SWIFTSHADER_LOGGING_LEVEL))
if(static_cast<int>(level) >= static_cast<int>(Level::SWIFTSHADER_LOGGING_LEVEL))
{
return;
}
#ifndef SWIFTSHADER_DISABLE_TRACE
char buffer[2048];
vsnprintf(buffer, sizeof(buffer), format, args);
char buffer[2048];
vsnprintf(buffer, sizeof(buffer), format, args);
# if defined(__ANDROID__)
logv_android(level, buffer);
logv_android(level, buffer);
# elif defined(_WIN32)
logv_std(level, buffer);
::OutputDebugString(buffer);
logv_std(level, buffer);
::OutputDebugString(buffer);
# else
logv_std(level, buffer);
logv_std(level, buffer);
# endif
}
const bool traceToFile = false;
if(traceToFile)
const Level traceToFileLevel = Level::Disabled;
if(static_cast<int>(level) >= static_cast<int>(traceToFileLevel))
{
FILE *file = fopen(TRACE_OUTPUT_FILE, "a");
......@@ -210,8 +214,10 @@ void abort(const char *format, ...)
::abort();
}
void trace_assert(const char *format, ...)
void log_trap(const char *format, ...)
{
// If enabled, log_assert will log all messages, and otherwise ignore them
// unless a debugger is attached.
static std::atomic<bool> asserted = { false };
if(IsUnderDebugger() && !asserted.exchange(true))
{
......@@ -227,7 +233,7 @@ void trace_assert(const char *format, ...)
{
va_list vararg;
va_start(vararg, format);
logv(Level::Fatal, format, vararg);
logv(Level::Verbose, format, vararg);
va_end(vararg);
}
}
......
......@@ -47,8 +47,8 @@ inline void warn() {}
// Outputs the message to the debugging log and stderr, and calls abort().
void abort(const char *format, ...) CHECK_PRINTF_ARGS;
// Outputs text to the debugging log, and asserts once if a debugger is attached.
void trace_assert(const char *format, ...) CHECK_PRINTF_ARGS;
// Outputs text to the debugging log, and traps once if a debugger is attached.
void log_trap(const char *format, ...) CHECK_PRINTF_ARGS;
} // namespace sw
......@@ -59,7 +59,7 @@ void trace_assert(const char *format, ...) CHECK_PRINTF_ARGS;
# define TRACE_ASSERT(message, ...) (void(0))
#else
# define TRACE(message, ...) sw::trace("%s:%d TRACE: " message "\n", __FILE__, __LINE__, ##__VA_ARGS__)
# define TRACE_ASSERT(message, ...) sw::trace_assert("%s:%d %s TRACE_ASSERT: " message "\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__)
# define LOG_TRAP(message, ...) sw::log_trap("%s:%d %s TRACE_ASSERT: " message "\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__)
#endif
// A macro to print a warning message to the debugging log and stderr to denote
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment