e10d04de1bf656cd3ccde7f3cb1cf2b072cda1ad
[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/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 ULONG
30 __cdecl
31 DbgPrint(
32 IN PCH Format,
33 IN ...
34 );
35
36 VOID
37 NTAPI
38 RtlAssert(
39 PVOID FailedAssertion,
40 PVOID FileName,
41 ULONG LineNumber,
42 PCHAR Message
43 );
44 #endif
45
46 #endif
47
48 #ifndef assert
49 #ifndef NASSERT
50 #define assert(x) if (!(x)) {RtlAssert("#x",__FILE__,__LINE__, ""); }
51 #else
52 #define assert(x)
53 #endif
54 #endif
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 ASSERTMSG
65 #ifndef NASSERT
66 #define ASSERTMSG(x,m) if (!(x)) {RtlAssert("#x",__FILE__,__LINE__, m); }
67 #else
68 #define ASSERTMSG(x)
69 #endif
70 #endif
71
72 /* Print stuff only on Debug Builds*/
73 #ifdef DBG
74
75 /* These are always printed */
76 #define DPRINT1 DbgPrint("(%s:%d) ",__FILE__,__LINE__), DbgPrint
77 #define CHECKPOINT1 do { DbgPrint("%s:%d\n",__FILE__,__LINE__); } while(0);
78
79 /* These are printed only if NDEBUG is NOT defined */
80 #ifndef NDEBUG
81
82 #define DPRINT DbgPrint("(%s:%d) ",__FILE__,__LINE__), DbgPrint
83 #define CHECKPOINT do { DbgPrint("%s:%d\n",__FILE__,__LINE__); } while(0);
84
85 #else
86 #ifdef _MSC_VER
87 static __inline void DPRINT ( const char* fmt, ... )
88 {
89 //UNREFERENCED_PARAMETER(fmt);
90 }
91 #else
92 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
93 #endif
94 #define CHECKPOINT
95 #endif
96
97 #define UNIMPLEMENTED \
98 DbgPrint("WARNING: %s at %s:%d is UNIMPLEMENTED!\n",__FUNCTION__,__FILE__,__LINE__);
99
100 #else
101
102 /* On non-debug builds, we never show these */
103 #define DPRINT1(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
104 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
105
106 #define CHECKPOINT1
107 #define CHECKPOINT
108 #define UNIMPLEMENTED
109 #endif
110
111 /*
112 * FUNCTION: Assert a maximum value for the current irql
113 * ARGUMENTS:
114 * x = Maximum irql
115 */
116 #define ASSERT_IRQL(x) assert(KeGetCurrentIrql()<=(x))
117 #define assert_irql(x) assert(KeGetCurrentIrql()<=(x))
118
119 /* Macros expanding to the appropriate inline assembly to raise a breakpoint */
120 #if defined(_M_IX86)
121 #define ASM_BREAKPOINT "\nint $3\n"
122 #elif defined(_M_ALPHA)
123 #define ASM_BREAKPOINT "\ncall_pal bpt\n"
124 #elif defined(_M_MIPS)
125 #define ASM_BREAKPOINT "\nbreak\n"
126 #else
127 #error Unsupported architecture.
128 #endif
129
130 #ifndef KEBUGCHECK
131 #define KEBUGCHECK(a) DbgPrint("KeBugCheck (0x%X) at %s:%i\n", a, __FILE__,__LINE__), KeBugCheck(a)
132 #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)
133 #endif
134
135 #endif /* __INTERNAL_DEBUG */