- NDK 0.98, now with versionned headers. Too many changes to list, see the TinyKRNL...
[reactos.git] / reactos / ntoskrnl / include / internal / 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 * NOTES: Define DBG in configuration file for "checked" version
13 * Define NDEBUG before including this header to disable debugging
14 * macros
15 * Define NASSERT before including this header to disable assertions
16 */
17
18 #ifdef CHECKPOINT
19 #undef CHECKPOINT
20 #endif
21
22 #ifdef DPRINT
23 #undef DPRINT
24 #endif
25
26 #ifndef NDEBUG
27 #ifdef __GNUC__ /* using GNU C/C99 macro ellipsis */
28 #define DPRINT(args...) do { DbgPrint("(%s:%d) ",__FILE__,__LINE__); DbgPrint(args); } while(0)
29 #else
30 #define DPRINT DbgPrint("(%s:%d) ",__FILE__,__LINE__); DbgPrint
31 #endif
32 #define CHECKPOINT do { DbgPrint("%s:%d\n",__FILE__,__LINE__); } while(0)
33 #else /* NDEBUG */
34 #ifdef __GNUC__ /* using GNU C/C99 macro ellipsis */
35 #define DPRINT(args...)
36 #else
37 #define DPRINT
38 #endif
39 #define CHECKPOINT
40 #endif /* NDEBUG */
41
42 #ifndef __INTERNAL_DEBUG
43 #define __INTERNAL_DEBUG
44
45 #if defined(_MSC_VER) && (_MSC_VER < 1300)
46 /* TODO: Verify which version the MS compiler learned the __FUNCTION__ macro */
47 #define __FUNCTION__ "<unknown>"
48 #endif
49 #define UNIMPLEMENTED do {DbgPrint("%s at %s:%d is unimplemented, have a nice day\n",__FUNCTION__,__FILE__,__LINE__); for(;;); } while(0)
50
51
52 #ifdef assert
53 #undef assert
54 #endif
55
56 #ifdef DBG
57
58 #ifndef __USE_W32API
59 /* Assert only on "checked" version */
60 #ifndef NASSERT
61 #ifdef CONFIG_SMP
62 #define assert(x) if (!(x)) {DbgPrint("Assertion "#x" failed at %s:%d for CPU%d\n", __FILE__,__LINE__, KeGetCurrentProcessorNumber()), DbgBreakPoint(); }
63 #define ASSERT(x) if (!(x)) {DbgPrint("Assertion "#x" failed at %s:%d for CPU%d\n", __FILE__,__LINE__, KeGetCurrentProcessorNumber()), DbgBreakPoint(); }
64 #else
65 #define assert(x) if (!(x)) {DbgPrint("Assertion "#x" failed at %s:%d\n", __FILE__,__LINE__); DbgBreakPoint(); }
66 #define ASSERT(x) if (!(x)) {DbgPrint("Assertion "#x" failed at %s:%d\n", __FILE__,__LINE__); DbgBreakPoint(); }
67 #endif
68
69 #define assertmsg(_c_, _m_) \
70 if (!(_c_)) { \
71 DbgPrint("(%s:%d)(%s) ", __FILE__, __LINE__, __FUNCTION__); \
72 DbgPrint _m_ ; \
73 KeBugCheck(0); \
74 }
75
76 #define ASSERTMSG(_c_, _m_) \
77 if (!(_c_)) { \
78 DbgPrint("(%s:%d)(%s) ", __FILE__, __LINE__, __FUNCTION__); \
79 DbgPrint _m_ ; \
80 KeBugCheck(0); \
81 }
82
83 #else
84
85 #define assert(x)
86 #define ASSERT(x)
87 #define assertmsg(_c_, _m_)
88 #define ASSERTMSG(_c_, _m_)
89
90 #endif
91 #endif /* !__USE_W32API */
92
93 /* Print if using a "checked" version */
94 #ifdef __GNUC__ /* using GNU C/C99 macro ellipsis */
95 #define CPRINT(args...) do { DbgPrint("(%s:%d) ",__FILE__,__LINE__); DbgPrint(args); } while(0)
96 #else
97 #define CPRINT DbgPrint("(%s:%d) ",__FILE__,__LINE__); DbgPrint
98 #endif
99
100 #ifdef __GNUC__ /* using GNU C/C99 macro ellipsis */
101 #define DPRINT1(args...) do { DbgPrint("(%s:%d) ",__FILE__,__LINE__); DbgPrint(args); } while(0)
102 #else
103 #define DPRINT1 DbgPrint("(%s:%d) ",__FILE__,__LINE__); DbgPrint
104 #endif
105
106 #else /* DBG */
107
108 #define CPRINT(args...)
109 #define DPRINT1(args...)
110 #ifndef __USE_W32API
111 #define assert(x)
112 #define ASSERT(x)
113 #define assertmsg(_c_, _m_)
114 #define ASSERTMSG(_c_, _m_)
115 #endif /* !__USE_W32API */
116
117 #endif /* DBG */
118
119 #define CHECKPOINT1 do { DbgPrint("%s:%d\n",__FILE__,__LINE__); } while(0)
120
121 /*
122 * FUNCTION: Assert a maximum value for the current irql
123 * ARGUMENTS:
124 * x = Maximum irql
125 */
126 #define ASSERT_IRQL_LESS_OR_EQUAL(x) ASSERT(KeGetCurrentIrql()<=(x))
127 #define ASSERT_IRQL(x) ASSERT_IRQL_LESS_OR_EQUAL(x)
128 #define ASSERT_IRQL_EQUAL(x) ASSERT(KeGetCurrentIrql()==(x))
129 #define ASSERT_IRQL_LESS(x) ASSERT(KeGetCurrentIrql()<(x))
130 #define assert_irql(x) assert(KeGetCurrentIrql()<=(x))
131
132 #endif /* __INTERNAL_DEBUG */