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