Put a comment and an #if around the lines I changed in my previous commit, because...
[reactos.git] / reactos / 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 /* FIXME: should probably remove this later */
20 #if !defined(CHECKED) && !defined(NDEBUG)
21 #define CHECKED
22 #endif
23
24 /* Define DbgPrint/DbgPrintEx/RtlAssert unless the NDK is used */
25 #if !defined(_RTLFUNCS_H) && (!defined(_NTDDK_) || !defined(__NTDDK_H))
26
27 /* Make sure we have basic types (some people include us *before* SDK... */
28 #if !defined(_NTDEF_) && !defined(_WINDEF_) && !defined(_WINDEF_H)
29 #error Please include SDK first.
30 #endif
31
32 ULONG
33 __cdecl
34 DbgPrint(
35 IN PCCH Format,
36 IN ...
37 );
38
39 ULONG
40 __cdecl
41 DbgPrintEx(
42 IN ULONG ComponentId,
43 IN ULONG Level,
44 IN PCCH Format,
45 IN ...
46 );
47
48 NTSYSAPI
49 VOID
50 NTAPI
51 RtlAssert(
52 PVOID FailedAssertion,
53 PVOID FileName,
54 ULONG LineNumber,
55 PCHAR Message
56 );
57
58 #endif
59
60 #ifndef assert
61 #ifndef NASSERT
62 #define assert(x) if (!(x)) {RtlAssert("#x",__FILE__,__LINE__, ""); }
63 #else
64 #define assert(x)
65 #endif
66 #endif
67
68 #ifndef ASSERT
69 #ifndef NASSERT
70 #define ASSERT(x) if (!(x)) {RtlAssert("#x",__FILE__,__LINE__, ""); }
71 #else
72 #define ASSERT(x)
73 #endif
74 #endif
75
76 #ifndef ASSERTMSG
77 #ifndef NASSERT
78 #define ASSERTMSG(x,m) if (!(x)) {RtlAssert("#x",__FILE__,__LINE__, m); }
79 #else
80 #define ASSERTMSG(x)
81 #endif
82 #endif
83
84 /* Print stuff only on Debug Builds*/
85 #define DPFLTR_DEFAULT_ID -1
86 #ifdef DBG
87
88 /* These are always printed */
89 #define DPRINT1 DbgPrint("(%s:%d) ",__FILE__,__LINE__), DbgPrint
90 #define CHECKPOINT1 do { DbgPrint("%s:%d\n",__FILE__,__LINE__); } while(0);
91
92 /* These are printed only if NDEBUG is NOT defined */
93 #ifndef NDEBUG
94
95 #define DPRINT DbgPrint("(%s:%d) ",__FILE__,__LINE__), DbgPrint
96 #define CHECKPOINT do { DbgPrint("%s:%d\n",__FILE__,__LINE__); } while(0);
97
98 #else
99 #ifdef _MSC_VER
100 static __inline void DPRINT ( const char* fmt, ... )
101 {
102 UNREFERENCED_PARAMETER(fmt);
103 }
104 #else
105 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
106 #endif
107 #define CHECKPOINT
108 #endif
109
110 #define UNIMPLEMENTED DbgPrint("WARNING: %s at %s:%d is UNIMPLEMENTED!\n",__FUNCTION__,__FILE__,__LINE__);
111
112 /* The ##__VA_ARGS__ syntax is not a standard and was only tested with MSVC and GCC. If other compilers support them as well, add them to this #if block. */
113 #if defined(_MSC_VER) || defined(__GNUC__)
114 #define ERR_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_ERROR_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
115 #define WARN_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_WARNING_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
116 #define TRACE_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_TRACE_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
117 #define INFO_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_INFO_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
118 #endif
119 #else
120
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)
124
125 #define CHECKPOINT1
126 #define CHECKPOINT
127 #define UNIMPLEMENTED
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
134
135 /*
136 * FUNCTION: Assert a maximum value for the current irql
137 * ARGUMENTS:
138 * x = Maximum irql
139 */
140 #define ASSERT_IRQL(x) assert(KeGetCurrentIrql()<=(x))
141 #define assert_irql(x) assert(KeGetCurrentIrql()<=(x))
142
143 #ifndef KEBUGCHECK
144 #define KEBUGCHECK(a) DbgPrint("KeBugCheck (0x%X) at %s:%i\n", a, __FILE__,__LINE__), KeBugCheck(a)
145 #define KEBUGCHECKEX(a,b,c,d,e) DbgPrint("KeBugCheckEx (0x%X, 0x%X, 0x%X, 0x%X, 0x%X) at %s:%i\n", a, b, c, d, e, __FILE__,__LINE__), KeBugCheckEx(a,b,c,d,e)
146 #endif
147
148 #endif /* __INTERNAL_DEBUG */