xref: /reactos/sdk/include/psdk/ksdebug.h (revision 4561998a)
1 /*
2  * ksdebug.h
3  *
4  * This file is part of the ReactOS PSDK package.
5  *
6  * Contributors:
7  *   Created by Magnus Olsen.
8  *
9  * THIS SOFTWARE IS NOT COPYRIGHTED
10  *
11  * This source code is offered for use in the public domain. You may
12  * use, modify or distribute it freely.
13  *
14  * This code is distributed in the hope that it will be useful but
15  * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
16  * DISCLAIMED. This includes but is not limited to warranties of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  */
20 
21 #include <evntrace.h>
22 
23 #if !defined(_KSDEBUG_)
24 #define _KSDEBUG_
25 
26 #if !defined(REMIND)
27 #define QUOTE(x) #x
28 #define QQUOTE(y) QUOTE(y)
29 #define REMIND(str) __FILE__ "(" QQUOTE(__LINE__) ") : " str
30 #endif
31 
32 #if defined(__cplusplus)
33 extern "C" {
34 #endif
35 
36 #if (DBG)
37 
38 #if defined(IRPMJFUNCDESC)
39 static const PCHAR IrpMjFuncDesc[] = {
40   "IRP_MJ_CREATE",
41   "IRP_MJ_CREATE_NAMED_PIPE",
42   "IRP_MJ_CLOSE",
43   "IRP_MJ_READ",
44   "IRP_MJ_WRITE",
45   "IRP_MJ_QUERY_INFORMATION",
46   "IRP_MJ_SET_INFORMATION",
47   "IRP_MJ_QUERY_EA",
48   "IRP_MJ_SET_EA",
49   "IRP_MJ_FLUSH_BUFFERS",
50   "IRP_MJ_QUERY_VOLUME_INFORMATION",
51   "IRP_MJ_SET_VOLUME_INFORMATION",
52   "IRP_MJ_DIRECTORY_CONTROL",
53   "IRP_MJ_FILE_SYSTEM_CONTROL",
54   "IRP_MJ_DEVICE_CONTROL",
55   "IRP_MJ_INTERNAL_DEVICE_CONTROL",
56   "IRP_MJ_SHUTDOWN",
57   "IRP_MJ_LOCK_CONTROL",
58   "IRP_MJ_CLEANUP",
59   "IRP_MJ_CREATE_MAILSLOT",
60   "IRP_MJ_QUERY_SECURITY",
61   "IRP_MJ_SET_SECURITY",
62   "IRP_MJ_SET_POWER",
63   "IRP_MJ_QUERY_POWER"
64 };
65 #endif /* defined(IRPMJFUNCDESC) */
66 
67 #endif /* DBG */
68 
69 #if defined(_NTDDK_)
70 
71 #define DEBUGLVL_BLAB TRACE_LEVEL_VERBOSE
72 #define DEBUGLVL_VERBOSE TRACE_LEVEL_VERBOSE
73 #define DEBUGLVL_TERSE TRACE_LEVEL_INFORMATION
74 #define DEBUGLVL_ERROR TRACE_LEVEL_ERROR
75 
76 #define DEBUGLVL_WARNING TRACE_LEVEL_WARNING
77 #define DEBUGLVL_INFO TRACE_LEVEL_INFORMATION
78 
79 #if (DBG)
80   #if !defined( DEBUG_LEVEL )
81     #if defined( DEBUG_VARIABLE )
82       #if defined( KSDEBUG_INIT )
83         ULONG DEBUG_VARIABLE = DEBUGLVL_TERSE;
84       #else
85         extern ULONG DEBUG_VARIABLE;
86       #endif
87     #else
88       #define DEBUG_VARIABLE DEBUGLVL_TERSE
89     #endif
90   #else
91     #if defined( DEBUG_VARIABLE )
92       #if defined( KSDEBUG_INIT )
93         ULONG DEBUG_VARIABLE = DEBUG_LEVEL;
94       #else
95         extern ULONG DEBUG_VARIABLE;
96       #endif
97     #else
98       #define DEBUG_VARIABLE DEBUG_LEVEL
99     #endif
100   #endif
101 
102 #if (NTDDI_VERSION >= NTDDI_WINXP)
103   #define _DbgPrintFEx(component, lvl, strings) { \
104     if ((lvl) <= DEBUG_VARIABLE) { \
105       DbgPrintEx(component, lvl, STR_MODULENAME); \
106       DbgPrintEx(component, lvl, strings); \
107       DbgPrintEx(component, lvl, "\n"); \
108       if ((lvl) == DEBUGLVL_ERROR) { \
109         DbgBreakPoint(); \
110       } \
111     } \
112   }
113 #endif /* (NTDDI_VERSION >= NTDDI_WINXP) */
114 
115   #define _DbgPrintF(lvl, strings) { \
116     if (((lvl)==DEBUG_VARIABLE) || (lvl < DEBUG_VARIABLE)) { \
117       DbgPrint(STR_MODULENAME); \
118       DbgPrint##strings; \
119       DbgPrint("\n"); \
120       if ((lvl) == DEBUGLVL_ERROR) { \
121         DbgBreakPoint(); \
122       } \
123     } \
124   }
125 
126 #else
127 
128 #define _DbgPrintF(lvl, strings)
129 
130 #if (NTDDI_VERSION >= NTDDI_WINXP)
131 #define _DbgPrintFEx(component, lvl, strings)
132 #endif
133 
134 #endif /* DBG */
135 
136 #endif /* defined(_NTDDK_) */
137 
138 #if defined(__cplusplus)
139 }
140 #endif
141 
142 #endif /* _KSDEBUG_ */
143