2 // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
7 // debug.h: Debugging utilities.
9 #ifndef COMMON_DEBUG_H_
10 #define COMMON_DEBUG_H_
15 #include "common/angleutils.h"
17 #if !defined(TRACE_OUTPUT_FILE)
18 #define TRACE_OUTPUT_FILE "debug.txt"
23 // Outputs text to the debugging log, or the debugging window
24 void trace(bool traceInDebugOnly, const char *format, ...);
26 // Returns whether D3DPERF is active.
29 // Pairs a D3D begin event with an end event.
30 class ScopedPerfEventHelper
33 ScopedPerfEventHelper(const char* format, ...);
34 ~ScopedPerfEventHelper();
37 DISALLOW_COPY_AND_ASSIGN(ScopedPerfEventHelper);
40 void InitializeDebugAnnotations();
41 void UninitializeDebugAnnotations();
44 // A macro to output a trace of a function call and its arguments to the debugging log
45 #if defined(ANGLE_ENABLE_DEBUG_TRACE) || defined(ANGLE_ENABLE_DEBUG_ANNOTATIONS)
46 #define TRACE(message, ...) gl::trace(true, "trace: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__)
48 #define TRACE(message, ...) (void(0))
51 // A macro to output a function call and its arguments to the debugging log, to denote an item in need of fixing.
52 #if defined(ANGLE_ENABLE_DEBUG_TRACE) || defined(ANGLE_ENABLE_DEBUG_ANNOTATIONS)
53 #define FIXME(message, ...) gl::trace(false, "fixme: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__)
55 #define FIXME(message, ...) (void(0))
58 // A macro to output a function call and its arguments to the debugging log, in case of error.
59 #if defined(ANGLE_ENABLE_DEBUG_TRACE) || defined(ANGLE_ENABLE_DEBUG_ANNOTATIONS)
60 #define ERR(message, ...) gl::trace(false, "err: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__)
62 #define ERR(message, ...) (void(0))
65 // A macro to log a performance event around a scope.
66 #if defined(ANGLE_ENABLE_DEBUG_TRACE) || defined(ANGLE_ENABLE_DEBUG_ANNOTATIONS)
68 #define EVENT(message, ...) gl::ScopedPerfEventHelper scopedPerfEventHelper ## __LINE__("%s" message "\n", __FUNCTION__, __VA_ARGS__);
70 #define EVENT(message, ...) gl::ScopedPerfEventHelper scopedPerfEventHelper(message "\n", ##__VA_ARGS__);
73 #define EVENT(message, ...) (void(0))
76 // A macro asserting a condition and outputting failures to the debug log
78 #define ASSERT(expression) do { \
80 ERR("\t! Assert failed in %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \
83 #define UNUSED_ASSERTION_VARIABLE(variable)
85 #define ASSERT(expression) (void(0))
86 #define UNUSED_ASSERTION_VARIABLE(variable) ((void)variable)
89 #ifndef ANGLE_ENABLE_DEBUG_TRACE
90 #define UNUSED_TRACE_VARIABLE(variable) ((void)variable)
92 #define UNUSED_TRACE_VARIABLE(variable)
95 // A macro to indicate unimplemented functionality
97 #if defined (ANGLE_TEST_CONFIG)
98 #define NOASSERT_UNIMPLEMENTED 1
101 // Define NOASSERT_UNIMPLEMENTED to non zero to skip the assert fail in the unimplemented checks
102 // This will allow us to test with some automated test suites (eg dEQP) without crashing
103 #ifndef NOASSERT_UNIMPLEMENTED
104 #define NOASSERT_UNIMPLEMENTED 0
108 #define UNIMPLEMENTED() do { \
109 FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); \
110 assert(NOASSERT_UNIMPLEMENTED); \
113 #define UNIMPLEMENTED() FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__)
116 // A macro for code which is not expected to be reached under valid assumptions
118 #define UNREACHABLE() do { \
119 ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__); \
123 #define UNREACHABLE() ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__)
126 // A macro that determines whether an object has a given runtime type.
127 #if !defined(NDEBUG) && (!defined(_MSC_VER) || defined(_CPPRTTI)) && (!defined(__GNUC__) || __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3) || defined(__GXX_RTTI))
128 #define HAS_DYNAMIC_TYPE(type, obj) (dynamic_cast<type >(obj) != NULL)
130 #define HAS_DYNAMIC_TYPE(type, obj) true
133 // A macro functioning as a compile-time assert to validate constant conditions
134 #if (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__GNUC__) && (__GNUC__ > 4 || __GNUC_MINOR__ >= 3))
135 #define META_ASSERT_MSG(condition, msg) static_assert(condition, msg)
137 #define META_ASSERT_CONCAT(a, b) a ## b
138 #define META_ASSERT_CONCAT2(a, b) META_ASSERT_CONCAT(a, b)
139 #define META_ASSERT_MSG(condition, msg) typedef int META_ASSERT_CONCAT2(COMPILE_TIME_ASSERT_, __LINE__)[static_cast<bool>(condition)?1:-1]
141 #define META_ASSERT(condition) META_ASSERT_MSG(condition, "compile time assertion failed.")
143 #endif // COMMON_DEBUG_H_