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