2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: include/internal/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.
15 #ifndef __INTERNAL_DEBUG
16 #define __INTERNAL_DEBUG
18 /* Define DbgPrint/DbgPrintEx/RtlAssert unless the NDK is used */
19 #if !defined(_RTLFUNCS_H) && !defined(_NTDDK_)
21 /* Make sure we have basic types (some people include us *before* SDK)... */
22 #if !defined(_NTDEF_) && !defined(_NTDEF_H) && !defined(_WINDEF_) && !defined(_WINDEF_H)
23 #error Please include SDK first.
33 _In_z_ _Printf_format_string_ PCSTR Format
,
41 _In_ ULONG ComponentId
,
43 _In_z_ _Printf_format_string_ PCSTR Format
,
52 _In_ PVOID FailedAssertion
,
54 _In_ ULONG LineNumber
,
55 _In_opt_z_ PCHAR Message
62 #endif /* !defined(_RTLFUNCS_H) && !defined(_NTDDK_) */
65 #if DBG && !defined(NASSERT)
66 #define assert(x) if (!(x)) { RtlAssert((PVOID)#x, (PVOID)__FILE__, __LINE__, ""); }
68 #define assert(x) ((VOID) 0)
73 #if DBG && !defined(NASSERT)
74 #define ASSERT(x) if (!(x)) { RtlAssert((PVOID)#x, (PVOID)__FILE__, __LINE__, ""); }
76 #define ASSERT(x) ((VOID) 0)
81 #if DBG && !defined(NASSERT)
82 #define ASSERTMSG(m, x) if (!(x)) { RtlAssert((PVOID)#x, __FILE__, __LINE__, m); }
84 #define ASSERTMSG(m, x) ((VOID) 0)
88 /* For internal purposes only */
89 #define __NOTICE(level, fmt, ...) DbgPrint(#level ": %s at %s:%d " fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
91 /* Print stuff only on Debug Builds*/
92 #define DPFLTR_DEFAULT_ID -1
95 /* These are always printed */
96 #define DPRINT1(fmt, ...) do { \
97 if (DbgPrint("(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)) \
98 DbgPrint("(%s:%d) DbgPrint() failed!\n", __FILE__, __LINE__); \
101 /* These are printed only if NDEBUG is NOT defined */
104 #define DPRINT(fmt, ...) do { \
105 if (DbgPrint("(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)) \
106 DbgPrint("(%s:%d) DbgPrint() failed!\n", __FILE__, __LINE__); \
111 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
115 #define UNIMPLEMENTED __NOTICE(WARNING, "is UNIMPLEMENTED!\n");
117 #define ERR_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_ERROR_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
118 #define WARN_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_WARNING_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
119 #define TRACE_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_TRACE_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
120 #define INFO_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_INFO_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
122 #define ERR__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_ERROR_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
123 #define WARN__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_WARNING_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
124 #define TRACE__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_TRACE_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
125 #define INFO__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_INFO_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
129 /* On non-debug builds, we never show these */
130 #define DPRINT1(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
131 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
133 #define UNIMPLEMENTED
135 #define ERR_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
136 #define WARN_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
137 #define TRACE_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
138 #define INFO_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
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)
147 /******************************************************************************/
149 * Declare a target-dependent process termination procedure.
151 #ifndef _NTDDK_ /* User-Mode */
152 #ifndef NTOS_MODE_USER /* Should be Win32 */
154 #error "Unsupported target."
156 #define TerminateCurrentProcess(Status) TerminateProcess(GetCurrentProcess(), (Status))
164 IN HANDLE ProcessHandle
,
165 IN NTSTATUS ExitStatus
168 #ifndef NtCurrentProcess
169 #define NtCurrentProcess() ((HANDLE)(LONG_PTR)-1)
171 #define TerminateCurrentProcess(Status) NtTerminateProcess(NtCurrentProcess(), (Status))
173 #else /* Kernel-Mode */
174 #include <bugcodes.h>
175 #define TerminateCurrentProcess(Status) KeBugCheckEx(CRITICAL_SERVICE_FAILED, (Status), 0, 0, 0)
179 /* For internal purposes only */
180 #define __ERROR_DBGBREAK(...) \
182 DbgPrint("" __VA_ARGS__); \
186 /* For internal purposes only */
187 #define __ERROR_FATAL(Status, ...) \
189 DbgPrint("" __VA_ARGS__); \
191 TerminateCurrentProcess(Status); \
195 * These macros are designed to display an optional printf-like
196 * user-defined message and to break into the debugger.
197 * After that they allow to continue the program execution.
199 #define ERROR_DBGBREAK(...) \
201 __NOTICE(ERROR, "\n"); \
202 __ERROR_DBGBREAK(__VA_ARGS__); \
205 #define UNIMPLEMENTED_DBGBREAK(...) \
207 __NOTICE(ERROR, "is UNIMPLEMENTED!\n"); \
208 __ERROR_DBGBREAK(__VA_ARGS__); \
212 * These macros are designed to display an optional printf-like
213 * user-defined message and to break into the debugger.
214 * After that they halt the execution of the current thread.
216 #define ERROR_FATAL(...) \
218 __NOTICE(UNRECOVERABLE ERROR, "\n"); \
219 __ERROR_FATAL(STATUS_ASSERTION_FAILURE, __VA_ARGS__); \
222 #define UNIMPLEMENTED_FATAL(...) \
224 __NOTICE(UNRECOVERABLE ERROR, "is UNIMPLEMENTED!\n"); \
225 __ERROR_FATAL(STATUS_NOT_IMPLEMENTED, __VA_ARGS__); \
227 /******************************************************************************/
229 #define ASSERT_IRQL_LESS_OR_EQUAL(x) ASSERT(KeGetCurrentIrql()<=(x))
230 #define ASSERT_IRQL_EQUAL(x) ASSERT(KeGetCurrentIrql()==(x))
231 #define ASSERT_IRQL_LESS(x) ASSERT(KeGetCurrentIrql()<(x))
233 #define __STRING2__(x) #x
234 #define __STRING__(x) __STRING2__(x)
235 #define __STRLINE__ __STRING__(__LINE__)
237 #define __TOKENPASTE2__(x, y) x ## y
238 #define __TOKENPASTE__(x, y) __TOKENPASTE2__(x, y)
241 #define _WARN(msg) __pragma(message("WARNING! Line " __STRLINE__ ": " msg))
243 #define _WARN1(_func1, _func2, _msg) void __attribute__((warning (_msg))) _func1(void); void __attribute__((used)) _func2(void) { _func1(); }
244 #define _WARN(_msg) _WARN1(__TOKENPASTE__(__warn_func1__, __LINE__), __TOKENPASTE__(__warn_func2__, __LINE__), _msg)
247 #endif /* __INTERNAL_DEBUG */