Remove the unused 1st parameter of ACTION_VerifyComponentForAction.
[wine] / include / wine / debug.h
1 /*
2  * Wine debugging interface
3  *
4  * Copyright 1999 Patrik Stridvall
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #ifndef __WINE_WINE_DEBUG_H
22 #define __WINE_WINE_DEBUG_H
23
24 #include <stdarg.h>
25 #include <windef.h>
26 #ifndef GUID_DEFINED
27 #include <guiddef.h>
28 #endif
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 struct _GUID;
35
36 /*
37  * Internal definitions (do not use these directly)
38  */
39
40 enum __wine_debug_class
41 {
42     __WINE_DBCL_FIXME,
43     __WINE_DBCL_ERR,
44     __WINE_DBCL_WARN,
45     __WINE_DBCL_TRACE,
46
47     __WINE_DBCL_INIT = 7  /* lazy init flag */
48 };
49
50 struct __wine_debug_channel
51 {
52     unsigned char flags;
53     char name[15];
54 };
55
56 #ifndef WINE_NO_TRACE_MSGS
57 # define __WINE_GET_DEBUGGING_TRACE(dbch) ((dbch)->flags & (1 << __WINE_DBCL_TRACE))
58 #else
59 # define __WINE_GET_DEBUGGING_TRACE(dbch) 0
60 #endif
61
62 #ifndef WINE_NO_DEBUG_MSGS
63 # define __WINE_GET_DEBUGGING_WARN(dbch)  ((dbch)->flags & (1 << __WINE_DBCL_WARN))
64 # define __WINE_GET_DEBUGGING_FIXME(dbch) ((dbch)->flags & (1 << __WINE_DBCL_FIXME))
65 #else
66 # define __WINE_GET_DEBUGGING_WARN(dbch)  0
67 # define __WINE_GET_DEBUGGING_FIXME(dbch) 0
68 #endif
69
70 /* define error macro regardless of what is configured */
71 #define __WINE_GET_DEBUGGING_ERR(dbch)  ((dbch)->flags & (1 << __WINE_DBCL_ERR))
72
73 #define __WINE_GET_DEBUGGING(dbcl,dbch)  __WINE_GET_DEBUGGING##dbcl(dbch)
74
75 #define __WINE_IS_DEBUG_ON(dbcl,dbch) \
76   (__WINE_GET_DEBUGGING##dbcl(dbch) && (__wine_dbg_get_channel_flags(dbch) & (1 << __WINE_DBCL##dbcl)))
77
78 #ifdef __GNUC__
79
80 #define __WINE_DPRINTF(dbcl,dbch) \
81   do { if(__WINE_GET_DEBUGGING(dbcl,(dbch))) { \
82        struct __wine_debug_channel * const __dbch = (dbch); \
83        const enum __wine_debug_class __dbcl = __WINE_DBCL##dbcl; \
84        __WINE_DBG_LOG
85
86 #define __WINE_DBG_LOG(args...) \
87     wine_dbg_log( __dbcl, __dbch, __FUNCTION__, args); } } while(0)
88
89 #define __WINE_PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
90
91
92 #ifdef WINE_NO_TRACE_MSGS
93 #define WINE_TRACE(args...) do { } while(0)
94 #define WINE_TRACE_(ch) WINE_TRACE
95 #endif
96
97 #ifdef WINE_NO_DEBUG_MSGS
98 #define WINE_WARN(args...) do { } while(0)
99 #define WINE_WARN_(ch) WINE_WARN
100 #define WINE_FIXME(args...) do { } while(0)
101 #define WINE_FIXME_(ch) WINE_FIXME
102 #endif
103
104 #elif defined(__SUNPRO_C)
105
106 #define __WINE_DPRINTF(dbcl,dbch) \
107   do { if(__WINE_GET_DEBUGGING(dbcl,(dbch))) { \
108        struct __wine_debug_channel * const __dbch = (dbch); \
109        const enum __WINE_DEBUG_CLASS __dbcl = __WINE_DBCL##dbcl; \
110        __WINE_DBG_LOG
111
112 #define __WINE_DBG_LOG(...) \
113    wine_dbg_log( __dbcl, __dbch, __func__, __VA_ARGS__); } } while(0)
114
115 #define __WINE_PRINTF_ATTR(fmt,args)
116
117 #ifdef WINE_NO_TRACE_MSGS
118 #define WINE_TRACE(...) do { } while(0)
119 #define WINE_TRACE_(ch) WINE_TRACE
120 #endif
121
122 #ifdef WINE_NO_DEBUG_MSGS
123 #define WINE_WARN(...) do { } while(0)
124 #define WINE_WARN_(ch) WINE_WARN
125 #define WINE_FIXME(...) do { } while(0)
126 #define WINE_FIXME_(ch) WINE_FIXME
127 #endif
128
129 #else  /* !__GNUC__ && !__SUNPRO_C */
130
131 #define __WINE_DPRINTF(dbcl,dbch) \
132     (!__WINE_GET_DEBUGGING(dbcl,(dbch)) || \
133      (wine_dbg_log(__WINE_DBCL##dbcl,(dbch),__FILE__,"%d: ",__LINE__) == -1)) ? \
134      (void)0 : (void)wine_dbg_printf
135
136 #define __WINE_PRINTF_ATTR(fmt, args)
137
138 #endif  /* !__GNUC__ && !__SUNPRO_C */
139
140 struct __wine_debug_functions
141 {
142     char * (*get_temp_buffer)( size_t n );
143     void   (*release_temp_buffer)( char *buffer, size_t n );
144     const char * (*dbgstr_an)( const char * s, int n );
145     const char * (*dbgstr_wn)( const WCHAR *s, int n );
146     int (*dbg_vprintf)( const char *format, va_list args );
147     int (*dbg_vlog)( enum __wine_debug_class cls, struct __wine_debug_channel *channel,
148                      const char *function, const char *format, va_list args );
149 };
150
151 extern unsigned char __wine_dbg_get_channel_flags( struct __wine_debug_channel *channel );
152 extern int __wine_dbg_set_channel_flags( struct __wine_debug_channel *channel,
153                                          unsigned char set, unsigned char clear );
154 extern void __wine_dbg_set_functions( const struct __wine_debug_functions *new_funcs,
155                                       struct __wine_debug_functions *old_funcs, size_t size );
156
157 /*
158  * Exported definitions and macros
159  */
160
161 /* These function return a printable version of a string, including
162    quotes.  The string will be valid for some time, but not indefinitely
163    as strings are re-used.  */
164 extern const char *wine_dbgstr_an( const char * s, int n );
165 extern const char *wine_dbgstr_wn( const WCHAR *s, int n );
166 extern const char *wine_dbg_sprintf( const char *format, ... ) __WINE_PRINTF_ATTR(1,2);
167
168 extern int wine_dbg_printf( const char *format, ... ) __WINE_PRINTF_ATTR(1,2);
169 extern int wine_dbg_log( enum __wine_debug_class cls, struct __wine_debug_channel *ch, const char *func,
170                          const char *format, ... ) __WINE_PRINTF_ATTR(4,5);
171
172 static inline const char *wine_dbgstr_a( const char *s )
173 {
174     return wine_dbgstr_an( s, -1 );
175 }
176
177 static inline const char *wine_dbgstr_w( const WCHAR *s )
178 {
179     return wine_dbgstr_wn( s, -1 );
180 }
181
182 static inline const char *wine_dbgstr_guid( const GUID *id )
183 {
184     if (!id) return "(null)";
185     if (!((INT_PTR)id >> 16)) return wine_dbg_sprintf( "<guid-0x%04x>", (INT_PTR)id & 0xffff );
186     return wine_dbg_sprintf( "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
187                              id->Data1, id->Data2, id->Data3,
188                              id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
189                              id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
190 }
191
192 static inline const char *wine_dbgstr_point( const POINT *pt )
193 {
194     if (!pt) return "(null)";
195     return wine_dbg_sprintf( "(%ld,%ld)", pt->x, pt->y );
196 }
197
198 static inline const char *wine_dbgstr_size( const SIZE *size )
199 {
200     if (!size) return "(null)";
201     return wine_dbg_sprintf( "(%ld,%ld)", size->cx, size->cy );
202 }
203
204 static inline const char *wine_dbgstr_rect( const RECT *rect )
205 {
206     if (!rect) return "(null)";
207     return wine_dbg_sprintf( "(%ld,%ld)-(%ld,%ld)", rect->left, rect->top, rect->right, rect->bottom );
208 }
209
210 static inline const char *wine_dbgstr_longlong( ULONGLONG ll )
211 {
212     if (sizeof(ll) > sizeof(unsigned long) && ll >> 32)
213         return wine_dbg_sprintf( "%lx%08lx", (unsigned long)(ll >> 32), (unsigned long)ll );
214     else return wine_dbg_sprintf( "%lx", (unsigned long)ll );
215 }
216
217 #ifndef WINE_TRACE
218 #define WINE_TRACE                 __WINE_DPRINTF(_TRACE,__wine_dbch___default)
219 #define WINE_TRACE_(ch)            __WINE_DPRINTF(_TRACE,&__wine_dbch_##ch)
220 #endif
221 #define WINE_TRACE_ON(ch)          __WINE_IS_DEBUG_ON(_TRACE,&__wine_dbch_##ch)
222
223 #ifndef WINE_WARN
224 #define WINE_WARN                  __WINE_DPRINTF(_WARN,__wine_dbch___default)
225 #define WINE_WARN_(ch)             __WINE_DPRINTF(_WARN,&__wine_dbch_##ch)
226 #endif
227 #define WINE_WARN_ON(ch)           __WINE_IS_DEBUG_ON(_WARN,&__wine_dbch_##ch)
228
229 #ifndef WINE_FIXME
230 #define WINE_FIXME                 __WINE_DPRINTF(_FIXME,__wine_dbch___default)
231 #define WINE_FIXME_(ch)            __WINE_DPRINTF(_FIXME,&__wine_dbch_##ch)
232 #endif
233 #define WINE_FIXME_ON(ch)          __WINE_IS_DEBUG_ON(_FIXME,&__wine_dbch_##ch)
234
235 #define WINE_ERR                   __WINE_DPRINTF(_ERR,__wine_dbch___default)
236 #define WINE_ERR_(ch)              __WINE_DPRINTF(_ERR,&__wine_dbch_##ch)
237 #define WINE_ERR_ON(ch)            __WINE_IS_DEBUG_ON(_ERR,&__wine_dbch_##ch)
238
239 #define WINE_DECLARE_DEBUG_CHANNEL(ch) \
240     static struct __wine_debug_channel __wine_dbch_##ch = { ~0, #ch }
241 #define WINE_DEFAULT_DEBUG_CHANNEL(ch) \
242     static struct __wine_debug_channel __wine_dbch_##ch = { ~0, #ch }; \
243     static struct __wine_debug_channel * const __wine_dbch___default = &__wine_dbch_##ch
244
245 #define WINE_DPRINTF               wine_dbg_printf
246 #define WINE_MESSAGE               wine_dbg_printf
247
248 #ifdef __WINESRC__
249 /* Wine uses shorter names that are very likely to conflict with other software */
250
251 inline static const char *debugstr_an( const char * s, int n ) { return wine_dbgstr_an( s, n ); }
252 inline static const char *debugstr_wn( const WCHAR *s, int n ) { return wine_dbgstr_wn( s, n ); }
253 inline static const char *debugstr_guid( const struct _GUID *id ) { return wine_dbgstr_guid(id); }
254 inline static const char *debugstr_a( const char *s )  { return wine_dbgstr_an( s, -1 ); }
255 inline static const char *debugstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, -1 ); }
256
257 #define TRACE                      WINE_TRACE
258 #define TRACE_(ch)                 WINE_TRACE_(ch)
259 #define TRACE_ON(ch)               WINE_TRACE_ON(ch)
260
261 #define WARN                       WINE_WARN
262 #define WARN_(ch)                  WINE_WARN_(ch)
263 #define WARN_ON(ch)                WINE_WARN_ON(ch)
264
265 #define FIXME                      WINE_FIXME
266 #define FIXME_(ch)                 WINE_FIXME_(ch)
267 #define FIXME_ON(ch)               WINE_FIXME_ON(ch)
268
269 #undef ERR  /* Solaris got an 'ERR' define in <sys/reg.h> */
270 #define ERR                        WINE_ERR
271 #define ERR_(ch)                   WINE_ERR_(ch)
272 #define ERR_ON(ch)                 WINE_ERR_ON(ch)
273
274 #define DPRINTF                    WINE_DPRINTF
275 #define MESSAGE                    WINE_MESSAGE
276
277 #endif /* __WINESRC__ */
278
279 #ifdef __cplusplus
280 }
281 #endif
282
283 #endif  /* __WINE_WINE_DEBUG_H */