1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/common/debug.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,114 @@ 1.4 +// 1.5 +// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. 1.6 +// Use of this source code is governed by a BSD-style license that can be 1.7 +// found in the LICENSE file. 1.8 +// 1.9 + 1.10 +// debug.h: Debugging utilities. 1.11 + 1.12 +#ifndef COMMON_DEBUG_H_ 1.13 +#define COMMON_DEBUG_H_ 1.14 + 1.15 +#include <stdio.h> 1.16 +#include <assert.h> 1.17 + 1.18 +#include "common/angleutils.h" 1.19 + 1.20 +#if !defined(TRACE_OUTPUT_FILE) 1.21 +#define TRACE_OUTPUT_FILE "debug.txt" 1.22 +#endif 1.23 + 1.24 +namespace gl 1.25 +{ 1.26 + // Outputs text to the debugging log 1.27 + void trace(bool traceFileDebugOnly, const char *format, ...); 1.28 + 1.29 + // Returns whether D3DPERF is active. 1.30 + bool perfActive(); 1.31 + 1.32 + // Pairs a D3D begin event with an end event. 1.33 + class ScopedPerfEventHelper 1.34 + { 1.35 + public: 1.36 + ScopedPerfEventHelper(const char* format, ...); 1.37 + ~ScopedPerfEventHelper(); 1.38 + 1.39 + private: 1.40 + DISALLOW_COPY_AND_ASSIGN(ScopedPerfEventHelper); 1.41 + }; 1.42 +} 1.43 + 1.44 +// A macro to output a trace of a function call and its arguments to the debugging log 1.45 +#if defined(ANGLE_DISABLE_TRACE) && defined(ANGLE_DISABLE_PERF) 1.46 +#define TRACE(message, ...) (void(0)) 1.47 +#else 1.48 +#define TRACE(message, ...) gl::trace(true, "trace: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__) 1.49 +#endif 1.50 + 1.51 +// A macro to output a function call and its arguments to the debugging log, to denote an item in need of fixing. 1.52 +#if defined(ANGLE_DISABLE_TRACE) && defined(ANGLE_DISABLE_PERF) 1.53 +#define FIXME(message, ...) (void(0)) 1.54 +#else 1.55 +#define FIXME(message, ...) gl::trace(false, "fixme: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__) 1.56 +#endif 1.57 + 1.58 +// A macro to output a function call and its arguments to the debugging log, in case of error. 1.59 +#if defined(ANGLE_DISABLE_TRACE) && defined(ANGLE_DISABLE_PERF) 1.60 +#define ERR(message, ...) (void(0)) 1.61 +#else 1.62 +#define ERR(message, ...) gl::trace(false, "err: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__) 1.63 +#endif 1.64 + 1.65 +// A macro to log a performance event around a scope. 1.66 +#if defined(ANGLE_DISABLE_TRACE) && defined(ANGLE_DISABLE_PERF) 1.67 +#define EVENT(message, ...) (void(0)) 1.68 +#elif defined(_MSC_VER) 1.69 +#define EVENT(message, ...) gl::ScopedPerfEventHelper scopedPerfEventHelper ## __LINE__(__FUNCTION__ message "\n", __VA_ARGS__); 1.70 +#else 1.71 +#define EVENT(message, ...) gl::ScopedPerfEventHelper scopedPerfEventHelper(message "\n", ##__VA_ARGS__); 1.72 +#endif 1.73 + 1.74 +// A macro asserting a condition and outputting failures to the debug log 1.75 +#if !defined(NDEBUG) 1.76 +#define ASSERT(expression) do { \ 1.77 + if(!(expression)) \ 1.78 + ERR("\t! Assert failed in %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \ 1.79 + assert(expression); \ 1.80 + } while(0) 1.81 +#else 1.82 +#define ASSERT(expression) (void(0)) 1.83 +#endif 1.84 + 1.85 +// A macro to indicate unimplemented functionality 1.86 +#if !defined(NDEBUG) 1.87 +#define UNIMPLEMENTED() do { \ 1.88 + FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); \ 1.89 + assert(false); \ 1.90 + } while(0) 1.91 +#else 1.92 + #define UNIMPLEMENTED() FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__) 1.93 +#endif 1.94 + 1.95 +// A macro for code which is not expected to be reached under valid assumptions 1.96 +#if !defined(NDEBUG) 1.97 +#define UNREACHABLE() do { \ 1.98 + ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__); \ 1.99 + assert(false); \ 1.100 + } while(0) 1.101 +#else 1.102 + #define UNREACHABLE() ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__) 1.103 +#endif 1.104 + 1.105 +// A macro that determines whether an object has a given runtime type. MSVC uses _CPPRTTI. 1.106 +// GCC uses __GXX_RTTI, but the macro was introduced in version 4.3, so we assume that all older 1.107 +// versions support RTTI. 1.108 +#if !defined(NDEBUG) && (!defined(_MSC_VER) || defined(_CPPRTTI)) && (!defined(__GNUC__) || __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3) || defined(__GXX_RTTI)) 1.109 +#define HAS_DYNAMIC_TYPE(type, obj) (dynamic_cast<type >(obj) != NULL) 1.110 +#else 1.111 +#define HAS_DYNAMIC_TYPE(type, obj) true 1.112 +#endif 1.113 + 1.114 +// A macro functioning as a compile-time assert to validate constant conditions 1.115 +#define META_ASSERT(condition) typedef int COMPILE_TIME_ASSERT_##__LINE__[static_cast<bool>(condition)?1:-1] 1.116 + 1.117 +#endif // COMMON_DEBUG_H_