2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: include/reactos/debug.h
5 * PURPOSE: Useful debugging macros
6 * PROGRAMMERS: David Welch (welch@mcmail.com)
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
11 * NOTE: Define NDEBUG before including this header
12 * to disable debugging macros.
19 /* Define DbgPrint/DbgPrintEx/RtlAssert unless the NDK is used */
20 #if !defined(_RTLFUNCS_H) && !defined(_NTDDK_)
22 /* Make sure we have basic types (some people include us *before* SDK)... */
23 #if !defined(_NTDEF_) && !defined(_NTDEF_H) && !defined(_WINDEF_) && !defined(_WINDEF_H)
24 #error Please include SDK first.
34 _In_z_ _Printf_format_string_ PCSTR Format
,
42 _In_ ULONG ComponentId
,
44 _In_z_ _Printf_format_string_ PCSTR Format
,
53 _In_ PVOID FailedAssertion
,
55 _In_ ULONG LineNumber
,
56 _In_opt_z_ PCHAR Message
63 #endif /* !defined(_RTLFUNCS_H) && !defined(_NTDDK_) */
66 #if DBG && !defined(NASSERT)
67 #define assert(x) if (!(x)) { RtlAssert((PVOID)#x, (PVOID)__RELFILE__, __LINE__, ""); }
69 #define assert(x) ((VOID) 0)
74 #if DBG && !defined(NASSERT)
75 #define ASSERT(x) if (!(x)) { RtlAssert((PVOID)#x, (PVOID)__RELFILE__, __LINE__, ""); }
77 #define ASSERT(x) ((VOID) 0)
82 #if DBG && !defined(NASSERT)
83 #define ASSERTMSG(m, x) if (!(x)) { RtlAssert((PVOID)#x, __RELFILE__, __LINE__, m); }
85 #define ASSERTMSG(m, x) ((VOID) 0)
89 /* For internal purposes only */
90 #define __NOTICE(level, fmt, ...) DbgPrint(#level ": %s at %s:%d " fmt, __FUNCTION__, __RELFILE__, __LINE__, ##__VA_ARGS__)
92 /* Print stuff only on Debug Builds*/
95 /* These are always printed */
96 #define DPRINT1(fmt, ...) do { \
97 if (DbgPrint("(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)) \
98 DbgPrint("(%s:%d) DbgPrint() failed!\n", __RELFILE__, __LINE__); \
101 /* These are printed only if NDEBUG is NOT defined */
104 #define DPRINT(fmt, ...) do { \
105 if (DbgPrint("(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)) \
106 DbgPrint("(%s:%d) DbgPrint() failed!\n", __RELFILE__, __LINE__); \
111 #if defined(_MSC_VER)
112 #define DPRINT __noop
114 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
119 #define UNIMPLEMENTED __NOTICE(WARNING, "is UNIMPLEMENTED!\n")
121 #define ERR_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_ERROR_LEVEL, "(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)
122 #define WARN_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_WARNING_LEVEL, "(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)
123 #define TRACE_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_TRACE_LEVEL, "(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)
124 #define INFO_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_INFO_LEVEL, "(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)
126 #define ERR__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_ERROR_LEVEL, "(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)
127 #define WARN__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_WARNING_LEVEL, "(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)
128 #define TRACE__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_TRACE_LEVEL, "(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)
129 #define INFO__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_INFO_LEVEL, "(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)
133 /* On non-debug builds, we never show these */
134 #if defined(_MSC_VER)
135 #define DPRINT1 __noop
136 #define DPRINT __noop
138 #define UNIMPLEMENTED
140 #define ERR_(ch, ...) __noop
141 #define WARN_(ch, ...) __noop
142 #define TRACE_(ch, ...) __noop
143 #define INFO_(ch, ...) __noop
145 #define ERR__(ch, ...) __noop
146 #define WARN__(ch, ...) __noop
147 #define TRACE__(ch, ...) __noop
148 #define INFO__(ch, ...) __noop
150 #define DPRINT1(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
151 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
153 #define UNIMPLEMENTED
155 #define ERR_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
156 #define WARN_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
157 #define TRACE_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
158 #define INFO_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
160 #define ERR__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
161 #define WARN__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
162 #define TRACE__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
163 #define INFO__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
164 #endif /* _MSC_VER */
168 /******************************************************************************/
170 * Declare a target-dependent process termination procedure.
172 #ifndef _NTDDK_ /* User-Mode */
173 #ifndef NTOS_MODE_USER /* Should be Win32 */
175 #error "Unsupported target."
177 #define TerminateCurrentProcess(Status) TerminateProcess(GetCurrentProcess(), (Status))
185 IN HANDLE ProcessHandle
,
186 IN NTSTATUS ExitStatus
189 #ifndef NtCurrentProcess
190 #define NtCurrentProcess() ((HANDLE)(LONG_PTR)-1)
192 #define TerminateCurrentProcess(Status) NtTerminateProcess(NtCurrentProcess(), (Status))
194 #else /* Kernel-Mode */
195 #include <bugcodes.h>
196 #define TerminateCurrentProcess(Status) KeBugCheckEx(CRITICAL_SERVICE_FAILED, (Status), 0, 0, 0)
200 /* For internal purposes only */
201 #define __ERROR_DBGBREAK(...) \
203 DbgPrint("" __VA_ARGS__); \
207 /* For internal purposes only */
208 #define __ERROR_FATAL(Status, ...) \
210 DbgPrint("" __VA_ARGS__); \
212 TerminateCurrentProcess(Status); \
216 * These macros are designed to display an optional printf-like
217 * user-defined message and to break into the debugger.
218 * After that they allow to continue the program execution.
220 #define ERROR_DBGBREAK(...) \
222 __NOTICE(ERROR, "\n"); \
223 __ERROR_DBGBREAK(__VA_ARGS__); \
226 #define UNIMPLEMENTED_DBGBREAK(...) \
228 __NOTICE(ERROR, "is UNIMPLEMENTED!\n"); \
229 __ERROR_DBGBREAK(__VA_ARGS__); \
233 * These macros are designed to display an optional printf-like
234 * user-defined message and to break into the debugger.
235 * After that they halt the execution of the current thread.
237 #define ERROR_FATAL(...) \
239 __NOTICE(UNRECOVERABLE ERROR, "\n"); \
240 __ERROR_FATAL(STATUS_ASSERTION_FAILURE, __VA_ARGS__); \
243 #define UNIMPLEMENTED_FATAL(...) \
245 __NOTICE(UNRECOVERABLE ERROR, "is UNIMPLEMENTED!\n"); \
246 __ERROR_FATAL(STATUS_NOT_IMPLEMENTED, __VA_ARGS__); \
248 /******************************************************************************/
250 #define ASSERT_IRQL_LESS_OR_EQUAL(x) ASSERT(KeGetCurrentIrql()<=(x))
251 #define ASSERT_IRQL_EQUAL(x) ASSERT(KeGetCurrentIrql()==(x))
252 #define ASSERT_IRQL_LESS(x) ASSERT(KeGetCurrentIrql()<(x))
254 #define __STRING2__(x) #x
255 #define __STRING__(x) __STRING2__(x)
256 #define __STRLINE__ __STRING__(__LINE__)
258 #if !defined(_MSC_VER) && !defined(__pragma)
259 #define __pragma(x) _Pragma(#x)
262 #define _WARN(msg) __pragma(message("WARNING! Line " __STRLINE__ ": " msg))