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