- Synchronize up to trunk's revision r57864.
[reactos.git] / include / reactos / debug.h
1 /*
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 * PROGRAMMER: David Welch (welch@mcmail.com)
7 * UPDATE HISTORY:
8 * 28/05/98: Created
9 */
10
11 /*
12 * NOTE: Define NDEBUG before including this header to disable debugging
13 * macros
14 */
15
16 #ifndef __INTERNAL_DEBUG
17 #define __INTERNAL_DEBUG
18
19 /* Define DbgPrint/DbgPrintEx/RtlAssert unless the NDK is used */
20 #if !defined(_RTLFUNCS_H) && !defined(_NTDDK_)
21
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.
25 #endif
26
27 ULONG
28 __cdecl
29 DbgPrint(
30 _In_z_ _Printf_format_string_ PCSTR Format,
31 ...
32 );
33
34 NTSYSAPI
35 ULONG
36 __cdecl
37 DbgPrintEx(
38 _In_ ULONG ComponentId,
39 _In_ ULONG Level,
40 _In_z_ _Printf_format_string_ PCCH Format,
41 ...
42 );
43
44 __analysis_noreturn
45 NTSYSAPI
46 VOID
47 NTAPI
48 RtlAssert(
49 PVOID FailedAssertion,
50 PVOID FileName,
51 ULONG LineNumber,
52 PCHAR Message
53 );
54
55 #endif /* !defined(_RTLFUNCS_H) && !defined(_NTDDK_) */
56
57 #ifndef assert
58 #ifndef NASSERT
59 #define assert(x) if (!(x)) {RtlAssert((PVOID)#x,(PVOID)__FILE__,__LINE__, ""); }
60 #else
61 #define assert(x)
62 #endif
63 #endif
64
65 #ifndef ASSERT
66 #ifndef NASSERT
67 #define ASSERT(x) if (!(x)) {RtlAssert((PVOID)#x,(PVOID)__FILE__,__LINE__, ""); }
68 #else
69 #define ASSERT(x)
70 #endif
71 #endif
72
73 #ifndef ASSERTMSG
74 #ifndef NASSERT
75 #define ASSERTMSG(x,m) if (!(x)) {RtlAssert((PVOID)#x,__FILE__,__LINE__, m); }
76 #else
77 #define ASSERTMSG(x)
78 #endif
79 #endif
80
81 /* Print stuff only on Debug Builds*/
82 #define DPFLTR_DEFAULT_ID -1
83 #if DBG
84
85 /* These are always printed */
86 #define DPRINT1(fmt, ...) do { \
87 if (DbgPrint("(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)) \
88 DbgPrint("(%s:%d) DbgPrint() failed!\n", __FILE__, __LINE__); \
89 } while (0)
90
91 /* These are printed only if NDEBUG is NOT defined */
92 #ifndef NDEBUG
93
94 #define DPRINT(fmt, ...) do { \
95 if (DbgPrint("(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)) \
96 DbgPrint("(%s:%d) DbgPrint() failed!\n", __FILE__, __LINE__); \
97 } while (0)
98
99 #else
100
101 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
102
103 #endif
104
105 #define UNIMPLEMENTED DbgPrint("WARNING: %s at %s:%d is UNIMPLEMENTED!\n",__FUNCTION__,__FILE__,__LINE__);
106
107 #define ERR_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_ERROR_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
108 #define WARN_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_WARNING_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
109 #define TRACE_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_TRACE_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
110 #define INFO_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_INFO_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
111
112 #define ERR__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_ERROR_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
113 #define WARN__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_WARNING_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
114 #define TRACE__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_TRACE_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
115 #define INFO__(ch, fmt, ...) DbgPrintEx(ch, DPFLTR_INFO_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
116 #else /* not DBG */
117
118 /* On non-debug builds, we never show these */
119 #define DPRINT1(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
120 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
121
122 #define UNIMPLEMENTED
123
124 #define ERR_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
125 #define WARN_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
126 #define TRACE_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
127 #define INFO_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
128
129 #define ERR__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
130 #define WARN__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
131 #define TRACE__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
132 #define INFO__(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
133 #endif /* not DBG */
134
135 #define ASSERT_IRQL_LESS_OR_EQUAL(x) ASSERT(KeGetCurrentIrql()<=(x))
136 #define ASSERT_IRQL_EQUAL(x) ASSERT(KeGetCurrentIrql()==(x))
137 #define ASSERT_IRQL_LESS(x) ASSERT(KeGetCurrentIrql()<(x))
138
139 #endif /* __INTERNAL_DEBUG */