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
22 #pragma makedep install
25 #ifndef __WINE_WINE_DEBUG_H
26 #define __WINE_WINE_DEBUG_H
43 * Internal definitions (do not use these directly)
46 enum __wine_debug_class
53 __WINE_DBCL_INIT
= 7 /* lazy init flag */
56 struct __wine_debug_channel
62 #ifndef WINE_NO_TRACE_MSGS
63 # define __WINE_GET_DEBUGGING_TRACE(dbch) ((dbch)->flags & (1 << __WINE_DBCL_TRACE))
65 # define __WINE_GET_DEBUGGING_TRACE(dbch) 0
68 #ifndef WINE_NO_DEBUG_MSGS
69 # define __WINE_GET_DEBUGGING_WARN(dbch) ((dbch)->flags & (1 << __WINE_DBCL_WARN))
70 # define __WINE_GET_DEBUGGING_FIXME(dbch) ((dbch)->flags & (1 << __WINE_DBCL_FIXME))
72 # define __WINE_GET_DEBUGGING_WARN(dbch) 0
73 # define __WINE_GET_DEBUGGING_FIXME(dbch) 0
76 /* define error macro regardless of what is configured */
77 #define __WINE_GET_DEBUGGING_ERR(dbch) ((dbch)->flags & (1 << __WINE_DBCL_ERR))
79 #define __WINE_GET_DEBUGGING(dbcl,dbch) __WINE_GET_DEBUGGING##dbcl(dbch)
81 #define __WINE_IS_DEBUG_ON(dbcl,dbch) \
82 (__WINE_GET_DEBUGGING##dbcl(dbch) && (__wine_dbg_get_channel_flags(dbch) & (1 << __WINE_DBCL##dbcl)))
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; \
90 #define __WINE_DBG_LOG(...) \
91 wine_dbg_log( __dbcl, __dbch, __func__, __VA_ARGS__); } } while(0)
93 #if defined(__MINGW32__) || (!defined(__WINE_USE_MSVCRT) && (defined(__GNUC__) || defined(__clang__)))
94 #define __WINE_PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
96 #define __WINE_PRINTF_ATTR(fmt,args)
99 #ifdef WINE_NO_TRACE_MSGS
100 #define WINE_TRACE(...) do { } while(0)
101 #define WINE_TRACE_(ch) WINE_TRACE
104 #ifdef WINE_NO_DEBUG_MSGS
105 #define WINE_WARN(...) do { } while(0)
106 #define WINE_WARN_(ch) WINE_WARN
107 #define WINE_FIXME(...) do { } while(0)
108 #define WINE_FIXME_(ch) WINE_FIXME
111 extern int WINAPI
__wine_dbg_write( const char *str
, unsigned int len
);
112 extern unsigned char __cdecl
__wine_dbg_get_channel_flags( struct __wine_debug_channel
*channel
);
113 extern const char * __cdecl
__wine_dbg_strdup( const char *str
);
114 extern int __cdecl
__wine_dbg_output( const char *str
);
115 extern int __cdecl
__wine_dbg_header( enum __wine_debug_class cls
, struct __wine_debug_channel
*channel
,
116 const char *function
);
119 * Exported definitions and macros
122 /* These functions return a printable version of a string, including
123 quotes. The string will be valid for some time, but not indefinitely
124 as strings are re-used. */
126 #if (defined(__x86_64__) || (defined(__aarch64__) && __has_attribute(ms_abi))) && defined(__GNUC__) && defined(__WINE_USE_MSVCRT)
127 # define __wine_dbg_cdecl __cdecl
129 # define __wine_dbg_cdecl
132 static const char * __wine_dbg_cdecl
wine_dbg_vsprintf( const char *format
, va_list args
) __WINE_PRINTF_ATTR(1,0);
133 static inline const char * __wine_dbg_cdecl
wine_dbg_vsprintf( const char *format
, va_list args
)
137 vsnprintf( buffer
, sizeof(buffer
), format
, args
);
138 return __wine_dbg_strdup( buffer
);
141 static const char * __wine_dbg_cdecl
wine_dbg_sprintf( const char *format
, ... ) __WINE_PRINTF_ATTR(1,2);
142 static inline const char * __wine_dbg_cdecl
wine_dbg_sprintf( const char *format
, ... )
147 va_start( args
, format
);
148 ret
= wine_dbg_vsprintf( format
, args
);
153 static int __wine_dbg_cdecl
wine_dbg_vprintf( const char *format
, va_list args
) __WINE_PRINTF_ATTR(1,0);
154 static inline int __wine_dbg_cdecl
wine_dbg_vprintf( const char *format
, va_list args
)
158 vsnprintf( buffer
, sizeof(buffer
), format
, args
);
159 return __wine_dbg_output( buffer
);
162 static int __wine_dbg_cdecl
wine_dbg_printf( const char *format
, ... ) __WINE_PRINTF_ATTR(1,2);
163 static inline int __wine_dbg_cdecl
wine_dbg_printf( const char *format
, ... )
168 va_start( args
, format
);
169 ret
= wine_dbg_vprintf( format
, args
);
174 static int __wine_dbg_cdecl
wine_dbg_vlog( enum __wine_debug_class cls
,
175 struct __wine_debug_channel
*channel
, const char *func
,
176 const char *format
, va_list args
) __WINE_PRINTF_ATTR(4,0);
177 static inline int __wine_dbg_cdecl
wine_dbg_vlog( enum __wine_debug_class cls
,
178 struct __wine_debug_channel
*channel
,
179 const char *function
, const char *format
, va_list args
)
183 if (*format
== '\1') /* special magic to avoid standard prefix */
188 if ((ret
= __wine_dbg_header( cls
, channel
, function
)) != -1) ret
+= wine_dbg_vprintf( format
, args
);
192 static int __wine_dbg_cdecl
wine_dbg_log( enum __wine_debug_class cls
,
193 struct __wine_debug_channel
*channel
, const char *func
,
194 const char *format
, ... ) __WINE_PRINTF_ATTR(4,5);
195 static inline int __wine_dbg_cdecl
wine_dbg_log( enum __wine_debug_class cls
,
196 struct __wine_debug_channel
*channel
,
197 const char *function
, const char *format
, ... )
202 va_start( args
, format
);
203 ret
= wine_dbg_vlog( cls
, channel
, function
, format
, args
);
208 static inline const char *wine_dbgstr_an( const char *str
, int n
)
210 static const char hex
[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
211 char buffer
[300], *dst
= buffer
;
213 if (!str
) return "(null)";
214 if (!((ULONG_PTR
)str
>> 16)) return wine_dbg_sprintf( "#%04x", LOWORD(str
) );
215 #ifndef WINE_UNIX_LIB
216 if (IsBadStringPtrA( str
, n
)) return "(invalid)";
218 if (n
== -1) for (n
= 0; str
[n
]; n
++) ;
220 while (n
-- > 0 && dst
<= buffer
+ sizeof(buffer
) - 9)
222 unsigned char c
= *str
++;
225 case '\n': *dst
++ = '\\'; *dst
++ = 'n'; break;
226 case '\r': *dst
++ = '\\'; *dst
++ = 'r'; break;
227 case '\t': *dst
++ = '\\'; *dst
++ = 't'; break;
228 case '"': *dst
++ = '\\'; *dst
++ = '"'; break;
229 case '\\': *dst
++ = '\\'; *dst
++ = '\\'; break;
231 if (c
< ' ' || c
>= 127)
235 *dst
++ = hex
[(c
>> 4) & 0x0f];
236 *dst
++ = hex
[c
& 0x0f];
249 return __wine_dbg_strdup( buffer
);
252 static inline const char *wine_dbgstr_wn( const WCHAR
*str
, int n
)
254 static const char hex
[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
255 char buffer
[300], *dst
= buffer
;
257 if (!str
) return "(null)";
258 if (!((ULONG_PTR
)str
>> 16)) return wine_dbg_sprintf( "#%04x", LOWORD(str
) );
259 #ifndef WINE_UNIX_LIB
260 if (IsBadStringPtrW( str
, n
)) return "(invalid)";
262 if (n
== -1) for (n
= 0; str
[n
]; n
++) ;
265 while (n
-- > 0 && dst
<= buffer
+ sizeof(buffer
) - 10)
270 case '\n': *dst
++ = '\\'; *dst
++ = 'n'; break;
271 case '\r': *dst
++ = '\\'; *dst
++ = 'r'; break;
272 case '\t': *dst
++ = '\\'; *dst
++ = 't'; break;
273 case '"': *dst
++ = '\\'; *dst
++ = '"'; break;
274 case '\\': *dst
++ = '\\'; *dst
++ = '\\'; break;
276 if (c
< ' ' || c
>= 127)
279 *dst
++ = hex
[(c
>> 12) & 0x0f];
280 *dst
++ = hex
[(c
>> 8) & 0x0f];
281 *dst
++ = hex
[(c
>> 4) & 0x0f];
282 *dst
++ = hex
[c
& 0x0f];
284 else *dst
++ = (char)c
;
295 return __wine_dbg_strdup( buffer
);
298 static inline const char *wine_dbgstr_a( const char *s
)
300 return wine_dbgstr_an( s
, -1 );
303 static inline const char *wine_dbgstr_w( const WCHAR
*s
)
305 return wine_dbgstr_wn( s
, -1 );
308 static inline const char *wine_dbgstr_guid( const GUID
*id
)
310 if (!id
) return "(null)";
311 if (!((ULONG_PTR
)id
>> 16)) return wine_dbg_sprintf( "<guid-0x%04hx>", (WORD
)(ULONG_PTR
)id
);
312 return wine_dbg_sprintf( "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
313 (unsigned int)id
->Data1
, id
->Data2
, id
->Data3
,
314 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
315 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7] );
318 static inline const char *wine_dbgstr_point( const POINT
*pt
)
320 if (!pt
) return "(null)";
321 return wine_dbg_sprintf( "(%d,%d)", (int)pt
->x
, (int)pt
->y
);
324 static inline const char *wine_dbgstr_rect( const RECT
*rect
)
326 if (!rect
) return "(null)";
327 return wine_dbg_sprintf( "(%d,%d)-(%d,%d)", (int)rect
->left
, (int)rect
->top
,
328 (int)rect
->right
, (int)rect
->bottom
);
331 static inline const char *wine_dbgstr_longlong( ULONGLONG ll
)
333 if (sizeof(ll
) > sizeof(unsigned long) && ll
>> 32)
334 return wine_dbg_sprintf( "%lx%08lx", (unsigned long)(ll
>> 32), (unsigned long)ll
);
335 else return wine_dbg_sprintf( "%lx", (unsigned long)ll
);
338 #if defined(__oaidl_h__) && defined(V_VT)
340 static inline const char *wine_dbgstr_vt( VARTYPE vt
)
342 static const char *const variant_types
[] =
344 "VT_EMPTY","VT_NULL","VT_I2","VT_I4","VT_R4","VT_R8","VT_CY","VT_DATE",
345 "VT_BSTR","VT_DISPATCH","VT_ERROR","VT_BOOL","VT_VARIANT","VT_UNKNOWN",
346 "VT_DECIMAL","15","VT_I1","VT_UI1","VT_UI2","VT_UI4","VT_I8","VT_UI8",
347 "VT_INT","VT_UINT","VT_VOID","VT_HRESULT","VT_PTR","VT_SAFEARRAY",
348 "VT_CARRAY","VT_USERDEFINED","VT_LPSTR","VT_LPWSTR","32","33","34","35",
349 "VT_RECORD","VT_INT_PTR","VT_UINT_PTR","39","40","41","42","43","44","45",
350 "46","47","48","49","50","51","52","53","54","55","56","57","58","59","60",
351 "61","62","63","VT_FILETIME","VT_BLOB","VT_STREAM","VT_STORAGE",
352 "VT_STREAMED_OBJECT","VT_STORED_OBJECT","VT_BLOB_OBJECT","VT_CF","VT_CLSID",
353 "VT_VERSIONED_STREAM"
356 static const char *const variant_flags
[16] =
361 "|VT_VECTOR|VT_ARRAY",
363 "|VT_VECTOR|VT_BYREF",
364 "|VT_ARRAY|VT_BYREF",
365 "|VT_VECTOR|VT_ARRAY|VT_BYREF",
367 "|VT_VECTOR|VT_RESERVED",
368 "|VT_ARRAY|VT_RESERVED",
369 "|VT_VECTOR|VT_ARRAY|VT_RESERVED",
370 "|VT_BYREF|VT_RESERVED",
371 "|VT_VECTOR|VT_BYREF|VT_RESERVED",
372 "|VT_ARRAY|VT_BYREF|VT_RESERVED",
373 "|VT_VECTOR|VT_ARRAY|VT_BYREF|VT_RESERVED",
376 if (vt
& ~VT_TYPEMASK
)
377 return wine_dbg_sprintf( "%s%s", wine_dbgstr_vt(vt
&VT_TYPEMASK
), variant_flags
[vt
>>12] );
379 if (vt
< sizeof(variant_types
)/sizeof(*variant_types
))
380 return variant_types
[vt
];
382 if (vt
== VT_BSTR_BLOB
)
383 return "VT_BSTR_BLOB";
385 return wine_dbg_sprintf( "vt(invalid %x)", vt
);
388 static inline const char *wine_dbgstr_variant( const VARIANT
*v
)
393 if (V_VT(v
) & VT_BYREF
) {
394 if (V_VT(v
) == (VT_VARIANT
|VT_BYREF
))
395 return wine_dbg_sprintf( "%p {VT_VARIANT|VT_BYREF: %s}", v
, wine_dbgstr_variant(V_VARIANTREF(v
)) );
396 if (V_VT(v
) == (VT_BSTR
|VT_BYREF
))
397 return wine_dbg_sprintf( "%p {VT_BSTR|VT_BYREF: %s}", v
, V_BSTRREF(v
) ? wine_dbgstr_w(*V_BSTRREF(v
)) : "(none)" );
398 return wine_dbg_sprintf( "%p {%s %p}", v
, wine_dbgstr_vt(V_VT(v
)), V_BYREF(v
) );
401 if (V_ISARRAY(v
) || V_ISVECTOR(v
))
402 return wine_dbg_sprintf( "%p {%s %p}", v
, wine_dbgstr_vt(V_VT(v
)), V_ARRAY(v
) );
406 return wine_dbg_sprintf( "%p {VT_EMPTY}", v
);
408 return wine_dbg_sprintf( "%p {VT_NULL}", v
);
410 return wine_dbg_sprintf( "%p {VT_I2: %d}", v
, V_I2(v
) );
412 return wine_dbg_sprintf( "%p {VT_I4: %d}", v
, (int)V_I4(v
) );
414 return wine_dbg_sprintf( "%p {VT_R4: %f}", v
, V_R4(v
) );
416 return wine_dbg_sprintf( "%p {VT_R8: %lf}", v
, V_R8(v
) );
418 return wine_dbg_sprintf( "%p {VT_CY: %s}", v
, wine_dbgstr_longlong(V_CY(v
).int64
) );
420 return wine_dbg_sprintf( "%p {VT_DATE: %lf}", v
, V_DATE(v
) );
422 return wine_dbg_sprintf( "%p {VT_LPSTR: %s}", v
, wine_dbgstr_a((const char *)V_BSTR(v
)) );
424 return wine_dbg_sprintf( "%p {VT_LPWSTR: %s}", v
, wine_dbgstr_w(V_BSTR(v
)) );
426 return wine_dbg_sprintf( "%p {VT_BSTR: %s}", v
, wine_dbgstr_w(V_BSTR(v
)) );
428 return wine_dbg_sprintf( "%p {VT_DISPATCH: %p}", v
, V_DISPATCH(v
) );
430 return wine_dbg_sprintf( "%p {VT_ERROR: %08x}", v
, (int)V_ERROR(v
) );
432 return wine_dbg_sprintf( "%p {VT_BOOL: %x}", v
, V_BOOL(v
) );
434 return wine_dbg_sprintf( "%p {VT_UNKNOWN: %p}", v
, V_UNKNOWN(v
) );
436 return wine_dbg_sprintf( "%p {VT_I1: %d}", v
, V_I1(v
) );
438 return wine_dbg_sprintf( "%p {VT_UI1: %u}", v
, V_UI1(v
) );
440 return wine_dbg_sprintf( "%p {VT_UI2: %u}", v
, V_UI2(v
) );
442 return wine_dbg_sprintf( "%p {VT_UI4: %u}", v
, (unsigned int)V_UI4(v
) );
444 return wine_dbg_sprintf( "%p {VT_I8: %s}", v
, wine_dbgstr_longlong(V_I8(v
)) );
446 return wine_dbg_sprintf( "%p {VT_UI8: %s}", v
, wine_dbgstr_longlong(V_UI8(v
)) );
448 return wine_dbg_sprintf( "%p {VT_INT: %d}", v
, V_INT(v
) );
450 return wine_dbg_sprintf( "%p {VT_UINT: %u}", v
, V_UINT(v
) );
452 return wine_dbg_sprintf( "%p {VT_VOID}", v
);
454 return wine_dbg_sprintf( "%p {VT_RECORD: %p %p}", v
, V_RECORD(v
), V_RECORDINFO(v
) );
456 return wine_dbg_sprintf( "%p {vt %s}", v
, wine_dbgstr_vt(V_VT(v
)) );
460 #endif /* defined(__oaidl_h__) && defined(V_VT) */
463 #define WINE_TRACE __WINE_DPRINTF(_TRACE,__wine_dbch___default)
464 #define WINE_TRACE_(ch) __WINE_DPRINTF(_TRACE,&__wine_dbch_##ch)
466 #define WINE_TRACE_ON(ch) __WINE_IS_DEBUG_ON(_TRACE,&__wine_dbch_##ch)
469 #define WINE_WARN __WINE_DPRINTF(_WARN,__wine_dbch___default)
470 #define WINE_WARN_(ch) __WINE_DPRINTF(_WARN,&__wine_dbch_##ch)
472 #define WINE_WARN_ON(ch) __WINE_IS_DEBUG_ON(_WARN,&__wine_dbch_##ch)
475 #define WINE_FIXME __WINE_DPRINTF(_FIXME,__wine_dbch___default)
476 #define WINE_FIXME_(ch) __WINE_DPRINTF(_FIXME,&__wine_dbch_##ch)
478 #define WINE_FIXME_ON(ch) __WINE_IS_DEBUG_ON(_FIXME,&__wine_dbch_##ch)
480 #define WINE_ERR __WINE_DPRINTF(_ERR,__wine_dbch___default)
481 #define WINE_ERR_(ch) __WINE_DPRINTF(_ERR,&__wine_dbch_##ch)
482 #define WINE_ERR_ON(ch) __WINE_IS_DEBUG_ON(_ERR,&__wine_dbch_##ch)
484 #define WINE_DECLARE_DEBUG_CHANNEL(ch) \
485 static struct __wine_debug_channel __wine_dbch_##ch = { 0xff, #ch }
486 #define WINE_DEFAULT_DEBUG_CHANNEL(ch) \
487 static struct __wine_debug_channel __wine_dbch_##ch = { 0xff, #ch }; \
488 static struct __wine_debug_channel * const __wine_dbch___default = &__wine_dbch_##ch
490 #define WINE_MESSAGE wine_dbg_printf
493 /* Wine uses shorter names that are very likely to conflict with other software */
495 static inline const char *debugstr_an( const char * s
, int n
) { return wine_dbgstr_an( s
, n
); }
496 static inline const char *debugstr_wn( const WCHAR
*s
, int n
) { return wine_dbgstr_wn( s
, n
); }
497 static inline const char *debugstr_guid( const struct _GUID
*id
) { return wine_dbgstr_guid(id
); }
498 static inline const char *debugstr_a( const char *s
) { return wine_dbgstr_an( s
, -1 ); }
499 static inline const char *debugstr_w( const WCHAR
*s
) { return wine_dbgstr_wn( s
, -1 ); }
501 #if defined(__oaidl_h__) && defined(V_VT)
502 static inline const char *debugstr_vt( VARTYPE vt
) { return wine_dbgstr_vt( vt
); }
503 static inline const char *debugstr_variant( const VARIANT
*v
) { return wine_dbgstr_variant( v
); }
506 #define TRACE WINE_TRACE
507 #define TRACE_(ch) WINE_TRACE_(ch)
508 #define TRACE_ON(ch) WINE_TRACE_ON(ch)
510 #define WARN WINE_WARN
511 #define WARN_(ch) WINE_WARN_(ch)
512 #define WARN_ON(ch) WINE_WARN_ON(ch)
514 #define FIXME WINE_FIXME
515 #define FIXME_(ch) WINE_FIXME_(ch)
516 #define FIXME_ON(ch) WINE_FIXME_ON(ch)
518 #undef ERR /* Solaris got an 'ERR' define in <sys/reg.h> */
520 #define ERR_(ch) WINE_ERR_(ch)
521 #define ERR_ON(ch) WINE_ERR_ON(ch)
523 #define MESSAGE WINE_MESSAGE
525 #endif /* __WINESRC__ */
531 #endif /* __WINE_WINE_DEBUG_H */