summaryrefslogtreecommitdiffstats
path: root/Source/ThirdParty/ANGLE/src/common/debug.h
blob: 2c4ec701a3b45448e8347fffeeefd9280669a732 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//

// debug.h: Debugging utilities.

#ifndef COMMON_DEBUG_H_
#define COMMON_DEBUG_H_

#include <stdio.h>
#include <assert.h>

namespace gl
{
    // Outputs text to the debugging log
    void trace(const char *format, ...);
}

// A macro to output a trace of a function call and its arguments to the debugging log
#if !defined(NDEBUG) && !defined(ANGLE_DISABLE_TRACE) 
    #define TRACE(message, ...) gl::trace("trace: %s"message"\n", __FUNCTION__, __VA_ARGS__)
#else
    #define TRACE(...) ((void)0)
#endif

// 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.
#define FIXME(message, ...) gl::trace("fixme: %s"message"\n", __FUNCTION__, __VA_ARGS__)

// A macro to output a function call and its arguments to the debugging log, in case of error. Will occur even in release mode.
#define ERR(message, ...) gl::trace("err: %s"message"\n", __FUNCTION__, __VA_ARGS__)

// A macro asserting a condition and outputting failures to the debug log
#define ASSERT(expression) do { \
    if(!(expression)) \
        ERR("\t! Assert failed in %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \
    assert(expression); \
    } while(0)


// A macro to indicate unimplemented functionality
#ifndef NDEBUG
    #define UNIMPLEMENTED() do { \
        FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); \
        assert(false); \
        } while(0)
#else
    #define UNIMPLEMENTED() FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__)
#endif

// A macro for code which is not expected to be reached under valid assumptions
#ifndef NDEBUG
    #define UNREACHABLE() do { \
        ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__); \
        assert(false); \
        } while(0)
#else
    #define UNREACHABLE() ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__)
#endif

// A macro functioning as a compile-time assert to validate constant conditions
#define META_ASSERT(condition) typedef int COMPILE_TIME_ASSERT_##__LINE__[static_cast<bool>(condition)?1:-1]

#endif   // COMMON_DEBUG_H_