[DDK]
[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 PCCH Format,
31 IN ...
32 );
33
34 NTSYSAPI
35 ULONG
36 __cdecl
37 DbgPrintEx(
38 IN ULONG ComponentId,
39 IN ULONG Level,
40 IN PCCH Format,
41 IN ...
42 );
43
44 NTSYSAPI
45 VOID
46 NTAPI
47 RtlAssert(
48 PVOID FailedAssertion,
49 PVOID FileName,
50 ULONG LineNumber,
51 PCHAR Message
52 );
53
54 #endif /* !defined(_RTLFUNCS_H) && !defined(_NTDDK_) */
55
56 #ifndef assert
57 #ifndef NASSERT
58 #define assert(x) if (!(x)) {RtlAssert("#x",__FILE__,__LINE__, ""); }
59 #else
60 #define assert(x)
61 #endif
62 #endif
63
64 #ifndef ASSERT
65 #ifndef NASSERT
66 #define ASSERT(x) if (!(x)) {RtlAssert("#x",__FILE__,__LINE__, ""); }
67 #else
68 #define ASSERT(x)
69 #endif
70 #endif
71
72 #ifndef ASSERTMSG
73 #ifndef NASSERT
74 #define ASSERTMSG(x,m) if (!(x)) {RtlAssert("#x",__FILE__,__LINE__, m); }
75 #else
76 #define ASSERTMSG(x)
77 #endif
78 #endif
79
80 /* Print stuff only on Debug Builds*/
81 #define DPFLTR_DEFAULT_ID -1
82 #if DBG
83
84 /* These are always printed */
85 #define DPRINT1(fmt, ...) do { \
86 if (DbgPrint("(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)) \
87 DbgPrint("(%s:%d) DbgPrint() failed!\n", __FILE__, __LINE__); \
88 } while (0)
89
90 /* These are printed only if NDEBUG is NOT defined */
91 #ifndef NDEBUG
92
93 #define DPRINT(fmt, ...) do { \
94 if (DbgPrint("(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)) \
95 DbgPrint("(%s:%d) DbgPrint() failed!\n", __FILE__, __LINE__); \
96 } while (0)
97
98 #else
99
100 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
101
102 #endif
103
104 #define UNIMPLEMENTED DbgPrint("WARNING: %s at %s:%d is UNIMPLEMENTED!\n",__FUNCTION__,__FILE__,__LINE__);
105
106 #define ERR_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_ERROR_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
107 #define WARN_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_WARNING_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
108 #define TRACE_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_TRACE_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
109 #define INFO_(ch, fmt, ...) DbgPrintEx(DPFLTR_##ch##_ID, DPFLTR_INFO_LEVEL, "(%s:%d) " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
110 #else /* not DBG */
111
112 /* On non-debug builds, we never show these */
113 #define DPRINT1(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
114 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
115
116 #define UNIMPLEMENTED
117
118 #define ERR_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
119 #define WARN_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
120 #define TRACE_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
121 #define INFO_(ch, ...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
122 #endif /* not DBG */
123
124 #define ASSERT_IRQL_LESS_OR_EQUAL(x) ASSERT(KeGetCurrentIrql()<=(x))
125 #define ASSERT_IRQL_EQUAL(x) ASSERT(KeGetCurrentIrql()==(x))
126 #define ASSERT_IRQL_LESS(x) ASSERT(KeGetCurrentIrql()<(x))
127
128 #endif /* __INTERNAL_DEBUG */