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 | { |
| 23 | // Outputs text to the debugging log |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 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 | }; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | // A macro to output a trace of a function call and its arguments to the debugging log |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 42 | #if defined(ANGLE_DISABLE_TRACE) && defined(ANGLE_DISABLE_PERF) |
| 43 | #define TRACE(message, ...) (void(0)) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 44 | #else |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 45 | #define TRACE(message, ...) gl::trace(true, "trace: %s(%d): "message"\n", __FUNCTION__, __LINE__, __VA_ARGS__) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 46 | #endif |
| 47 | |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 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_DISABLE_TRACE) && defined(ANGLE_DISABLE_PERF) |
| 50 | #define FIXME(message, ...) (void(0)) |
| 51 | #else |
| 52 | #define FIXME(message, ...) gl::trace(false, "fixme: %s(%d): "message"\n", __FUNCTION__, __LINE__, __VA_ARGS__) |
| 53 | #endif |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 54 | |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 55 | // A macro to output a function call and its arguments to the debugging log, in case of error. |
| 56 | #if defined(ANGLE_DISABLE_TRACE) && defined(ANGLE_DISABLE_PERF) |
| 57 | #define ERR(message, ...) (void(0)) |
| 58 | #else |
| 59 | #define ERR(message, ...) gl::trace(false, "err: %s(%d): "message"\n", __FUNCTION__, __LINE__, __VA_ARGS__) |
| 60 | #endif |
| 61 | |
| 62 | // A macro to log a performance event around a scope. |
| 63 | #if defined(ANGLE_DISABLE_TRACE) && defined(ANGLE_DISABLE_PERF) |
| 64 | #define EVENT(message, ...) (void(0)) |
| 65 | #else |
| 66 | #define EVENT(message, ...) gl::ScopedPerfEventHelper scopedPerfEventHelper ## __LINE__("%s\n" message, __FUNCTION__, __VA_ARGS__); |
| 67 | #endif |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 68 | |
| 69 | // 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] | 70 | #if !defined(NDEBUG) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 71 | #define ASSERT(expression) do { \ |
| 72 | if(!(expression)) \ |
| 73 | ERR("\t! Assert failed in %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \ |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 74 | assert(expression); \ |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 75 | } while(0) |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 76 | #else |
| 77 | #define ASSERT(expression) (void(0)) |
| 78 | #endif |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 79 | |
| 80 | // A macro to indicate unimplemented functionality |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 81 | #if !defined(NDEBUG) |
| 82 | #define UNIMPLEMENTED() do { \ |
| 83 | FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); \ |
| 84 | assert(false); \ |
| 85 | } while(0) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 86 | #else |
| 87 | #define UNIMPLEMENTED() FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__) |
| 88 | #endif |
| 89 | |
| 90 | // 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] | 91 | #if !defined(NDEBUG) |
| 92 | #define UNREACHABLE() do { \ |
| 93 | ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__); \ |
| 94 | assert(false); \ |
| 95 | } while(0) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 96 | #else |
| 97 | #define UNREACHABLE() ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__) |
| 98 | #endif |
| 99 | |
| 100 | // A macro functioning as a compile-time assert to validate constant conditions |
| 101 | #define META_ASSERT(condition) typedef int COMPILE_TIME_ASSERT_##__LINE__[static_cast<bool>(condition)?1:-1] |
| 102 | |
| 103 | #endif // COMMON_DEBUG_H_ |