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
37 * Internal definitions (do not use these directly)
40 enum __wine_debug_class
49 struct __wine_debug_channel
55 #ifndef WINE_NO_TRACE_MSGS
56 # define __WINE_GET_DEBUGGING_TRACE(dbch) ((dbch)->flags & (1 << __WINE_DBCL_TRACE))
58 # define __WINE_GET_DEBUGGING_TRACE(dbch) 0
61 #ifndef WINE_NO_DEBUG_MSGS
62 # define __WINE_GET_DEBUGGING_WARN(dbch) ((dbch)->flags & (1 << __WINE_DBCL_WARN))
63 # define __WINE_GET_DEBUGGING_FIXME(dbch) ((dbch)->flags & (1 << __WINE_DBCL_FIXME))
65 # define __WINE_GET_DEBUGGING_WARN(dbch) 0
66 # define __WINE_GET_DEBUGGING_FIXME(dbch) 0
69 /* define error macro regardless of what is configured */
70 #define __WINE_GET_DEBUGGING_ERR(dbch) ((dbch)->flags & (1 << __WINE_DBCL_ERR))
72 #define __WINE_GET_DEBUGGING(dbcl,dbch) __WINE_GET_DEBUGGING##dbcl(dbch)
73 #define __WINE_SET_DEBUGGING(dbcl,dbch,on) \
74 ((on) ? ((dbch)[0] |= 1 << (dbcl)) : ((dbch)[0] &= ~(1 << (dbcl))))
78 #define __WINE_DPRINTF(dbcl,dbch) \
79 do { if(__WINE_GET_DEBUGGING(dbcl,(dbch))) { \
80 struct __wine_debug_channel * const __dbch = (dbch); \
81 const enum __wine_debug_class __dbcl = __WINE_DBCL##dbcl; \
84 #define __WINE_DBG_LOG(args...) \
85 wine_dbg_log( __dbcl, __dbch, __FUNCTION__, args); } } while(0)
87 #define __WINE_PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
90 #ifdef WINE_NO_TRACE_MSGS
91 #define WINE_TRACE(args...) do { } while(0)
92 #define WINE_TRACE_(ch) WINE_TRACE
95 #ifdef WINE_NO_DEBUG_MSGS
96 #define WINE_WARN(args...) do { } while(0)
97 #define WINE_WARN_(ch) WINE_WARN
98 #define WINE_FIXME(args...) do { } while(0)
99 #define WINE_FIXME_(ch) WINE_FIXME
102 #elif defined(__SUNPRO_C)
104 #define __WINE_DPRINTF(dbcl,dbch) \
105 do { if(__WINE_GET_DEBUGGING(dbcl,(dbch))) { \
106 struct __wine_debug_channel * const __dbch = (dbch); \
107 const enum __WINE_DEBUG_CLASS __dbcl = __WINE_DBCL##dbcl; \
110 #define __WINE_DBG_LOG(...) \
111 wine_dbg_log( __dbcl, __dbch, __func__, __VA_ARGS__); } } while(0)
113 #define __WINE_PRINTF_ATTR(fmt,args)
115 #ifdef WINE_NO_TRACE_MSGS
116 #define WINE_TRACE(...) do { } while(0)
117 #define WINE_TRACE_(ch) WINE_TRACE
120 #ifdef WINE_NO_DEBUG_MSGS
121 #define WINE_WARN(...) do { } while(0)
122 #define WINE_WARN_(ch) WINE_WARN
123 #define WINE_FIXME(...) do { } while(0)
124 #define WINE_FIXME_(ch) WINE_FIXME
127 #else /* !__GNUC__ && !__SUNPRO_C */
129 #define __WINE_DPRINTF(dbcl,dbch) \
130 (!__WINE_GET_DEBUGGING(dbcl,(dbch)) || \
131 (wine_dbg_log(__WINE_DBCL##dbcl,(dbch),__FILE__,"%d: ",__LINE__),0)) ? \
132 (void)0 : (void)wine_dbg_printf
134 #define __WINE_PRINTF_ATTR(fmt, args)
136 #endif /* !__GNUC__ && !__SUNPRO_C */
138 struct __wine_debug_functions
140 char * (*get_temp_buffer)( size_t n );
141 void (*release_temp_buffer)( char *buffer, size_t n );
142 const char * (*dbgstr_an)( const char * s, int n );
143 const char * (*dbgstr_wn)( const WCHAR *s, int n );
144 int (*dbg_vprintf)( const char *format, va_list args );
145 int (*dbg_vlog)( enum __wine_debug_class cls, struct __wine_debug_channel *channel,
146 const char *function, const char *format, va_list args );
149 extern void __wine_dbg_set_functions( const struct __wine_debug_functions *new_funcs,
150 struct __wine_debug_functions *old_funcs, size_t size );
153 * Exported definitions and macros
156 /* These function return a printable version of a string, including
157 quotes. The string will be valid for some time, but not indefinitely
158 as strings are re-used. */
159 extern const char *wine_dbgstr_an( const char * s, int n );
160 extern const char *wine_dbgstr_wn( const WCHAR *s, int n );
161 extern const char *wine_dbg_sprintf( const char *format, ... ) __WINE_PRINTF_ATTR(1,2);
163 extern int wine_dbg_printf( const char *format, ... ) __WINE_PRINTF_ATTR(1,2);
164 extern int wine_dbg_log( enum __wine_debug_class cls, struct __wine_debug_channel *ch, const char *func,
165 const char *format, ... ) __WINE_PRINTF_ATTR(4,5);
167 extern inline const char *wine_dbgstr_a( const char *s )
169 return wine_dbgstr_an( s, -1 );
172 extern inline const char *wine_dbgstr_w( const WCHAR *s )
174 return wine_dbgstr_wn( s, -1 );
177 static inline const char *wine_dbgstr_guid( const GUID *id )
179 if (!id) return "(null)";
180 if (!((INT_PTR)id >> 16)) return wine_dbg_sprintf( "<guid-0x%04x>", (INT_PTR)id & 0xffff );
181 return wine_dbg_sprintf( "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
182 id->Data1, id->Data2, id->Data3,
183 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
184 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
187 static inline const char *wine_dbgstr_point( const POINT *pt )
189 if (!pt) return "(null)";
190 return wine_dbg_sprintf( "(%ld,%ld)", pt->x, pt->y );
193 static inline const char *wine_dbgstr_size( const SIZE *size )
195 if (!size) return "(null)";
196 return wine_dbg_sprintf( "(%ld,%ld)", size->cx, size->cy );
199 static inline const char *wine_dbgstr_rect( const RECT *rect )
201 if (!rect) return "(null)";
202 return wine_dbg_sprintf( "(%ld,%ld)-(%ld,%ld)", rect->left, rect->top, rect->right, rect->bottom );
205 static inline const char *wine_dbgstr_longlong( ULONGLONG ll )
207 if (sizeof(ll) > sizeof(unsigned long) && ll >> 32)
208 return wine_dbg_sprintf( "%lx%08lx", (unsigned long)(ll >> 32), (unsigned long)ll );
209 else return wine_dbg_sprintf( "%lx", (unsigned long)ll );
213 #define WINE_TRACE __WINE_DPRINTF(_TRACE,__wine_dbch___default)
214 #define WINE_TRACE_(ch) __WINE_DPRINTF(_TRACE,&__wine_dbch_##ch)
216 #define WINE_TRACE_ON(ch) __WINE_GET_DEBUGGING(_TRACE,&__wine_dbch_##ch)
219 #define WINE_WARN __WINE_DPRINTF(_WARN,__wine_dbch___default)
220 #define WINE_WARN_(ch) __WINE_DPRINTF(_WARN,&__wine_dbch_##ch)
222 #define WINE_WARN_ON(ch) __WINE_GET_DEBUGGING(_WARN,&__wine_dbch_##ch)
225 #define WINE_FIXME __WINE_DPRINTF(_FIXME,__wine_dbch___default)
226 #define WINE_FIXME_(ch) __WINE_DPRINTF(_FIXME,&__wine_dbch_##ch)
228 #define WINE_FIXME_ON(ch) __WINE_GET_DEBUGGING(_FIXME,&__wine_dbch_##ch)
230 #define WINE_ERR __WINE_DPRINTF(_ERR,__wine_dbch___default)
231 #define WINE_ERR_(ch) __WINE_DPRINTF(_ERR,&__wine_dbch_##ch)
232 #define WINE_ERR_ON(ch) __WINE_GET_DEBUGGING(_ERR,&__wine_dbch_##ch)
234 #define WINE_DECLARE_DEBUG_CHANNEL(ch) \
235 extern struct __wine_debug_channel __wine_dbch_##ch
236 #define WINE_DEFAULT_DEBUG_CHANNEL(ch) \
237 extern struct __wine_debug_channel __wine_dbch_##ch; \
238 static struct __wine_debug_channel * const __wine_dbch___default = &__wine_dbch_##ch
240 #define WINE_DPRINTF wine_dbg_printf
241 #define WINE_MESSAGE wine_dbg_printf
244 /* Wine uses shorter names that are very likely to conflict with other software */
246 inline static const char *debugstr_an( const char * s, int n ) { return wine_dbgstr_an( s, n ); }
247 inline static const char *debugstr_wn( const WCHAR *s, int n ) { return wine_dbgstr_wn( s, n ); }
248 inline static const char *debugstr_guid( const struct _GUID *id ) { return wine_dbgstr_guid(id); }
249 inline static const char *debugstr_a( const char *s ) { return wine_dbgstr_an( s, -1 ); }
250 inline static const char *debugstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, -1 ); }
252 #define TRACE WINE_TRACE
253 #define TRACE_(ch) WINE_TRACE_(ch)
254 #define TRACE_ON(ch) WINE_TRACE_ON(ch)
256 #define WARN WINE_WARN
257 #define WARN_(ch) WINE_WARN_(ch)
258 #define WARN_ON(ch) WINE_WARN_ON(ch)
260 #define FIXME WINE_FIXME
261 #define FIXME_(ch) WINE_FIXME_(ch)
262 #define FIXME_ON(ch) WINE_FIXME_ON(ch)
264 #undef ERR /* Solaris got an 'ERR' define in <sys/reg.h> */
266 #define ERR_(ch) WINE_ERR_(ch)
267 #define ERR_ON(ch) WINE_ERR_ON(ch)
269 #define DPRINTF WINE_DPRINTF
270 #define MESSAGE WINE_MESSAGE
272 #endif /* __WINESRC__ */
278 #endif /* __WINE_WINE_DEBUG_H */