michael@0: // michael@0: // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: // debug.h: Debugging utilities. michael@0: michael@0: #ifndef COMMON_DEBUG_H_ michael@0: #define COMMON_DEBUG_H_ michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "common/angleutils.h" michael@0: michael@0: #if !defined(TRACE_OUTPUT_FILE) michael@0: #define TRACE_OUTPUT_FILE "debug.txt" michael@0: #endif michael@0: michael@0: namespace gl michael@0: { michael@0: // Outputs text to the debugging log michael@0: void trace(bool traceFileDebugOnly, const char *format, ...); michael@0: michael@0: // Returns whether D3DPERF is active. michael@0: bool perfActive(); michael@0: michael@0: // Pairs a D3D begin event with an end event. michael@0: class ScopedPerfEventHelper michael@0: { michael@0: public: michael@0: ScopedPerfEventHelper(const char* format, ...); michael@0: ~ScopedPerfEventHelper(); michael@0: michael@0: private: michael@0: DISALLOW_COPY_AND_ASSIGN(ScopedPerfEventHelper); michael@0: }; michael@0: } michael@0: michael@0: // A macro to output a trace of a function call and its arguments to the debugging log michael@0: #if defined(ANGLE_DISABLE_TRACE) && defined(ANGLE_DISABLE_PERF) michael@0: #define TRACE(message, ...) (void(0)) michael@0: #else michael@0: #define TRACE(message, ...) gl::trace(true, "trace: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__) michael@0: #endif michael@0: michael@0: // A macro to output a function call and its arguments to the debugging log, to denote an item in need of fixing. michael@0: #if defined(ANGLE_DISABLE_TRACE) && defined(ANGLE_DISABLE_PERF) michael@0: #define FIXME(message, ...) (void(0)) michael@0: #else michael@0: #define FIXME(message, ...) gl::trace(false, "fixme: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__) michael@0: #endif michael@0: michael@0: // A macro to output a function call and its arguments to the debugging log, in case of error. michael@0: #if defined(ANGLE_DISABLE_TRACE) && defined(ANGLE_DISABLE_PERF) michael@0: #define ERR(message, ...) (void(0)) michael@0: #else michael@0: #define ERR(message, ...) gl::trace(false, "err: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__) michael@0: #endif michael@0: michael@0: // A macro to log a performance event around a scope. michael@0: #if defined(ANGLE_DISABLE_TRACE) && defined(ANGLE_DISABLE_PERF) michael@0: #define EVENT(message, ...) (void(0)) michael@0: #elif defined(_MSC_VER) michael@0: #define EVENT(message, ...) gl::ScopedPerfEventHelper scopedPerfEventHelper ## __LINE__(__FUNCTION__ message "\n", __VA_ARGS__); michael@0: #else michael@0: #define EVENT(message, ...) gl::ScopedPerfEventHelper scopedPerfEventHelper(message "\n", ##__VA_ARGS__); michael@0: #endif michael@0: michael@0: // A macro asserting a condition and outputting failures to the debug log michael@0: #if !defined(NDEBUG) michael@0: #define ASSERT(expression) do { \ michael@0: if(!(expression)) \ michael@0: ERR("\t! Assert failed in %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \ michael@0: assert(expression); \ michael@0: } while(0) michael@0: #else michael@0: #define ASSERT(expression) (void(0)) michael@0: #endif michael@0: michael@0: // A macro to indicate unimplemented functionality michael@0: #if !defined(NDEBUG) michael@0: #define UNIMPLEMENTED() do { \ michael@0: FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); \ michael@0: assert(false); \ michael@0: } while(0) michael@0: #else michael@0: #define UNIMPLEMENTED() FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__) michael@0: #endif michael@0: michael@0: // A macro for code which is not expected to be reached under valid assumptions michael@0: #if !defined(NDEBUG) michael@0: #define UNREACHABLE() do { \ michael@0: ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__); \ michael@0: assert(false); \ michael@0: } while(0) michael@0: #else michael@0: #define UNREACHABLE() ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__) michael@0: #endif michael@0: michael@0: // A macro that determines whether an object has a given runtime type. MSVC uses _CPPRTTI. michael@0: // GCC uses __GXX_RTTI, but the macro was introduced in version 4.3, so we assume that all older michael@0: // versions support RTTI. michael@0: #if !defined(NDEBUG) && (!defined(_MSC_VER) || defined(_CPPRTTI)) && (!defined(__GNUC__) || __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3) || defined(__GXX_RTTI)) michael@0: #define HAS_DYNAMIC_TYPE(type, obj) (dynamic_cast(obj) != NULL) michael@0: #else michael@0: #define HAS_DYNAMIC_TYPE(type, obj) true michael@0: #endif michael@0: michael@0: // A macro functioning as a compile-time assert to validate constant conditions michael@0: #define META_ASSERT(condition) typedef int COMPILE_TIME_ASSERT_##__LINE__[static_cast(condition)?1:-1] michael@0: michael@0: #endif // COMMON_DEBUG_H_