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