Release 0.9.6.
[wine/multimedia.git] / include / wine / debug.h
blob05c41841f6b0dc2b0c10e88b9cf75c394683fb5a
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 __cplusplus
31 extern "C" {
32 #endif
34 struct _GUID;
37 * Internal definitions (do not use these directly)
40 enum __wine_debug_class
42 __WINE_DBCL_FIXME,
43 __WINE_DBCL_ERR,
44 __WINE_DBCL_WARN,
45 __WINE_DBCL_TRACE,
47 __WINE_DBCL_INIT = 7 /* lazy init flag */
50 struct __wine_debug_channel
52 unsigned char flags;
53 char name[15];
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
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
70 /* define error macro regardless of what is configured */
71 #define __WINE_GET_DEBUGGING_ERR(dbch) ((dbch)->flags & (1 << __WINE_DBCL_ERR))
73 #define __WINE_GET_DEBUGGING(dbcl,dbch) __WINE_GET_DEBUGGING##dbcl(dbch)
75 #define __WINE_IS_DEBUG_ON(dbcl,dbch) \
76 (__WINE_GET_DEBUGGING##dbcl(dbch) && (__wine_dbg_get_channel_flags(dbch) & (1 << __WINE_DBCL##dbcl)))
78 #ifdef __GNUC__
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
86 #define __WINE_DBG_LOG(args...) \
87 wine_dbg_log( __dbcl, __dbch, __FUNCTION__, args); } } while(0)
89 #define __WINE_PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
92 #ifdef WINE_NO_TRACE_MSGS
93 #define WINE_TRACE(args...) do { } while(0)
94 #define WINE_TRACE_(ch) WINE_TRACE
95 #endif
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
104 #elif defined(__SUNPRO_C)
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
112 #define __WINE_DBG_LOG(...) \
113 wine_dbg_log( __dbcl, __dbch, __func__, __VA_ARGS__); } } while(0)
115 #define __WINE_PRINTF_ATTR(fmt,args)
117 #ifdef WINE_NO_TRACE_MSGS
118 #define WINE_TRACE(...) do { } while(0)
119 #define WINE_TRACE_(ch) WINE_TRACE
120 #endif
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
129 #else /* !__GNUC__ && !__SUNPRO_C */
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
136 #define __WINE_PRINTF_ATTR(fmt, args)
138 #endif /* !__GNUC__ && !__SUNPRO_C */
140 struct __wine_debug_functions
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 );
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 );
158 * Exported definitions and macros
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);
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);
172 static inline const char *wine_dbgstr_a( const char *s )
174 return wine_dbgstr_an( s, -1 );
177 static inline const char *wine_dbgstr_w( const WCHAR *s )
179 return wine_dbgstr_wn( s, -1 );
182 static inline const char *wine_dbgstr_guid( const GUID *id )
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] );
192 static inline const char *wine_dbgstr_point( const POINT *pt )
194 if (!pt) return "(null)";
195 return wine_dbg_sprintf( "(%ld,%ld)", pt->x, pt->y );
198 static inline const char *wine_dbgstr_size( const SIZE *size )
200 if (!size) return "(null)";
201 return wine_dbg_sprintf( "(%ld,%ld)", size->cx, size->cy );
204 static inline const char *wine_dbgstr_rect( const RECT *rect )
206 if (!rect) return "(null)";
207 return wine_dbg_sprintf( "(%ld,%ld)-(%ld,%ld)", rect->left, rect->top, rect->right, rect->bottom );
210 static inline const char *wine_dbgstr_longlong( ULONGLONG ll )
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 );
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)
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)
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)
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)
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
245 #define WINE_DPRINTF wine_dbg_printf
246 #define WINE_MESSAGE wine_dbg_printf
248 #ifdef __WINESRC__
249 /* Wine uses shorter names that are very likely to conflict with other software */
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 ); }
257 #define TRACE WINE_TRACE
258 #define TRACE_(ch) WINE_TRACE_(ch)
259 #define TRACE_ON(ch) WINE_TRACE_ON(ch)
261 #define WARN WINE_WARN
262 #define WARN_(ch) WINE_WARN_(ch)
263 #define WARN_ON(ch) WINE_WARN_ON(ch)
265 #define FIXME WINE_FIXME
266 #define FIXME_(ch) WINE_FIXME_(ch)
267 #define FIXME_ON(ch) WINE_FIXME_ON(ch)
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)
274 #define DPRINTF WINE_DPRINTF
275 #define MESSAGE WINE_MESSAGE
277 #endif /* __WINESRC__ */
279 #ifdef __cplusplus
281 #endif
283 #endif /* __WINE_WINE_DEBUG_H */