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