xref: /reactos/win32ss/user/ntuser/win32kdebug.h (revision 560428e2)
1 #pragma once
2 
3 /*
4     When a process is created, DbgInitDebugChannels will locate DEBUGCHANNEL
5     environment variable and extract information about debug channels.
6     This information includes which of the win32k debug channels will be
7     enabled for the current process and which level of a channel will be active.
8     This information will be stored in ppi->DbgChannelLevel.
9     In this way user mode can control how win32k debugging will work when
10     the following macros are used: ERR, FIXME, WARN, TRACE
11 
12     By default only the ERR channel will be active. Remember that other
13     debug channels can be activated for applications that are executed with a DEBUGCHANNEL
14 
15     Valid syntax for DEBUGCHANNEL is the following:
16     +UserProcess,info+UserWnd,err+UserWndpos,-listview
17     warn+UserMsgQ,-UserMsgGet,+shell
18 
19     Note the following:
20     The debug level is not required
21     The operation to enable/disable (+/-) and the name of the channel is required
22     Channels are devided by commas
23     No spaces are allowed
24     The syntax is case sensitive. Levels must be lowercase and
25     the names of the channels must be exactly like they are defined in DBG_DEFAULT_CHANNEL
26     This syntax can be mixed with wine debug channels without problems
27 
28 */
29 
30 #if DBG
31 
32     #if !defined(__RELFILE__)
33         #define __RELFILE__ __FILE__
34     #endif
35 
36     typedef struct
37     {
38         PWCHAR Name;
39         ULONG Id;
40     } DBG_CHANNEL;
41 
42     /* Note: The following values don't need to be sorted */
43     enum _DEBUGCHANNELS
44     {
45         DbgChEngBlt,
46         DbgChEngBrush,
47         DbgChEngClip,
48         DbgChEngCursor,
49         DbgChEngDev,
50         DbgChEngErr,
51         DbgChEngEvent,
52         DbgChEngGrad,
53         DbgChEngLDev,
54         DbgChEngLine,
55         DbgChEngMapping,
56         DbgChEngMDev,
57         DbgChEngPDev,
58         DbgChEngSurface,
59         DbgChEngWnd,
60         DbgChEngXlate,
61         DbgChGdiBitmap,
62         DbgChGdiBlt,
63         DbgChGdiBrush,
64         DbgChGdiClipRgn,
65         DbgChGdiCoord,
66         DbgChGdiDC,
67         DbgChGdiDCAttr,
68         DbgChGdiDCState,
69         DbgChGdiDev,
70         DbgChGdiDib,
71         DbgChGdiFont,
72         DbgChGdiLine,
73         DbgChGdiObj,
74         DbgChGdiPalette,
75         DbgChGdiPath,
76         DbgChGdiPen,
77         DbgChGdiPool,
78         DbgChGdiRgn,
79         DbgChGdiText,
80         DbgChGdiXFormObj,
81         DbgChUserAccel,
82         DbgChUserCallback,
83         DbgChUserCallProc,
84         DbgChUserCaret,
85         DbgChUserClass,
86         DbgChUserClipbrd,
87         DbgChUserCsr,
88         DbgChUserDce,
89         DbgChUserDefwnd,
90         DbgChUserDesktop,
91         DbgChUserDisplay,
92         DbgChUserEvent,
93         DbgChUserFocus,
94         DbgChUserHook,
95         DbgChUserHotkey,
96         DbgChUserIcon,
97         DbgChUserInput,
98         DbgChUserKbd,
99         DbgChUserKbdLayout,
100         DbgChUserMenu,
101         DbgChUserMetric,
102         DbgChUserMisc,
103         DbgChUserMonitor,
104         DbgChUserMsg,
105         DbgChUserMsgQ,
106         DbgChUserObj,
107         DbgChUserPainting,
108         DbgChUserProcess,
109         DbgChUserPowerManager,
110         DbgChUserProp,
111         DbgChUserScrollbar,
112         DbgChUserSecurity,
113         DbgChUserShutdown,
114         DbgChUserSysparams,
115         DbgChUserThread,
116         DbgChUserTimer,
117         DbgChUserWinsta,
118         DbgChUserWnd,
119         DbgChUserWinpos,
120         DbgChCount
121     };
122 
123     #define DISABLED_LEVEL 0x0
124     #define ERR_LEVEL      0x1
125     #define FIXME_LEVEL    0x2
126     #define WARN_LEVEL     0x4
127     #define TRACE_LEVEL    0x8
128 
129     #define MAX_LEVEL ERR_LEVEL | FIXME_LEVEL | WARN_LEVEL | TRACE_LEVEL
130 
131     #define DBG_GET_PPI ((PPROCESSINFO)PsGetCurrentProcessWin32Process())
132     #define DBG_DEFAULT_CHANNEL(x) static int DbgDefaultChannel = DbgCh##x;
133 
134     #define DBG_ENABLE_CHANNEL(ppi,ch,level) ((ppi)->DbgChannelLevel[ch] |= level)
135     #define DBG_DISABLE_CHANNEL(ppi,ch,level) ((ppi)->DbgChannelLevel[ch] &= ~level)
136     #define DBG_IS_CHANNEL_ENABLED(ppi,ch,level) (((ppi)->DbgChannelLevel[ch] & level) == level)
137 
138     #define DBG_PRINT(ppi,ch,level,fmt, ...)    \
139     do {    \
140     if ((level == ERR_LEVEL) || (ppi && DBG_IS_CHANNEL_ENABLED(ppi,ch,level)))  \
141         DbgPrint("(%s:%d) " fmt, __RELFILE__, __LINE__, ##__VA_ARGS__);         \
142     } while (0)
143 
144     #define ERR(fmt, ...)     DBG_PRINT(DBG_GET_PPI, DbgDefaultChannel, ERR_LEVEL,"err: " fmt, ##__VA_ARGS__)
145     #define FIXME(fmt, ...)   DBG_PRINT(DBG_GET_PPI, DbgDefaultChannel, FIXME_LEVEL,"fixme: " fmt, ##__VA_ARGS__)
146     #define WARN(fmt, ...)    DBG_PRINT(DBG_GET_PPI, DbgDefaultChannel, WARN_LEVEL,"warn: " fmt, ##__VA_ARGS__)
147     #define TRACE(fmt, ...)   DBG_PRINT(DBG_GET_PPI, DbgDefaultChannel, TRACE_LEVEL,"trace: " fmt, ##__VA_ARGS__)
148 
149     #define ERR_CH(ch,fmt, ...)        DBG_PRINT(DBG_GET_PPI, DbgCh##ch, ERR_LEVEL, "err: " fmt, ##__VA_ARGS__)
150     #define FIXME_CH(ch,fmt, ...)      DBG_PRINT(DBG_GET_PPI, DbgCh##ch, FIXME_LEVEL, "fixme: " fmt, ##__VA_ARGS__)
151     #define WARN_CH(ch,fmt, ...)       DBG_PRINT(DBG_GET_PPI, DbgCh##ch, WARN_LEVEL, "warn: " fmt, ##__VA_ARGS__)
152     #define TRACE_CH(ch,fmt, ...)      DBG_PRINT(DBG_GET_PPI, DbgCh##ch, TRACE_LEVEL, "trace: " fmt, ##__VA_ARGS__)
153 
154     #define ERR_PPI(ppi,ch,fmt, ...)   DBG_PRINT(ppi, DbgCh##ch, ERR_LEVEL,"err: " fmt, ##__VA_ARGS__)
155     #define FIXME_PPI(ppi,ch,fmt, ...) DBG_PRINT(ppi, DbgCh##ch, FIXME_LEVEL,"fixme: " fmt, ##__VA_ARGS__)
156     #define WARN_PPI(ppi,ch,fmt, ...)  DBG_PRINT(ppi, DbgCh##ch, WARN_LEVEL,"warn: " fmt, ##__VA_ARGS__)
157     #define TRACE_PPI(ppi,ch,fmt, ...) DBG_PRINT(ppi, DbgCh##ch, TRACE_LEVEL,"trace: " fmt, ##__VA_ARGS__)
158 
159     #define STUB         DbgPrint("WARNING:  %s at %s:%d is UNIMPLEMENTED!\n",__FUNCTION__,__RELFILE__,__LINE__);
160 
161 #else
162     #define DBG_GET_PPI
163     #define DBG_DEFAULT_CHANNEL(x)
164 
165     #define DBG_ENABLE_CHANNEL(ppi,ch,level)
166     #define DBG_DISABLE_CHANNEL(ppi,ch,level)
167     #define DBG_IS_CHANNEL_ENABLED(ppi,ch,level)
168 
169     #define DBG_PRINT(ppi,ch,level)
170 
171     #define ERR(fmt, ...)
172     #define FIXME(fmt, ...)
173     #define WARN(fmt, ...)
174     #define TRACE(fmt, ...)
175 
176     #define ERR_CH(ch,fmt, ...)
177     #define FIXME_CH(ch,fmt, ...)
178     #define WARN_CH(ch,fmt, ...)
179     #define TRACE_CH(ch,fmt, ...)
180 
181     #define ERR_PPI(ppi,ch,fmt, ...)
182     #define FIXME_PPI(ppi,ch,fmt, ...)
183     #define WARN_PPI(ppi,ch,fmt, ...)
184     #define TRACE_PPI(ppi,ch,fmt, ...)
185 
186     #define STUB
187 
188 #endif
189 
190 BOOL DbgInitDebugChannels();
191