only define DPRINT macro if the compiler can handle __VA_ARGS__
[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 UNIMPLEMENTED DbgPrint("WARNING: %s at %s:%d is UNIMPLEMENTED!\n",__FUNCTION__,__FILE__,__LINE__);
20
21 /* FIXME: should probably remove this later */
22 #if !defined(CHECKED) && !defined(NDEBUG)
23 #define CHECKED
24 #endif
25
26 #ifndef assert
27 #ifndef NASSERT
28 #define assert(x) if (!(x)) {RtlAssert("#x",__FILE__,__LINE__, ""); }
29 #else
30 #define assert(x)
31 #endif
32 #endif
33
34 #ifndef ASSERT
35 #ifndef NASSERT
36 #define ASSERT(x) if (!(x)) {RtlAssert("#x",__FILE__,__LINE__, ""); }
37 #else
38 #define ASSERT(x)
39 #endif
40 #endif
41
42 #ifndef ASSERTMSG
43 #ifndef NASSERT
44 #define ASSERTMSG(x,m) if (!(x)) {RtlAssert("#x",__FILE__,__LINE__, m); }
45 #else
46 #define ASSERTMSG(x)
47 #endif
48 #endif
49
50 /* Print stuff only on Debug Builds*/
51 #ifdef DBG
52
53 /* These are always printed */
54 #define DPRINT1 DbgPrint("(%s:%d) ",__FILE__,__LINE__), DbgPrint
55 #define CHECKPOINT1 do { DbgPrint("%s:%d\n",__FILE__,__LINE__); } while(0);
56
57 /* These are printed only if NDEBUG is NOT defined */
58 #ifndef NDEBUG
59
60 #define DPRINT DbgPrint("(%s:%d) ",__FILE__,__LINE__), DbgPrint
61 #define CHECKPOINT do { DbgPrint("%s:%d\n",__FILE__,__LINE__); } while(0);
62
63 #else
64 #if defined (__STDC__)
65 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
66 #endif
67 #define CHECKPOINT
68
69 #endif
70
71 #else
72
73 /* On non-debug builds, we never show these */
74 #if defined (__STDC__)
75 #define DPRINT1(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
76 #define DPRINT(...) do { if(0) { DbgPrint(__VA_ARGS__); } } while(0)
77 #endif
78 #define CHECKPOINT1
79 #define CHECKPOINT
80 #endif
81
82 /*
83 * FUNCTION: Assert a maximum value for the current irql
84 * ARGUMENTS:
85 * x = Maximum irql
86 */
87 #define ASSERT_IRQL(x) assert(KeGetCurrentIrql()<=(x))
88 #define assert_irql(x) assert(KeGetCurrentIrql()<=(x))
89
90 /* Macros expanding to the appropriate inline assembly to raise a breakpoint */
91 #if defined(_M_IX86)
92 #define ASM_BREAKPOINT "\nint $3\n"
93 #elif defined(_M_ALPHA)
94 #define ASM_BREAKPOINT "\ncall_pal bpt\n"
95 #elif defined(_M_MIPS)
96 #define ASM_BREAKPOINT "\nbreak\n"
97 #else
98 #error Unsupported architecture.
99 #endif
100
101 #ifndef KEBUGCHECK
102 #define KEBUGCHECK(a) DbgPrint("KeBugCheck (0x%X) at %s:%i\n", a, __FILE__,__LINE__), KeBugCheck(a)
103 #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)
104 #endif
105
106 #endif /* __INTERNAL_DEBUG */