35aefc9852b49385b46c3b6e7e47ae1a148254e5
[reactos.git] / sdk / include / reactos / 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #ifndef __WINE_DEBUG_H
22 #define __WINE_DEBUG_H
23
24 #include <stdarg.h>
25 #include <windef.h>
26 #ifndef GUID_DEFINED
27 #include <guiddef.h>
28 #endif
29
30 #ifndef __RELFILE__
31 #define __RELFILE__ __FILE__
32 #endif
33
34 #ifdef __WINE_WINE_TEST_H
35 #error This file should not be used in Wine tests
36 #endif
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 struct _GUID;
43
44 /*
45 * Internal definitions (do not use these directly)
46 */
47
48 enum __wine_debug_class
49 {
50 __WINE_DBCL_FIXME = 0, /* 0x1 */
51 __WINE_DBCL_ERR = 1, /* 0x2 */
52 __WINE_DBCL_WARN = 2, /* 0x4 */
53 __WINE_DBCL_TRACE = 3, /* 0x8 */
54
55 /* lazy init flag */
56 __WINE_DBCL_INIT = 0x7
57 };
58
59 struct __wine_debug_channel
60 {
61 unsigned char flags;
62 char name[15];
63 };
64
65 #define UNIMPLEMENTED WINE_FIXME("%s is UNIMPLEMENTED!\n", __FUNCTION__)
66
67 #ifndef WINE_NO_TRACE_MSGS
68 # define __WINE_GET_DEBUGGING_TRACE(dbch) ((dbch)->flags & (1 << __WINE_DBCL_TRACE))
69 #else
70 # define __WINE_GET_DEBUGGING_TRACE(dbch) 0
71 #endif
72
73 #ifndef WINE_NO_DEBUG_MSGS
74 # define __WINE_GET_DEBUGGING_WARN(dbch) ((dbch)->flags & (1 << __WINE_DBCL_WARN))
75 # define __WINE_GET_DEBUGGING_FIXME(dbch) ((dbch)->flags & (1 << __WINE_DBCL_FIXME))
76 #else
77 # define __WINE_GET_DEBUGGING_WARN(dbch) 0
78 # define __WINE_GET_DEBUGGING_FIXME(dbch) 0
79 #endif
80
81 /* define error macro regardless of what is configured */
82 #define __WINE_GET_DEBUGGING_ERR(dbch) ((dbch)->flags & (1 << __WINE_DBCL_ERR))
83
84 #define __WINE_GET_DEBUGGING(dbcl,dbch) __WINE_GET_DEBUGGING##dbcl(dbch)
85
86 #define __WINE_IS_DEBUG_ON(dbcl,dbch) \
87 (__WINE_GET_DEBUGGING##dbcl(dbch) && (__wine_dbg_get_channel_flags(dbch) & (1 << __WINE_DBCL##dbcl)))
88
89 #ifdef __GNUC__
90
91 #define __WINE_DPRINTF(dbcl,dbch) \
92 do { if(__WINE_GET_DEBUGGING(dbcl,(dbch))) { \
93 struct __wine_debug_channel * const __dbch = (dbch); \
94 const enum __wine_debug_class __dbcl = __WINE_DBCL##dbcl; \
95 __WINE_DBG_LOG
96
97 #define __WINE_DBG_LOG(args...) \
98 ros_dbg_log( __dbcl, __dbch, __RELFILE__, __FUNCTION__, __LINE__, args); } } while(0)
99
100 #define __WINE_PRINTF_ATTR(fmt,args) /*__attribute__((format (printf,fmt,args)))*/
101
102
103 #ifdef WINE_NO_TRACE_MSGS
104 #define WINE_TRACE(args...) do { } while(0)
105 #define WINE_TRACE_(ch) WINE_TRACE
106 #endif
107
108 #ifdef WINE_NO_DEBUG_MSGS
109 #define WINE_WARN(args...) do { } while(0)
110 #define WINE_WARN_(ch) WINE_WARN
111 #define WINE_FIXME(args...) do { } while(0)
112 #define WINE_FIXME_(ch) WINE_FIXME
113 #endif
114
115 #elif defined(__SUNPRO_C)
116
117 #define __WINE_DPRINTF(dbcl,dbch) \
118 do { if(__WINE_GET_DEBUGGING(dbcl,(dbch))) { \
119 struct __wine_debug_channel * const __dbch = (dbch); \
120 const enum __WINE_DEBUG_CLASS __dbcl = __WINE_DBCL##dbcl; \
121 __WINE_DBG_LOG
122
123 #define __WINE_DBG_LOG(...) \
124 wine_dbg_log( __dbcl, __dbch, __func__, __VA_ARGS__); } } while(0)
125
126 #define __WINE_PRINTF_ATTR(fmt,args)
127
128 #ifdef WINE_NO_TRACE_MSGS
129 #define WINE_TRACE(...) do { } while(0)
130 #define WINE_TRACE_(ch) WINE_TRACE
131 #endif
132
133 #ifdef WINE_NO_DEBUG_MSGS
134 #define WINE_WARN(...) do { } while(0)
135 #define WINE_WARN_(ch) WINE_WARN
136 #define WINE_FIXME(...) do { } while(0)
137 #define WINE_FIXME_(ch) WINE_FIXME
138 #endif
139
140 #else /* !__GNUC__ && !__SUNPRO_C */
141
142 #define __WINE_DPRINTF(dbcl,dbch) \
143 (!__WINE_GET_DEBUGGING(dbcl,(dbch)) || \
144 (ros_dbg_log(__WINE_DBCL##dbcl,(dbch),__RELFILE__,__FUNCTION__,__LINE__,"") == -1)) ? \
145 (void)0 : (void)wine_dbg_printf
146
147 #define __WINE_PRINTF_ATTR(fmt, args)
148
149 #endif /* !__GNUC__ && !__SUNPRO_C */
150
151 struct __wine_debug_functions
152 {
153 char * (*get_temp_buffer)( size_t n );
154 void (*release_temp_buffer)( char *buffer, size_t n );
155 const char * (*dbgstr_an)( const char * s, int n );
156 const char * (*dbgstr_wn)( const WCHAR *s, int n );
157 int (*dbg_vprintf)( const char *format, va_list args );
158 int (*dbg_vlog)( enum __wine_debug_class cls, struct __wine_debug_channel *channel,
159 const char *file, const char *function, const int line, const char *format, va_list args );
160 };
161
162 extern unsigned char __wine_dbg_get_channel_flags( struct __wine_debug_channel *channel );
163 extern int __wine_dbg_set_channel_flags( struct __wine_debug_channel *channel,
164 unsigned char set, unsigned char clear );
165 extern void __wine_dbg_set_functions( const struct __wine_debug_functions *new_funcs,
166 struct __wine_debug_functions *old_funcs, size_t size );
167
168 /*
169 * Exported definitions and macros
170 */
171
172 /* These functions return a printable version of a string, including
173 quotes. The string will be valid for some time, but not indefinitely
174 as strings are re-used. */
175 extern const char *wine_dbgstr_an( const char * s, int n );
176 extern const char *wine_dbgstr_wn( const WCHAR *s, int n );
177 extern const char *wine_dbg_sprintf( const char *format, ... ) __WINE_PRINTF_ATTR(1,2);
178
179 extern int wine_dbg_printf( const char *format, ... ) __WINE_PRINTF_ATTR(1,2);
180 extern int wine_dbg_log( enum __wine_debug_class cls, struct __wine_debug_channel *ch, const char *func,
181 const char *format, ... ) __WINE_PRINTF_ATTR(4,5);
182 /* ReactOS compliant debug format */
183 extern int ros_dbg_log( enum __wine_debug_class cls, struct __wine_debug_channel *ch, const char *file,
184 const char *func, const int line, const char *format, ... ) __WINE_PRINTF_ATTR(6,7);
185
186 static __inline const char *wine_dbgstr_a( const char *s )
187 {
188 return wine_dbgstr_an( s, -1 );
189 }
190
191 static __inline const char *wine_dbgstr_w( const WCHAR *s )
192 {
193 return wine_dbgstr_wn( s, -1 );
194 }
195
196 static __inline const char *wine_dbgstr_guid( const GUID *id )
197 {
198 if (!id) return "(null)";
199 if (!((ULONG_PTR)id >> 16)) return wine_dbg_sprintf( "<guid-0x%04lx>", (ULONG_PTR)id & 0xffff );
200 return wine_dbg_sprintf( "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
201 id->Data1, id->Data2, id->Data3,
202 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
203 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
204 }
205
206 static __inline const char *wine_dbgstr_point( const POINT *pt )
207 {
208 if (!pt) return "(null)";
209 return wine_dbg_sprintf( "(%ld,%ld)", pt->x, pt->y );
210 }
211
212 static __inline const char *wine_dbgstr_size( const SIZE *size )
213 {
214 if (!size) return "(null)";
215 return wine_dbg_sprintf( "(%ld,%ld)", size->cx, size->cy );
216 }
217
218 static __inline const char *wine_dbgstr_rect( const RECT *rect )
219 {
220 if (!rect) return "(null)";
221 return wine_dbg_sprintf( "(%ld,%ld)-(%ld,%ld)", rect->left, rect->top,
222 rect->right, rect->bottom );
223 }
224
225 static __inline const char *wine_dbgstr_longlong( ULONGLONG ll )
226 {
227 if (/*sizeof(ll) > sizeof(unsigned long) &&*/ ll >> 32) /* ULONGLONG is always > long in ReactOS */
228 return wine_dbg_sprintf( "%lx%08lx", (unsigned long)(ll >> 32), (unsigned long)ll );
229 else return wine_dbg_sprintf( "%lx", (unsigned long)ll );
230 }
231
232 #if defined(__oaidl_h__) && defined(V_VT)
233
234 static inline const char *wine_dbgstr_vt( VARTYPE vt )
235 {
236 static const char *const variant_types[] =
237 {
238 "VT_EMPTY","VT_NULL","VT_I2","VT_I4","VT_R4","VT_R8","VT_CY","VT_DATE",
239 "VT_BSTR","VT_DISPATCH","VT_ERROR","VT_BOOL","VT_VARIANT","VT_UNKNOWN",
240 "VT_DECIMAL","15","VT_I1","VT_UI1","VT_UI2","VT_UI4","VT_I8","VT_UI8",
241 "VT_INT","VT_UINT","VT_VOID","VT_HRESULT","VT_PTR","VT_SAFEARRAY",
242 "VT_CARRAY","VT_USERDEFINED","VT_LPSTR","VT_LPWSTR","32","33","34","35",
243 "VT_RECORD","VT_INT_PTR","VT_UINT_PTR","39","40","41","42","43","44","45",
244 "46","47","48","49","50","51","52","53","54","55","56","57","58","59","60",
245 "61","62","63","VT_FILETIME","VT_BLOB","VT_STREAM","VT_STORAGE",
246 "VT_STREAMED_OBJECT","VT_STORED_OBJECT","VT_BLOB_OBJECT","VT_CF","VT_CLSID",
247 "VT_VERSIONED_STREAM"
248 };
249
250 static const char *const variant_flags[16] =
251 {
252 "",
253 "|VT_VECTOR",
254 "|VT_ARRAY",
255 "|VT_VECTOR|VT_ARRAY",
256 "|VT_BYREF",
257 "|VT_VECTOR|VT_BYREF",
258 "|VT_ARRAY|VT_BYREF",
259 "|VT_VECTOR|VT_ARRAY|VT_BYREF",
260 "|VT_RESERVED",
261 "|VT_VECTOR|VT_RESERVED",
262 "|VT_ARRAY|VT_RESERVED",
263 "|VT_VECTOR|VT_ARRAY|VT_RESERVED",
264 "|VT_BYREF|VT_RESERVED",
265 "|VT_VECTOR|VT_BYREF|VT_RESERVED",
266 "|VT_ARRAY|VT_BYREF|VT_RESERVED",
267 "|VT_VECTOR|VT_ARRAY|VT_BYREF|VT_RESERVED",
268 };
269
270 if (vt & ~VT_TYPEMASK)
271 return wine_dbg_sprintf( "%s%s", wine_dbgstr_vt(vt&VT_TYPEMASK), variant_flags[vt>>12] );
272
273 if (vt < sizeof(variant_types)/sizeof(*variant_types))
274 return variant_types[vt];
275
276 if (vt == VT_BSTR_BLOB)
277 return "VT_BSTR_BLOB";
278
279 return wine_dbg_sprintf( "vt(invalid %x)", vt );
280 }
281
282 static inline const char *wine_dbgstr_variant( const VARIANT *v )
283 {
284 if (!v)
285 return "(null)";
286
287 if (V_VT(v) & VT_BYREF) {
288 if (V_VT(v) == (VT_VARIANT|VT_BYREF))
289 return wine_dbg_sprintf( "%p {VT_VARIANT|VT_BYREF: %s}", v, wine_dbgstr_variant(V_VARIANTREF(v)) );
290 if (V_VT(v) == (VT_BSTR|VT_BYREF))
291 return wine_dbg_sprintf( "%p {VT_BSTR|VT_BYREF: %s}", v, V_BSTRREF(v) ? wine_dbgstr_w(*V_BSTRREF(v)) : "(none)" );
292 return wine_dbg_sprintf( "%p {%s %p}", v, wine_dbgstr_vt(V_VT(v)), V_BYREF(v) );
293 }
294
295 if (V_ISARRAY(v) || V_ISVECTOR(v))
296 return wine_dbg_sprintf( "%p {%s %p}", v, wine_dbgstr_vt(V_VT(v)), V_ARRAY(v) );
297
298 switch(V_VT(v)) {
299 case VT_EMPTY:
300 return wine_dbg_sprintf( "%p {VT_EMPTY}", v );
301 case VT_NULL:
302 return wine_dbg_sprintf( "%p {VT_NULL}", v );
303 case VT_I2:
304 return wine_dbg_sprintf( "%p {VT_I2: %d}", v, V_I2(v) );
305 case VT_I4:
306 return wine_dbg_sprintf( "%p {VT_I4: %d}", v, V_I4(v) );
307 case VT_R4:
308 return wine_dbg_sprintf( "%p {VT_R4: %f}", v, V_R4(v) );
309 case VT_R8:
310 return wine_dbg_sprintf( "%p {VT_R8: %lf}", v, V_R8(v) );
311 case VT_CY:
312 return wine_dbg_sprintf( "%p {VT_CY: %s}", v, wine_dbgstr_longlong(V_CY(v).int64) );
313 case VT_DATE:
314 return wine_dbg_sprintf( "%p {VT_DATE: %lf}", v, V_DATE(v) );
315 case VT_BSTR:
316 return wine_dbg_sprintf( "%p {VT_BSTR: %s}", v, wine_dbgstr_w(V_BSTR(v)) );
317 case VT_DISPATCH:
318 return wine_dbg_sprintf( "%p {VT_DISPATCH: %p}", v, V_DISPATCH(v) );
319 case VT_ERROR:
320 return wine_dbg_sprintf( "%p {VT_ERROR: %08x}", v, V_ERROR(v) );
321 case VT_BOOL:
322 return wine_dbg_sprintf( "%p {VT_BOOL: %x}", v, V_BOOL(v) );
323 case VT_UNKNOWN:
324 return wine_dbg_sprintf( "%p {VT_UNKNOWN: %p}", v, V_UNKNOWN(v) );
325 case VT_I1:
326 return wine_dbg_sprintf( "%p {VT_I1: %d}", v, V_I1(v) );
327 case VT_UI1:
328 return wine_dbg_sprintf( "%p {VT_UI1: %u}", v, V_UI1(v) );
329 case VT_UI2:
330 return wine_dbg_sprintf( "%p {VT_UI2: %d}", v, V_UI2(v) );
331 case VT_UI4:
332 return wine_dbg_sprintf( "%p {VT_UI4: %d}", v, V_UI4(v) );
333 case VT_I8:
334 return wine_dbg_sprintf( "%p {VT_I8: %s}", v, wine_dbgstr_longlong(V_I8(v)) );
335 case VT_UI8:
336 return wine_dbg_sprintf( "%p {VT_UI8: %s}", v, wine_dbgstr_longlong(V_UI8(v)) );
337 case VT_INT:
338 return wine_dbg_sprintf( "%p {VT_INT: %d}", v, V_INT(v) );
339 case VT_UINT:
340 return wine_dbg_sprintf( "%p {VT_UINT: %u}", v, V_UINT(v) );
341 case VT_VOID:
342 return wine_dbg_sprintf( "%p {VT_VOID}", v );
343 case VT_RECORD:
344 return wine_dbg_sprintf( "%p {VT_RECORD: %p %p}", v, V_RECORD(v), V_RECORDINFO(v) );
345 default:
346 return wine_dbg_sprintf( "%p {vt %s}", v, wine_dbgstr_vt(V_VT(v)) );
347 }
348 }
349
350 #endif /* defined(__oaidl_h__) && defined(V_VT) */
351
352 #ifndef WINE_TRACE
353 #define WINE_TRACE __WINE_DPRINTF(_TRACE,__wine_dbch___default)
354 #define WINE_TRACE_(ch) __WINE_DPRINTF(_TRACE,&__wine_dbch_##ch)
355 #endif
356 #define WINE_TRACE_ON(ch) __WINE_IS_DEBUG_ON(_TRACE,&__wine_dbch_##ch)
357
358 #ifndef WINE_WARN
359 #define WINE_WARN __WINE_DPRINTF(_WARN,__wine_dbch___default)
360 #define WINE_WARN_(ch) __WINE_DPRINTF(_WARN,&__wine_dbch_##ch)
361 #endif
362 #define WINE_WARN_ON(ch) __WINE_IS_DEBUG_ON(_WARN,&__wine_dbch_##ch)
363
364 #ifndef WINE_FIXME
365 #define WINE_FIXME __WINE_DPRINTF(_FIXME,__wine_dbch___default)
366 #define WINE_FIXME_(ch) __WINE_DPRINTF(_FIXME,&__wine_dbch_##ch)
367 #endif
368 #define WINE_FIXME_ON(ch) __WINE_IS_DEBUG_ON(_FIXME,&__wine_dbch_##ch)
369
370 #define WINE_ERR __WINE_DPRINTF(_ERR,__wine_dbch___default)
371 #define WINE_ERR_(ch) __WINE_DPRINTF(_ERR,&__wine_dbch_##ch)
372 #define WINE_ERR_ON(ch) __WINE_IS_DEBUG_ON(_ERR,&__wine_dbch_##ch)
373
374 #define WINE_DECLARE_DEBUG_CHANNEL(ch) \
375 static struct __wine_debug_channel __wine_dbch_##ch = { (unsigned char)~0, #ch }
376 #define WINE_DEFAULT_DEBUG_CHANNEL(ch) \
377 static struct __wine_debug_channel __wine_dbch_##ch = { (unsigned char)~0, #ch }; \
378 static struct __wine_debug_channel * const __wine_dbch___default = &__wine_dbch_##ch
379
380 #define WINE_DPRINTF wine_dbg_printf
381 #define WINE_MESSAGE wine_dbg_printf
382
383 /* Wine uses shorter names that are very likely to conflict with other software */
384
385 static __inline const char *debugstr_an( const char * s, int n ) { return wine_dbgstr_an( s, n ); }
386 static __inline const char *debugstr_wn( const WCHAR *s, int n ) { return wine_dbgstr_wn( s, n ); }
387 static __inline const char *debugstr_guid( const struct _GUID *id ) { return wine_dbgstr_guid(id); }
388 static __inline const char *debugstr_a( const char *s ) { return wine_dbgstr_an( s, -1 ); }
389 static __inline const char *debugstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, -1 ); }
390
391 #if defined(__oaidl_h__) && defined(V_VT)
392 static __inline const char *debugstr_vt( VARTYPE vt ) { return wine_dbgstr_vt( vt ); }
393 static __inline const char *debugstr_variant( const VARIANT *v ) { return wine_dbgstr_variant( v ); }
394 #endif
395
396 #define TRACE WINE_TRACE
397 #define TRACE_(ch) WINE_TRACE_(ch)
398 #define TRACE_ON(ch) WINE_TRACE_ON(ch)
399
400 #define WARN WINE_WARN
401 #define WARN_(ch) WINE_WARN_(ch)
402 #define WARN_ON(ch) WINE_WARN_ON(ch)
403
404 #define FIXME WINE_FIXME
405 #define FIXME_(ch) WINE_FIXME_(ch)
406 #define FIXME_ON(ch) WINE_FIXME_ON(ch)
407
408 #undef ERR /* Solaris got an 'ERR' define in <sys/reg.h> */
409 #define ERR WINE_ERR
410 #define ERR_(ch) WINE_ERR_(ch)
411 #define ERR_ON(ch) WINE_ERR_ON(ch)
412
413 #define DPRINTF WINE_DPRINTF
414 #define MESSAGE WINE_MESSAGE
415
416 #ifdef __cplusplus
417 }
418 #endif
419
420 #endif /* __WINE_DEBUG_H */