blob: 2c4ec701a3b45448e8347fffeeefd9280669a732 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
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.com4f39fd92010-03-08 20:26:45 +000012#include <stdio.h>
13#include <assert.h>
14
15namespace gl
16{
17 // Outputs text to the debugging log
18 void trace(const char *format, ...);
19}
20
21// A macro to output a trace of a function call and its arguments to the debugging log
baustin@google.com71557742011-01-06 21:46:29 +000022#if !defined(NDEBUG) && !defined(ANGLE_DISABLE_TRACE)
daniel@transgaming.comd37dec82010-03-24 09:44:05 +000023 #define TRACE(message, ...) gl::trace("trace: %s"message"\n", __FUNCTION__, __VA_ARGS__)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000024#else
25 #define TRACE(...) ((void)0)
26#endif
27
28// A macro to output a function call and its arguments to the debugging log, to denote an item in need of fixing. Will occur even in release mode.
daniel@transgaming.comd37dec82010-03-24 09:44:05 +000029#define FIXME(message, ...) gl::trace("fixme: %s"message"\n", __FUNCTION__, __VA_ARGS__)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000030
31// A macro to output a function call and its arguments to the debugging log, in case of error. Will occur even in release mode.
daniel@transgaming.comd37dec82010-03-24 09:44:05 +000032#define ERR(message, ...) gl::trace("err: %s"message"\n", __FUNCTION__, __VA_ARGS__)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000033
34// A macro asserting a condition and outputting failures to the debug log
35#define ASSERT(expression) do { \
36 if(!(expression)) \
37 ERR("\t! Assert failed in %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \
38 assert(expression); \
39 } while(0)
40
41
42// A macro to indicate unimplemented functionality
43#ifndef NDEBUG
44 #define UNIMPLEMENTED() do { \
45 FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); \
46 assert(false); \
47 } while(0)
48#else
49 #define UNIMPLEMENTED() FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__)
50#endif
51
52// A macro for code which is not expected to be reached under valid assumptions
53#ifndef NDEBUG
54 #define UNREACHABLE() do { \
55 ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__); \
56 assert(false); \
57 } while(0)
58#else
59 #define UNREACHABLE() ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__)
60#endif
61
62// A macro functioning as a compile-time assert to validate constant conditions
63#define META_ASSERT(condition) typedef int COMPILE_TIME_ASSERT_##__LINE__[static_cast<bool>(condition)?1:-1]
64
65#endif // COMMON_DEBUG_H_