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