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 #if !defined(__RELFILE__)
20 #define __RELFILE__ __FILE__
23 /* Define DbgPrint/DbgPrintEx/RtlAssert unless the NDK is used */
24 #if !defined(_RTLFUNCS_H) && !defined(_NTDDK_)
26 /* Make sure we have basic types (some people include us *before* SDK)... */
27 #if !defined(_NTDEF_) && !defined(_NTDEF_H) && !defined(_WINDEF_) && !defined(_WINDEF_H)
28 #error Please include SDK first.
38 _In_z_ _Printf_format_string_ PCSTR Format
,
46 _In_ ULONG ComponentId
,
48 _In_z_ _Printf_format_string_ PCSTR Format
,
57 _In_ PVOID FailedAssertion
,
59 _In_ ULONG LineNumber
,
60 _In_opt_z_ PCHAR Message
67 #endif /* !defined(_RTLFUNCS_H) && !defined(_NTDDK_) */
70 #if DBG && !defined(NASSERT)
71 #define assert(x) if (!(x)) { RtlAssert((PVOID)#x, (PVOID)__RELFILE__, __LINE__, ""); }
73 #define assert(x) ((VOID) 0)
78 #if DBG && !defined(NASSERT)
79 #define ASSERT(x) if (!(x)) { RtlAssert((PVOID)#x, (PVOID)__RELFILE__, __LINE__, ""); }
81 #define ASSERT(x) ((VOID) 0)
86 #if DBG && !defined(NASSERT)
87 #define ASSERTMSG(m, x) if (!(x)) { RtlAssert((PVOID)#x, __RELFILE__, __LINE__, m); }
89 #define ASSERTMSG(m, x) ((VOID) 0)
93 /* For internal purposes only */
94 #define __NOTICE(level, fmt, ...) DbgPrint(#level ": %s at %s:%d " fmt, __FUNCTION__, __RELFILE__, __LINE__, ##__VA_ARGS__)
96 /* Print stuff only on Debug Builds*/
97 #define DPFLTR_DEFAULT_ID -1
100 /* These are always printed */
101 #define DPRINT1(fmt, ...) do { \
102 if (DbgPrint("(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)) \
103 DbgPrint("(%s:%d) DbgPrint() failed!\n", __RELFILE__, __LINE__); \
106 /* These are printed only if NDEBUG is NOT defined */
109 #define DPRINT(fmt, ...) do { \
110 if (DbgPrint("(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)) \
111 DbgPrint("(%s:%d) DbgPrint() failed!\n", __RELFILE__, __LINE__); \
116 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
120 #define UNIMPLEMENTED __NOTICE(WARNING, "is UNIMPLEMENTED!\n");
122 #define ERR_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_ERROR_LEVEL, "(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)
123 #define WARN_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_WARNING_LEVEL, "(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)
124 #define TRACE_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_TRACE_LEVEL, "(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)
125 #define INFO_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_INFO_LEVEL, "(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)
127 #define ERR__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_ERROR_LEVEL, "(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)
128 #define WARN__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_WARNING_LEVEL, "(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)
129 #define TRACE__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_TRACE_LEVEL, "(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)
130 #define INFO__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_INFO_LEVEL, "(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__)
134 /* On non-debug builds, we never show these */
135 #define DPRINT1(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
136 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
138 #define UNIMPLEMENTED
140 #define ERR_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
141 #define WARN_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
142 #define TRACE_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
143 #define INFO_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
145 #define ERR__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
146 #define WARN__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
147 #define TRACE__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
148 #define INFO__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
152 /******************************************************************************/
154 * Declare a target-dependent process termination procedure.
156 #ifndef _NTDDK_ /* User-Mode */
157 #ifndef NTOS_MODE_USER /* Should be Win32 */
159 #error "Unsupported target."
161 #define TerminateCurrentProcess(Status) TerminateProcess(GetCurrentProcess(), (Status))
169 IN HANDLE ProcessHandle
,
170 IN NTSTATUS ExitStatus
173 #ifndef NtCurrentProcess
174 #define NtCurrentProcess() ((HANDLE)(LONG_PTR)-1)
176 #define TerminateCurrentProcess(Status) NtTerminateProcess(NtCurrentProcess(), (Status))
178 #else /* Kernel-Mode */
179 #include <bugcodes.h>
180 #define TerminateCurrentProcess(Status) KeBugCheckEx(CRITICAL_SERVICE_FAILED, (Status), 0, 0, 0)
184 /* For internal purposes only */
185 #define __ERROR_DBGBREAK(...) \
187 DbgPrint("" __VA_ARGS__); \
191 /* For internal purposes only */
192 #define __ERROR_FATAL(Status, ...) \
194 DbgPrint("" __VA_ARGS__); \
196 TerminateCurrentProcess(Status); \
200 * These macros are designed to display an optional printf-like
201 * user-defined message and to break into the debugger.
202 * After that they allow to continue the program execution.
204 #define ERROR_DBGBREAK(...) \
206 __NOTICE(ERROR, "\n"); \
207 __ERROR_DBGBREAK(__VA_ARGS__); \
210 #define UNIMPLEMENTED_DBGBREAK(...) \
212 __NOTICE(ERROR, "is UNIMPLEMENTED!\n"); \
213 __ERROR_DBGBREAK(__VA_ARGS__); \
217 * These macros are designed to display an optional printf-like
218 * user-defined message and to break into the debugger.
219 * After that they halt the execution of the current thread.
221 #define ERROR_FATAL(...) \
223 __NOTICE(UNRECOVERABLE ERROR, "\n"); \
224 __ERROR_FATAL(STATUS_ASSERTION_FAILURE, __VA_ARGS__); \
227 #define UNIMPLEMENTED_FATAL(...) \
229 __NOTICE(UNRECOVERABLE ERROR, "is UNIMPLEMENTED!\n"); \
230 __ERROR_FATAL(STATUS_NOT_IMPLEMENTED, __VA_ARGS__); \
232 /******************************************************************************/
234 #define ASSERT_IRQL_LESS_OR_EQUAL(x) ASSERT(KeGetCurrentIrql()<=(x))
235 #define ASSERT_IRQL_EQUAL(x) ASSERT(KeGetCurrentIrql()==(x))
236 #define ASSERT_IRQL_LESS(x) ASSERT(KeGetCurrentIrql()<(x))
238 #define __STRING2__(x) #x
239 #define __STRING__(x) __STRING2__(x)
240 #define __STRLINE__ __STRING__(__LINE__)
242 #if !defined(_MSC_VER) && !defined(__pragma)
243 #define __pragma(x) _Pragma(#x)
246 #define _WARN(msg) __pragma(message("WARNING! Line " __STRLINE__ ": " msg))