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/RtlRaiseStatus 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.
29 _In_z_ _Printf_format_string_ PCSTR Format
,
37 _In_ ULONG ComponentId
,
39 _In_z_ _Printf_format_string_ PCCH Format
,
48 PVOID FailedAssertion
,
54 #ifndef _NTDEF_ /* Guard against redefinition from ntdef.h */
55 typedef _Return_type_success_(return >= 0) LONG NTSTATUS
;
65 #endif /* !defined(_RTLFUNCS_H) && !defined(_NTDDK_) */
68 /* Fix usage of RtlRaiseStatus */
69 #if !defined(_RTLFUNCS_H) && defined(_NTDDK_)
70 #define RaiseStatus ExRaiseStatus
72 #define RaiseStatus RtlRaiseStatus
73 #endif /* !defined(_RTLFUNCS_H) && defined(_NTDDK_) */
78 #define assert(x) if (!(x)) { RtlAssert((PVOID)#x, (PVOID)__FILE__, __LINE__, ""); }
86 #define ASSERT(x) if (!(x)) { RtlAssert((PVOID)#x, (PVOID)__FILE__, __LINE__, ""); }
94 #define ASSERTMSG(x,m) if (!(x)) { RtlAssert((PVOID)#x, __FILE__, __LINE__, m); }
100 /* For internal purposes only */
101 #define __NOTICE(level, fmt, ...) DbgPrint(#level ": %s at %s:%d " fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
103 /* Print stuff only on Debug Builds*/
104 #define DPFLTR_DEFAULT_ID -1
107 /* These are always printed */
108 #define DPRINT1(fmt, ...) do { \
109 if (DbgPrint("(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)) \
110 DbgPrint("(%s:%d) DbgPrint() failed!\n", __FILE__, __LINE__); \
113 /* These are printed only if NDEBUG is NOT defined */
116 #define DPRINT(fmt, ...) do { \
117 if (DbgPrint("(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)) \
118 DbgPrint("(%s:%d) DbgPrint() failed!\n", __FILE__, __LINE__); \
123 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
127 #define UNIMPLEMENTED __NOTICE(WARNING, "is UNIMPLEMENTED!\n");
129 #define ERR_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_ERROR_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
130 #define WARN_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_WARNING_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
131 #define TRACE_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_TRACE_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
132 #define INFO_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_INFO_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
134 #define ERR__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_ERROR_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
135 #define WARN__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_WARNING_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
136 #define TRACE__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_TRACE_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
137 #define INFO__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_INFO_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
141 /* On non-debug builds, we never show these */
142 #define DPRINT1(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
143 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
145 #define UNIMPLEMENTED
147 #define ERR_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
148 #define WARN_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
149 #define TRACE_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
150 #define INFO_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
152 #define ERR__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
153 #define WARN__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
154 #define TRACE__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
155 #define INFO__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
159 /******************************************************************************/
160 /* For internal purposes only */
161 #define __ERROR_DBGBREAK(...) \
163 DbgPrint("" __VA_ARGS__); \
167 /* For internal purposes only */
168 #define __ERROR_FATAL(Status, ...) \
170 DbgPrint("" __VA_ARGS__); \
171 RaiseStatus((Status)); \
175 * These macros are designed to display an optional printf-like
176 * user-defined message and to break into the debugger.
177 * After that they allow to continue the program execution.
179 #define ERROR_DBGBREAK(...) \
181 __NOTICE(ERROR, "\n"); \
182 __ERROR_DBGBREAK(__VA_ARGS__); \
185 #define UNIMPLEMENTED_DBGBREAK(...) \
187 __NOTICE(ERROR, "is UNIMPLEMENTED!\n"); \
188 __ERROR_DBGBREAK(__VA_ARGS__); \
192 * These macros are designed to display an optional printf-like
193 * user-defined message and to break into the debugger.
194 * After that they halt the execution of the current thread.
196 #define ERROR_FATAL(...) \
198 __NOTICE(UNRECOVERABLE ERROR, "\n"); \
199 __ERROR_FATAL(STATUS_ASSERTION_FAILURE, __VA_ARGS__); \
202 #define UNIMPLEMENTED_FATAL(...) \
204 __NOTICE(UNRECOVERABLE ERROR, "is UNIMPLEMENTED!\n"); \
205 __ERROR_FATAL(STATUS_NOT_IMPLEMENTED, __VA_ARGS__); \
207 /******************************************************************************/
209 #define ASSERT_IRQL_LESS_OR_EQUAL(x) ASSERT(KeGetCurrentIrql()<=(x))
210 #define ASSERT_IRQL_EQUAL(x) ASSERT(KeGetCurrentIrql()==(x))
211 #define ASSERT_IRQL_LESS(x) ASSERT(KeGetCurrentIrql()<(x))
213 #endif /* __INTERNAL_DEBUG */