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 12 #include <stdio.h> 13 #include <assert.h> 14 15 #include "common/angleutils.h" 16 17 #if !defined(TRACE_OUTPUT_FILE) 18 #define TRACE_OUTPUT_FILE "debug.txt" 19 #endif 20 21 namespace gl 22 { 23 // Outputs text to the debugging log 24 void trace(bool traceFileDebugOnly, const char *format, ...); 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 }; 39 } 40 41 // A macro to output a trace of a function call and its arguments to the debugging log 42 #if defined(ANGLE_ENABLE_TRACE) || defined(ANGLE_ENABLE_PERF) 43 #define TRACE(message, ...) gl::trace(true, "trace: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__) 44 #else 45 #define TRACE(message, ...) (void(0)) 46 #endif 47 48 // A macro to output a function call and its arguments to the debugging log, to denote an item in need of fixing. 49 #if defined(ANGLE_ENABLE_TRACE) || defined(ANGLE_ENABLE_PERF) 50 #define FIXME(message, ...) gl::trace(false, "fixme: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__) 51 #else 52 #define FIXME(message, ...) (void(0)) 53 #endif 54 55 // A macro to output a function call and its arguments to the debugging log, in case of error. 56 #if defined(ANGLE_ENABLE_TRACE) || defined(ANGLE_ENABLE_PERF) 57 #define ERR(message, ...) gl::trace(false, "err: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__) 58 #else 59 #define ERR(message, ...) (void(0)) 60 #endif 61 62 // A macro to log a performance event around a scope. 63 #if defined(ANGLE_ENABLE_TRACE) || defined(ANGLE_ENABLE_PERF) 64 #if defined(_MSC_VER) 65 #define EVENT(message, ...) gl::ScopedPerfEventHelper scopedPerfEventHelper ## __LINE__(__FUNCTION__ message "\n", __VA_ARGS__); 66 #else 67 #define EVENT(message, ...) gl::ScopedPerfEventHelper scopedPerfEventHelper(message "\n", ##__VA_ARGS__); 68 #endif // _MSC_VER 69 #else 70 #define EVENT(message, ...) (void(0)) 71 #endif 72 73 // A macro asserting a condition and outputting failures to the debug log 74 #if !defined(NDEBUG) 75 #define ASSERT(expression) do { \ 76 if(!(expression)) \ 77 ERR("\t! Assert failed in %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \ 78 assert(expression); \ 79 } while(0) 80 #define UNUSED_ASSERTION_VARIABLE(variable) 81 #else 82 #define ASSERT(expression) (void(0)) 83 #define UNUSED_ASSERTION_VARIABLE(variable) ((void)variable) 84 #endif 85 86 // A macro to indicate unimplemented functionality 87 88 // Define NOASSERT_UNIMPLEMENTED to non zero to skip the assert fail in the unimplemented checks 89 // This will allow us to test with some automated test suites (eg dEQP) without crashing 90 #ifndef NOASSERT_UNIMPLEMENTED 91 #define NOASSERT_UNIMPLEMENTED 0 92 #endif 93 94 #if !defined(NDEBUG) 95 #define UNIMPLEMENTED() do { \ 96 FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); \ 97 assert(NOASSERT_UNIMPLEMENTED); \ 98 } while(0) 99 #else 100 #define UNIMPLEMENTED() FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__) 101 #endif 102 103 // A macro for code which is not expected to be reached under valid assumptions 104 #if !defined(NDEBUG) 105 #define UNREACHABLE() do { \ 106 ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__); \ 107 assert(false); \ 108 } while(0) 109 #else 110 #define UNREACHABLE() ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__) 111 #endif 112 113 // A macro that determines whether an object has a given runtime type. 114 #if !defined(NDEBUG) && (!defined(_MSC_VER) || defined(_CPPRTTI)) && (!defined(__GNUC__) || __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3) || defined(__GXX_RTTI)) 115 #define HAS_DYNAMIC_TYPE(type, obj) (dynamic_cast<type >(obj) != NULL) 116 #else 117 #define HAS_DYNAMIC_TYPE(type, obj) true 118 #endif 119 120 // A macro functioning as a compile-time assert to validate constant conditions 121 #if defined(_MSC_VER) && _MSC_VER >= 1600 122 #define META_ASSERT_MSG(condition, msg) static_assert(condition, msg) 123 #else 124 #define META_ASSERT_CONCAT(a, b) a ## b 125 #define META_ASSERT_CONCAT2(a, b) META_ASSERT_CONCAT(a, b) 126 #define META_ASSERT_MSG(condition, msg) typedef int META_ASSERT_CONCAT2(COMPILE_TIME_ASSERT_, __LINE__)[static_cast<bool>(condition)?1:-1] 127 #endif 128 #define META_ASSERT(condition) META_ASSERT_MSG(condition, "compile time assertion failed.") 129 130 #endif // COMMON_DEBUG_H_ 131