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