Commit e31fd875 by Jamie Madill Committed by Commit Bot

Enable Release ASSERT in ANGLE.

This will mainly affect the Chromium bots. BUG=angleproject:790 Change-Id: I0c4318e83eedba851f15b3b139551cdb6a2fde12 Reviewed-on: https://chromium-review.googlesource.com/346103Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 064da41c
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# found in the LICENSE file. # found in the LICENSE file.
# import the use_x11 variable # import the use_x11 variable
import("//build/config/dcheck_always_on.gni")
import("//build/config/ui.gni") import("//build/config/ui.gni")
import("//third_party/angle/build/angle_common.gni") import("//third_party/angle/build/angle_common.gni")
...@@ -107,6 +108,12 @@ config("debug_annotations_config") { ...@@ -107,6 +108,12 @@ config("debug_annotations_config") {
} }
} }
config("angle_release_asserts_config") {
if (dcheck_always_on) {
defines = [ "ANGLE_ENABLE_RELEASE_ASSERTS" ]
}
}
static_library("angle_common") { static_library("angle_common") {
sources = rebase_path(gles_gypi.libangle_common_sources, ".", "src") sources = rebase_path(gles_gypi.libangle_common_sources, ".", "src")
...@@ -120,6 +127,7 @@ static_library("angle_common") { ...@@ -120,6 +127,7 @@ static_library("angle_common") {
public_deps = [ public_deps = [
":commit_id", ":commit_id",
] ]
public_configs = [ ":angle_release_asserts_config" ]
} }
static_library("translator_lib") { static_library("translator_lib") {
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
'angle_enable_hlsl%': 0, 'angle_enable_hlsl%': 0,
'angle_link_glx%': 0, 'angle_link_glx%': 0,
'angle_gl_library_type%': 'shared_library', 'angle_gl_library_type%': 'shared_library',
'dcheck_always_on%': 0,
'conditions': 'conditions':
[ [
['OS=="win"', ['OS=="win"',
...@@ -80,6 +81,19 @@ ...@@ -80,6 +81,19 @@
], ],
'conditions': 'conditions':
[ [
['dcheck_always_on==1',
{
'configurations':
{
'Release_Base':
{
'defines':
[
'ANGLE_ENABLE_RELEASE_ASSERTS',
],
},
},
}],
['OS=="win"', ['OS=="win"',
{ {
'configurations': 'configurations':
...@@ -97,6 +111,19 @@ ...@@ -97,6 +111,19 @@
}, },
'conditions': 'conditions':
[ [
['dcheck_always_on==1',
{
'configurations':
{
'Release_Base':
{
'defines':
[
'ANGLE_ENABLE_RELEASE_ASSERTS',
],
},
},
}],
['OS=="win"', ['OS=="win"',
{ {
'configurations': 'configurations':
......
...@@ -7,19 +7,54 @@ ...@@ -7,19 +7,54 @@
// debug.cpp: Debugging utilities. // debug.cpp: Debugging utilities.
#include "common/debug.h" #include "common/debug.h"
#include "common/platform.h"
#include "common/angleutils.h"
#include <stdarg.h> #include <stdarg.h>
#include <vector>
#include <fstream>
#include <cstdio> #include <cstdio>
#include <fstream>
#include <iostream>
#include <vector>
#include "common/angleutils.h"
#include "common/platform.h"
#include "common/Optional.h"
namespace gl namespace gl
{ {
namespace namespace
{ {
class FormattedString final : angle::NonCopyable
{
public:
FormattedString(const char *format, va_list vararg) : mFormat(format)
{
va_copy(mVarArg, vararg);
}
const char *c_str() { return str().c_str(); }
const std::string &str()
{
if (!mMessage.valid())
{
mMessage = FormatString(mFormat, mVarArg);
}
return mMessage.value();
}
size_t length()
{
c_str();
return mMessage.value().length();
}
private:
const char *mFormat;
va_list mVarArg;
Optional<std::string> mMessage;
};
enum DebugTraceOutputType enum DebugTraceOutputType
{ {
DebugTraceOutputTypeNone, DebugTraceOutputTypeNone,
...@@ -52,19 +87,15 @@ void output(bool traceInDebugOnly, MessageType messageType, DebugTraceOutputType ...@@ -52,19 +87,15 @@ void output(bool traceInDebugOnly, MessageType messageType, DebugTraceOutputType
} }
} }
std::string formattedMessage; FormattedString formattedMessage(format, vararg);
UNUSED_VARIABLE(formattedMessage);
#if !defined(NDEBUG) && defined(_MSC_VER)
if (messageType == MESSAGE_ERR) if (messageType == MESSAGE_ERR)
{ {
if (formattedMessage.empty()) std::cerr << formattedMessage.c_str();
{ #if !defined(NDEBUG) && defined(_MSC_VER)
formattedMessage = FormatString(format, vararg);
}
OutputDebugStringA(formattedMessage.c_str()); OutputDebugStringA(formattedMessage.c_str());
#endif // !defined(NDEBUG) && defined(_MSC_VER)
} }
#endif
#if defined(ANGLE_ENABLE_DEBUG_TRACE) #if defined(ANGLE_ENABLE_DEBUG_TRACE)
#if defined(NDEBUG) #if defined(NDEBUG)
...@@ -72,12 +103,7 @@ void output(bool traceInDebugOnly, MessageType messageType, DebugTraceOutputType ...@@ -72,12 +103,7 @@ void output(bool traceInDebugOnly, MessageType messageType, DebugTraceOutputType
{ {
return; return;
} }
#endif // NDEBUG #endif // NDEBUG
if (formattedMessage.empty())
{
formattedMessage = FormatString(format, vararg);
}
static std::ofstream file(TRACE_OUTPUT_FILE, std::ofstream::app); static std::ofstream file(TRACE_OUTPUT_FILE, std::ofstream::app);
if (file) if (file)
{ {
...@@ -87,9 +113,9 @@ void output(bool traceInDebugOnly, MessageType messageType, DebugTraceOutputType ...@@ -87,9 +113,9 @@ void output(bool traceInDebugOnly, MessageType messageType, DebugTraceOutputType
#if defined(ANGLE_ENABLE_DEBUG_TRACE_TO_DEBUGGER) #if defined(ANGLE_ENABLE_DEBUG_TRACE_TO_DEBUGGER)
OutputDebugStringA(formattedMessage.c_str()); OutputDebugStringA(formattedMessage.c_str());
#endif // ANGLE_ENABLE_DEBUG_TRACE_TO_DEBUGGER #endif // ANGLE_ENABLE_DEBUG_TRACE_TO_DEBUGGER
#endif // ANGLE_ENABLE_DEBUG_TRACE #endif // ANGLE_ENABLE_DEBUG_TRACE
} }
} // namespace } // namespace
......
...@@ -64,6 +64,9 @@ bool DebugAnnotationsActive(); ...@@ -64,6 +64,9 @@ bool DebugAnnotationsActive();
#endif #endif
#define ANGLE_EMPTY_STATEMENT for (;;) break #define ANGLE_EMPTY_STATEMENT for (;;) break
#if !defined(NDEBUG) || defined(ANGLE_ENABLE_RELEASE_ASSERTS)
#define ANGLE_ENABLE_ASSERTS
#endif
// A macro to output a trace of a function call and its arguments to the debugging log // A macro to output a trace of a function call and its arguments to the debugging log
#if defined(ANGLE_TRACE_ENABLED) #if defined(ANGLE_TRACE_ENABLED)
...@@ -80,7 +83,7 @@ bool DebugAnnotationsActive(); ...@@ -80,7 +83,7 @@ bool DebugAnnotationsActive();
#endif #endif
// A macro to output a function call and its arguments to the debugging log, in case of error. // A macro to output a function call and its arguments to the debugging log, in case of error.
#if defined(ANGLE_TRACE_ENABLED) #if defined(ANGLE_TRACE_ENABLED) || defined(ANGLE_ENABLE_ASSERTS)
#define ERR(message, ...) gl::trace(false, gl::MESSAGE_ERR, "err: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__) #define ERR(message, ...) gl::trace(false, gl::MESSAGE_ERR, "err: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__)
#else #else
#define ERR(message, ...) (void(0)) #define ERR(message, ...) (void(0))
...@@ -101,13 +104,24 @@ bool DebugAnnotationsActive(); ...@@ -101,13 +104,24 @@ bool DebugAnnotationsActive();
#undef ANGLE_TRACE_ENABLED #undef ANGLE_TRACE_ENABLED
#endif #endif
// A macro asserting a condition and outputting failures to the debug log
#if !defined(NDEBUG) #if !defined(NDEBUG)
#define ASSERT(expression) { \ #define ANGLE_ASSERT_IMPL(expression) assert(expression)
if(!(expression)) \ #else
ERR("\t! Assert failed in %s(%d): %s\n", __FUNCTION__, __LINE__, #expression); \ // TODO(jmadill): Detect if debugger is attached and break.
assert(expression); \ #define ANGLE_ASSERT_IMPL(expression) abort()
} ANGLE_EMPTY_STATEMENT #endif // !defined(NDEBUG)
// A macro asserting a condition and outputting failures to the debug log
#if defined(ANGLE_ENABLE_ASSERTS)
#define ASSERT(expression) \
{ \
if (!(expression)) \
{ \
ERR("\t! Assert failed in %s(%d): %s\n", __FUNCTION__, __LINE__, #expression); \
ANGLE_ASSERT_IMPL(expression); \
} \
} \
ANGLE_EMPTY_STATEMENT
#define UNUSED_ASSERTION_VARIABLE(variable) #define UNUSED_ASSERTION_VARIABLE(variable)
#else #else
#define ASSERT(expression) (void(0)) #define ASSERT(expression) (void(0))
......
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