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.
29 _In_z_ _Printf_format_string_ PCSTR Format
,
37 _In_ ULONG ComponentId
,
39 _In_z_ _Printf_format_string_ PCCH Format
,
48 PVOID FailedAssertion
,
54 #endif /* !defined(_RTLFUNCS_H) && !defined(_NTDDK_) */
58 #define assert(x) if (!(x)) { RtlAssert((PVOID)#x, (PVOID)__FILE__, __LINE__, ""); }
66 #define ASSERT(x) if (!(x)) { RtlAssert((PVOID)#x, (PVOID)__FILE__, __LINE__, ""); }
74 #define ASSERTMSG(x,m) if (!(x)) { RtlAssert((PVOID)#x, __FILE__, __LINE__, m); }
80 /* For internal purposes only */
81 #define __NOTICE(level, fmt, ...) DbgPrint(#level ": %s at %s:%d " fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
83 /* Print stuff only on Debug Builds*/
84 #define DPFLTR_DEFAULT_ID -1
87 /* These are always printed */
88 #define DPRINT1(fmt, ...) do { \
89 if (DbgPrint("(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)) \
90 DbgPrint("(%s:%d) DbgPrint() failed!\n", __FILE__, __LINE__); \
93 /* These are printed only if NDEBUG is NOT defined */
96 #define DPRINT(fmt, ...) do { \
97 if (DbgPrint("(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)) \
98 DbgPrint("(%s:%d) DbgPrint() failed!\n", __FILE__, __LINE__); \
103 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
107 #define UNIMPLEMENTED __NOTICE(WARNING, "is UNIMPLEMENTED!\n");
109 #define ERR_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_ERROR_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
110 #define WARN_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_WARNING_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
111 #define TRACE_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_TRACE_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
112 #define INFO_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_INFO_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
114 #define ERR__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_ERROR_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
115 #define WARN__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_WARNING_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
116 #define TRACE__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_TRACE_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
117 #define INFO__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_INFO_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
121 /* On non-debug builds, we never show these */
122 #define DPRINT1(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
123 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
125 #define UNIMPLEMENTED
127 #define ERR_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
128 #define WARN_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
129 #define TRACE_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
130 #define INFO_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
132 #define ERR__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
133 #define WARN__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
134 #define TRACE__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
135 #define INFO__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
140 * These macros are designed to display an optional printf-like
141 * user-defined message and to break into the debugger.
142 * After that they allow to continue the program execution.
144 /* For internal purposes only */
145 #define __ERROR_DBGBREAK(...) \
147 DbgPrint("" __VA_ARGS__); \
151 #define ERROR_DBGBREAK(...) \
153 __NOTICE(ERROR, "\n"); \
154 __ERROR_DBGBREAK(__VA_ARGS__); \
157 #define UNIMPLEMENTED_DBGBREAK(...) \
159 __NOTICE(ERROR, "is UNIMPLEMENTED!\n"); \
160 __ERROR_DBGBREAK(__VA_ARGS__); \
164 * These macros are designed to display an optional printf-like
165 * user-defined message and to break into the debugger.
166 * After that they halt the execution of the current thread.
168 #define ERROR_FATAL(...) \
170 __NOTICE(UNRECOVERABLE ERROR, "\n"); \
171 __ERROR_DBGBREAK(__VA_ARGS__); \
175 #define UNIMPLEMENTED_FATAL(...) \
177 __NOTICE(UNRECOVERABLE ERROR, "is UNIMPLEMENTED!\n"); \
178 __ERROR_DBGBREAK(__VA_ARGS__); \
182 #define ASSERT_IRQL_LESS_OR_EQUAL(x) ASSERT(KeGetCurrentIrql()<=(x))
183 #define ASSERT_IRQL_EQUAL(x) ASSERT(KeGetCurrentIrql()==(x))
184 #define ASSERT_IRQL_LESS(x) ASSERT(KeGetCurrentIrql()<(x))
186 #endif /* __INTERNAL_DEBUG */