daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
| 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. |
| 5 | // |
| 6 | |
| 7 | // debug.h: Debugging utilities. |
| 8 | |
| 9 | #ifndef COMMON_DEBUG_H_ |
| 10 | #define COMMON_DEBUG_H_ |
| 11 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 12 | #include <stdio.h> |
| 13 | #include <assert.h> |
| 14 | |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 15 | #include "common/angleutils.h" |
| 16 | |
| 17 | #if !defined(TRACE_OUTPUT_FILE) |
| 18 | #define TRACE_OUTPUT_FILE "debug.txt" |
| 19 | #endif |
| 20 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 21 | namespace gl |
| 22 | { |
Austin Kinross | fe14d45 | 2014-10-20 14:36:18 -0700 | [diff] [blame] | 23 | // Outputs text to the debugging log, or the debugging window |
| 24 | void trace(bool traceInDebugOnly, const char *format, ...); |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 25 | |
| 26 | // Returns whether D3DPERF is active. |
| 27 | bool perfActive(); |
| 28 | |
| 29 | // Pairs a D3D begin event with an end event. |
| 30 | class ScopedPerfEventHelper |
| 31 | { |
| 32 | public: |
| 33 | ScopedPerfEventHelper(const char* format, ...); |
| 34 | ~ScopedPerfEventHelper(); |
| 35 | |
| 36 | private: |
| 37 | DISALLOW_COPY_AND_ASSIGN(ScopedPerfEventHelper); |
| 38 | }; |
Austin Kinross | 922a9fb | 2014-10-21 14:26:33 -0700 | [diff] [blame] | 39 | |
| 40 | void InitializeDebugAnnotations(); |
| 41 | void UninitializeDebugAnnotations(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | // A macro to output a trace of a function call and its arguments to the debugging log |
Austin Kinross | f0360c6 | 2014-10-20 14:26:13 -0700 | [diff] [blame] | 45 | #if defined(ANGLE_ENABLE_DEBUG_TRACE) || defined(ANGLE_ENABLE_DEBUG_ANNOTATIONS) |
daniel@transgaming.com | 1825d8e | 2012-08-27 16:25:29 +0000 | [diff] [blame] | 46 | #define TRACE(message, ...) gl::trace(true, "trace: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__) |
Geoff Lang | f571312 | 2013-10-07 17:06:30 -0400 | [diff] [blame] | 47 | #else |
| 48 | #define TRACE(message, ...) (void(0)) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 49 | #endif |
| 50 | |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 51 | // A macro to output a function call and its arguments to the debugging log, to denote an item in need of fixing. |
Austin Kinross | f0360c6 | 2014-10-20 14:26:13 -0700 | [diff] [blame] | 52 | #if defined(ANGLE_ENABLE_DEBUG_TRACE) || defined(ANGLE_ENABLE_DEBUG_ANNOTATIONS) |
daniel@transgaming.com | 1825d8e | 2012-08-27 16:25:29 +0000 | [diff] [blame] | 53 | #define FIXME(message, ...) gl::trace(false, "fixme: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__) |
Geoff Lang | f571312 | 2013-10-07 17:06:30 -0400 | [diff] [blame] | 54 | #else |
| 55 | #define FIXME(message, ...) (void(0)) |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 56 | #endif |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 57 | |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 58 | // A macro to output a function call and its arguments to the debugging log, in case of error. |
Austin Kinross | f0360c6 | 2014-10-20 14:26:13 -0700 | [diff] [blame] | 59 | #if defined(ANGLE_ENABLE_DEBUG_TRACE) || defined(ANGLE_ENABLE_DEBUG_ANNOTATIONS) |
daniel@transgaming.com | 1825d8e | 2012-08-27 16:25:29 +0000 | [diff] [blame] | 60 | #define ERR(message, ...) gl::trace(false, "err: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__) |
Geoff Lang | f571312 | 2013-10-07 17:06:30 -0400 | [diff] [blame] | 61 | #else |
| 62 | #define ERR(message, ...) (void(0)) |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 63 | #endif |
| 64 | |
| 65 | // A macro to log a performance event around a scope. |
Austin Kinross | f0360c6 | 2014-10-20 14:26:13 -0700 | [diff] [blame] | 66 | #if defined(ANGLE_ENABLE_DEBUG_TRACE) || defined(ANGLE_ENABLE_DEBUG_ANNOTATIONS) |
Geoff Lang | f571312 | 2013-10-07 17:06:30 -0400 | [diff] [blame] | 67 | #if defined(_MSC_VER) |
Ehsan Akhgari | c1cc4c4 | 2014-07-02 13:09:07 -0400 | [diff] [blame] | 68 | #define EVENT(message, ...) gl::ScopedPerfEventHelper scopedPerfEventHelper ## __LINE__("%s" message "\n", __FUNCTION__, __VA_ARGS__); |
daniel@transgaming.com | 1825d8e | 2012-08-27 16:25:29 +0000 | [diff] [blame] | 69 | #else |
| 70 | #define EVENT(message, ...) gl::ScopedPerfEventHelper scopedPerfEventHelper(message "\n", ##__VA_ARGS__); |
Geoff Lang | f571312 | 2013-10-07 17:06:30 -0400 | [diff] [blame] | 71 | #endif // _MSC_VER |
| 72 | #else |
| 73 | #define EVENT(message, ...) (void(0)) |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 74 | #endif |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 75 | |
| 76 | // A macro asserting a condition and outputting failures to the debug log |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 77 | #if !defined(NDEBUG) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 78 | #define ASSERT(expression) do { \ |
| 79 | if(!(expression)) \ |
| 80 | ERR("\t! Assert failed in %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \ |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 81 | assert(expression); \ |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 82 | } while(0) |
Geoff Lang | 9cd1915 | 2014-05-28 15:54:34 -0400 | [diff] [blame] | 83 | #define UNUSED_ASSERTION_VARIABLE(variable) |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 84 | #else |
| 85 | #define ASSERT(expression) (void(0)) |
Geoff Lang | 9cd1915 | 2014-05-28 15:54:34 -0400 | [diff] [blame] | 86 | #define UNUSED_ASSERTION_VARIABLE(variable) ((void)variable) |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 87 | #endif |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 88 | |
Austin Kinross | f0360c6 | 2014-10-20 14:26:13 -0700 | [diff] [blame] | 89 | #ifndef ANGLE_ENABLE_DEBUG_TRACE |
Jamie Madill | bae30a0 | 2014-06-17 10:45:02 -0400 | [diff] [blame] | 90 | #define UNUSED_TRACE_VARIABLE(variable) ((void)variable) |
| 91 | #else |
| 92 | #define UNUSED_TRACE_VARIABLE(variable) |
| 93 | #endif |
| 94 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 95 | // A macro to indicate unimplemented functionality |
shannonwoods@chromium.org | eafb069 | 2013-05-30 00:20:44 +0000 | [diff] [blame] | 96 | |
Shannon Woods | 950cb60 | 2014-09-18 10:01:56 -0400 | [diff] [blame] | 97 | #if defined (ANGLE_TEST_CONFIG) |
| 98 | #define NOASSERT_UNIMPLEMENTED 1 |
| 99 | #endif |
| 100 | |
shannonwoods@chromium.org | eafb069 | 2013-05-30 00:20:44 +0000 | [diff] [blame] | 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 |
| 105 | #endif |
| 106 | |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 107 | #if !defined(NDEBUG) |
| 108 | #define UNIMPLEMENTED() do { \ |
| 109 | FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); \ |
shannonwoods@chromium.org | eafb069 | 2013-05-30 00:20:44 +0000 | [diff] [blame] | 110 | assert(NOASSERT_UNIMPLEMENTED); \ |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 111 | } while(0) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 112 | #else |
| 113 | #define UNIMPLEMENTED() FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__) |
| 114 | #endif |
| 115 | |
| 116 | // A macro for code which is not expected to be reached under valid assumptions |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 117 | #if !defined(NDEBUG) |
| 118 | #define UNREACHABLE() do { \ |
| 119 | ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__); \ |
| 120 | assert(false); \ |
| 121 | } while(0) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 122 | #else |
| 123 | #define UNREACHABLE() ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__) |
| 124 | #endif |
| 125 | |
apatrick@chromium.org | 8b400b1 | 2013-01-30 21:53:40 +0000 | [diff] [blame] | 126 | // A macro that determines whether an object has a given runtime type. |
Geoff Lang | 8690da8 | 2013-10-08 10:57:09 -0400 | [diff] [blame] | 127 | #if !defined(NDEBUG) && (!defined(_MSC_VER) || defined(_CPPRTTI)) && (!defined(__GNUC__) || __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3) || defined(__GXX_RTTI)) |
apatrick@chromium.org | 8b400b1 | 2013-01-30 21:53:40 +0000 | [diff] [blame] | 128 | #define HAS_DYNAMIC_TYPE(type, obj) (dynamic_cast<type >(obj) != NULL) |
| 129 | #else |
| 130 | #define HAS_DYNAMIC_TYPE(type, obj) true |
| 131 | #endif |
| 132 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 133 | // A macro functioning as a compile-time assert to validate constant conditions |
Jacek Caban | a5521de | 2014-10-01 17:23:46 +0200 | [diff] [blame] | 134 | #if (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__GNUC__) && (__GNUC__ > 4 || __GNUC_MINOR__ >= 3)) |
Geoff Lang | d0f8e82 | 2013-09-30 15:21:53 -0400 | [diff] [blame] | 135 | #define META_ASSERT_MSG(condition, msg) static_assert(condition, msg) |
| 136 | #else |
Jamie Madill | 4f26786 | 2014-04-17 15:53:37 -0400 | [diff] [blame] | 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] |
Geoff Lang | d0f8e82 | 2013-09-30 15:21:53 -0400 | [diff] [blame] | 140 | #endif |
| 141 | #define META_ASSERT(condition) META_ASSERT_MSG(condition, "compile time assertion failed.") |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 142 | |
| 143 | #endif // COMMON_DEBUG_H_ |