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 | |
12 | #include <assert.h> |
13 | #include <stdio.h> |
14 | #include <string> |
15 | |
16 | #include "common/angleutils.h" |
17 | |
18 | #if !defined(TRACE_OUTPUT_FILE) |
19 | #define TRACE_OUTPUT_FILE "debug.txt" |
20 | #endif |
21 | |
22 | namespace gl |
23 | { |
24 | |
25 | enum MessageType |
26 | { |
27 | MESSAGE_TRACE, |
28 | MESSAGE_FIXME, |
29 | MESSAGE_ERR, |
30 | MESSAGE_EVENT, |
31 | }; |
32 | |
33 | // Outputs text to the debugging log, or the debugging window |
34 | void trace(bool traceInDebugOnly, MessageType messageType, const char *format, ...); |
35 | |
36 | // Pairs a D3D begin event with an end event. |
37 | class ScopedPerfEventHelper : angle::NonCopyable |
38 | { |
39 | public: |
40 | ScopedPerfEventHelper(const char* format, ...); |
41 | ~ScopedPerfEventHelper(); |
42 | }; |
43 | |
44 | // Wraps the D3D9/D3D11 debug annotation functions. |
45 | class DebugAnnotator : angle::NonCopyable |
46 | { |
47 | public: |
48 | DebugAnnotator() { }; |
49 | virtual ~DebugAnnotator() { }; |
50 | virtual void beginEvent(const std::wstring &eventName) = 0; |
51 | virtual void endEvent() = 0; |
52 | virtual void setMarker(const std::wstring &markerName) = 0; |
53 | virtual bool getStatus() = 0; |
54 | }; |
55 | |
56 | void InitializeDebugAnnotations(DebugAnnotator *debugAnnotator); |
57 | void UninitializeDebugAnnotations(); |
58 | bool DebugAnnotationsActive(); |
59 | |
60 | } |
61 | |
62 | #if defined(ANGLE_ENABLE_DEBUG_TRACE) || defined(ANGLE_ENABLE_DEBUG_ANNOTATIONS) |
63 | #define ANGLE_TRACE_ENABLED |
64 | #endif |
65 | |
66 | // A macro to output a trace of a function call and its arguments to the debugging log |
67 | #if defined(ANGLE_TRACE_ENABLED) |
68 | #define TRACE(message, ...) gl::trace(true, gl::MESSAGE_TRACE, "trace: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__) |
69 | #else |
70 | #define TRACE(message, ...) (void(0)) |
71 | #endif |
72 | |
73 | // A macro to output a function call and its arguments to the debugging log, to denote an item in need of fixing. |
74 | #if defined(ANGLE_TRACE_ENABLED) |
75 | #define FIXME(message, ...) gl::trace(false, gl::MESSAGE_FIXME, "fixme: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__) |
76 | #else |
77 | #define FIXME(message, ...) (void(0)) |
78 | #endif |
79 | |
80 | // A macro to output a function call and its arguments to the debugging log, in case of error. |
81 | #if defined(ANGLE_TRACE_ENABLED) |
82 | #define ERR(message, ...) gl::trace(false, gl::MESSAGE_ERR, "err: %s(%d): " message "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__) |
83 | #else |
84 | #define ERR(message, ...) (void(0)) |
85 | #endif |
86 | |
87 | // A macro to log a performance event around a scope. |
88 | #if defined(ANGLE_TRACE_ENABLED) |
89 | #if defined(_MSC_VER) |
90 | #define EVENT(message, ...) gl::ScopedPerfEventHelper scopedPerfEventHelper ## __LINE__("%s" message "\n", __FUNCTION__, __VA_ARGS__); |
91 | #else |
92 | #define EVENT(message, ...) gl::ScopedPerfEventHelper scopedPerfEventHelper(message "\n", ##__VA_ARGS__); |
93 | #endif // _MSC_VER |
94 | #else |
95 | #define EVENT(message, ...) (void(0)) |
96 | #endif |
97 | |
98 | #if defined(ANGLE_TRACE_ENABLED) |
99 | #undef ANGLE_TRACE_ENABLED |
100 | #endif |
101 | |
102 | // A macro asserting a condition and outputting failures to the debug log |
103 | #if !defined(NDEBUG) |
104 | #define ASSERT(expression) do { \ |
105 | if(!(expression)) \ |
106 | ERR("\t! Assert failed in %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \ |
107 | assert(expression); \ |
108 | } while(0) |
109 | #define UNUSED_ASSERTION_VARIABLE(variable) |
110 | #else |
111 | #define ASSERT(expression) (void(0)) |
112 | #define UNUSED_ASSERTION_VARIABLE(variable) ((void)variable) |
113 | #endif |
114 | |
115 | #ifndef ANGLE_ENABLE_DEBUG_TRACE |
116 | #define UNUSED_TRACE_VARIABLE(variable) ((void)variable) |
117 | #else |
118 | #define UNUSED_TRACE_VARIABLE(variable) |
119 | #endif |
120 | |
121 | // A macro to indicate unimplemented functionality |
122 | |
123 | #if defined (ANGLE_TEST_CONFIG) |
124 | #define NOASSERT_UNIMPLEMENTED 1 |
125 | #endif |
126 | |
127 | // Define NOASSERT_UNIMPLEMENTED to non zero to skip the assert fail in the unimplemented checks |
128 | // This will allow us to test with some automated test suites (eg dEQP) without crashing |
129 | #ifndef NOASSERT_UNIMPLEMENTED |
130 | #define NOASSERT_UNIMPLEMENTED 0 |
131 | #endif |
132 | |
133 | #if !defined(NDEBUG) |
134 | #define UNIMPLEMENTED() do { \ |
135 | FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); \ |
136 | assert(NOASSERT_UNIMPLEMENTED); \ |
137 | } while(0) |
138 | #else |
139 | #define UNIMPLEMENTED() FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__) |
140 | #endif |
141 | |
142 | // A macro for code which is not expected to be reached under valid assumptions |
143 | #if !defined(NDEBUG) |
144 | #define UNREACHABLE() do { \ |
145 | ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__); \ |
146 | assert(false); \ |
147 | } while(0) |
148 | #else |
149 | #define UNREACHABLE() ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__) |
150 | #endif |
151 | |
152 | #endif // COMMON_DEBUG_H_ |
153 | |