1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 // debug.h: Debugging utilities.
24 #if !defined(TRACE_OUTPUT_FILE)
25 #define TRACE_OUTPUT_FILE "debug.txt"
30 // Outputs text to the debugging log
31 void trace(const char *format, ...);
32 inline void trace() {}
34 // Outputs text to the debugging log and prints to stderr.
35 void warn(const char *format, ...);
38 // Outputs the message to the debugging log and stderr, and calls abort().
39 void abort(const char *format, ...);
42 // A macro to output a trace of a function call and its arguments to the
43 // debugging log. Disabled if SWIFTSHADER_DISABLE_TRACE is defined.
44 #if defined(SWIFTSHADER_DISABLE_TRACE)
45 #define TRACE(message, ...) (void(0))
47 #define TRACE(message, ...) vk::trace("%s:%d TRACE: " message "\n", __FILE__, __LINE__, ##__VA_ARGS__)
50 // A macro to print a warning message to the debugging log and stderr to denote
51 // an issue that needs fixing.
52 #define FIXME(message, ...) vk::warn("%s:%d FIXME: " message "\n", __FILE__, __LINE__, ##__VA_ARGS__);
54 // A macro to print a warning message to the debugging log and stderr.
55 #define WARN(message, ...) vk::warn("%s:%d WARNING: " message "\n", __FILE__, __LINE__, ##__VA_ARGS__);
57 // A macro that prints the message to the debugging log and stderr and
58 // immediately aborts execution of the application.
60 // Note: This will terminate the application regardless of build flags!
61 // Use with extreme caution!
63 #define ABORT(message, ...) vk::abort("%s:%d ABORT: " message "\n", __FILE__, __LINE__, ##__VA_ARGS__)
65 // A macro that delegates to:
66 // ABORT() in debug builds (!NDEBUG || DCHECK_ALWAYS_ON)
68 // WARN() in release builds (NDEBUG && !DCHECK_ALWAYS_ON)
70 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
71 #define DABORT(message, ...) ABORT(message, ##__VA_ARGS__)
73 #define DABORT(message, ...) WARN(message, ##__VA_ARGS__)
76 // A macro asserting a condition.
77 // If the condition fails, the condition and message is passed to DABORT().
79 #define ASSERT_MSG(expression, format, ...) do { \
81 DABORT("ASSERT(%s): " format "\n", #expression, ##__VA_ARGS__); \
84 // A macro asserting a condition.
85 // If the condition fails, the condition is passed to DABORT().
87 #define ASSERT(expression) do { \
89 DABORT("ASSERT(%s)\n", #expression); \
92 // A macro to indicate unimplemented functionality.
94 #define UNIMPLEMENTED(format, ...) DABORT("UNIMPLEMENTED: " format, ##__VA_ARGS__)
96 // A macro for code which is not expected to be reached under valid assumptions.
98 #define UNREACHABLE(format, ...) DABORT("UNREACHABLE: " format, ##__VA_ARGS__)
100 // A macro asserting a condition and performing a return.
101 #undef ASSERT_OR_RETURN
102 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
103 #define ASSERT_OR_RETURN(expression) ASSERT(expression)
105 #define ASSERT_OR_RETURN(expression) do { \
106 if(!(expression)) { \
111 #endif // VK_DEBUG_H_