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 {
48 #ifndef WINE_NO_TRACE_MSGS
49 # define __WINE_GET_DEBUGGING_TRACE(dbch) ((dbch)[0] & (1 << __WINE_DBCL_TRACE))
51 # define __WINE_GET_DEBUGGING_TRACE(dbch) 0
54 #ifndef WINE_NO_DEBUG_MSGS
55 # define __WINE_GET_DEBUGGING_WARN(dbch) ((dbch)[0] & (1 << __WINE_DBCL_WARN))
56 # define __WINE_GET_DEBUGGING_FIXME(dbch) ((dbch)[0] & (1 << __WINE_DBCL_FIXME))
58 # define __WINE_GET_DEBUGGING_WARN(dbch) 0
59 # define __WINE_GET_DEBUGGING_FIXME(dbch) 0
62 /* define error macro regardless of what is configured */
63 #define __WINE_GET_DEBUGGING_ERR(dbch) ((dbch)[0] & (1 << __WINE_DBCL_ERR))
65 #define __WINE_GET_DEBUGGING(dbcl,dbch) __WINE_GET_DEBUGGING##dbcl(dbch)
66 #define __WINE_SET_DEBUGGING(dbcl,dbch,on) \
67 ((on) ? ((dbch)[0] |= 1 << (dbcl)) : ((dbch)[0] &= ~(1 << (dbcl))))
71 #define __WINE_DPRINTF(dbcl,dbch) \
72 do { if(__WINE_GET_DEBUGGING(dbcl,(dbch))) { \
73 const char * const __dbch = (dbch); \
74 const enum __WINE_DEBUG_CLASS __dbcl = __WINE_DBCL##dbcl; \
77 #define __WINE_DBG_LOG(args...) \
78 wine_dbg_log( __dbcl, __dbch, __FUNCTION__, args); } } while(0)
80 #define __WINE_PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
83 #ifdef WINE_NO_TRACE_MSGS
84 #define WINE_TRACE(args...) do { } while(0)
85 #define WINE_TRACE_(ch) WINE_TRACE
88 #ifdef WINE_NO_DEBUG_MSGS
89 #define WINE_WARN(args...) do { } while(0)
90 #define WINE_WARN_(ch) WINE_WARN
91 #define WINE_FIXME(args...) do { } while(0)
92 #define WINE_FIXME_(ch) WINE_FIXME
95 #elif defined(__SUNPRO_C)
97 #define __WINE_DPRINTF(dbcl,dbch) \
98 do { if(__WINE_GET_DEBUGGING(dbcl,(dbch))) { \
99 const char * const __dbch = (dbch); \
100 const enum __WINE_DEBUG_CLASS __dbcl = __WINE_DBCL##dbcl; \
103 #define __WINE_DBG_LOG(...) \
104 wine_dbg_log( __dbcl, __dbch, __func__, __VA_ARGS__); } } while(0)
106 #define __WINE_PRINTF_ATTR(fmt,args)
108 #ifdef WINE_NO_TRACE_MSGS
109 #define WINE_TRACE(...) do { } while(0)
110 #define WINE_TRACE_(ch) WINE_TRACE
113 #ifdef WINE_NO_DEBUG_MSGS
114 #define WINE_WARN(...) do { } while(0)
115 #define WINE_WARN_(ch) WINE_WARN
116 #define WINE_FIXME(...) do { } while(0)
117 #define WINE_FIXME_(ch) WINE_FIXME
120 #else /* !__GNUC__ && !__SUNPRO_C */
122 #define __WINE_DPRINTF(dbcl,dbch) \
123 (!__WINE_GET_DEBUGGING(dbcl,(dbch)) || \
124 (wine_dbg_log(__WINE_DBCL##dbcl,(dbch),__FILE__,"%d: ",__LINE__),0)) ? \
125 (void)0 : (void)wine_dbg_printf
127 #define __WINE_PRINTF_ATTR(fmt, args)
129 #endif /* !__GNUC__ && !__SUNPRO_C */
133 * Exported definitions and macros
136 /* These function return a printable version of a string, including
137 quotes. The string will be valid for some time, but not indefinitely
138 as strings are re-used. */
139 extern const char *wine_dbgstr_an( const char * s, int n );
140 extern const char *wine_dbgstr_wn( const WCHAR *s, int n );
141 extern const char *wine_dbgstr_a( const char *s );
142 extern const char *wine_dbgstr_w( const WCHAR *s );
143 extern const char *wine_dbg_sprintf( const char *format, ... ) __WINE_PRINTF_ATTR(1,2);
145 extern int wine_dbg_printf( const char *format, ... ) __WINE_PRINTF_ATTR(1,2);
146 extern int wine_dbg_log( unsigned int cls, const char *ch, const char *func,
147 const char *format, ... ) __WINE_PRINTF_ATTR(4,5);
149 static inline const char *wine_dbgstr_guid( const GUID *id )
151 if (!id) return "(null)";
152 if (!((int)id >> 16)) return wine_dbg_sprintf( "<guid-0x%04x>", (int)id & 0xffff );
153 return wine_dbg_sprintf( "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
154 id->Data1, id->Data2, id->Data3,
155 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
156 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
159 static inline const char *wine_dbgstr_point( const POINT *pt )
161 if (!pt) return "(null)";
162 return wine_dbg_sprintf( "(%ld,%ld)", pt->x, pt->y );
165 static inline const char *wine_dbgstr_size( const SIZE *size )
167 if (!size) return "(null)";
168 return wine_dbg_sprintf( "(%ld,%ld)", size->cx, size->cy );
171 static inline const char *wine_dbgstr_rect( const RECT *rect )
173 if (!rect) return "(null)";
174 return wine_dbg_sprintf( "(%ld,%ld)-(%ld,%ld)", rect->left, rect->top, rect->right, rect->bottom );
177 static inline const char *wine_dbgstr_longlong( ULONGLONG ll )
179 if (ll >> 32) return wine_dbg_sprintf( "%lx%08lx", (unsigned long)(ll >> 32), (unsigned long)ll );
180 else return wine_dbg_sprintf( "%lx", (unsigned long)ll );
184 #define WINE_TRACE __WINE_DPRINTF(_TRACE,__wine_dbch___default)
185 #define WINE_TRACE_(ch) __WINE_DPRINTF(_TRACE,__wine_dbch_##ch)
187 #define WINE_TRACE_ON(ch) __WINE_GET_DEBUGGING(_TRACE,__wine_dbch_##ch)
190 #define WINE_WARN __WINE_DPRINTF(_WARN,__wine_dbch___default)
191 #define WINE_WARN_(ch) __WINE_DPRINTF(_WARN,__wine_dbch_##ch)
193 #define WINE_WARN_ON(ch) __WINE_GET_DEBUGGING(_WARN,__wine_dbch_##ch)
196 #define WINE_FIXME __WINE_DPRINTF(_FIXME,__wine_dbch___default)
197 #define WINE_FIXME_(ch) __WINE_DPRINTF(_FIXME,__wine_dbch_##ch)
199 #define WINE_FIXME_ON(ch) __WINE_GET_DEBUGGING(_FIXME,__wine_dbch_##ch)
201 #define WINE_ERR __WINE_DPRINTF(_ERR,__wine_dbch___default)
202 #define WINE_ERR_(ch) __WINE_DPRINTF(_ERR,__wine_dbch_##ch)
203 #define WINE_ERR_ON(ch) __WINE_GET_DEBUGGING(_ERR,__wine_dbch_##ch)
205 #define WINE_DECLARE_DEBUG_CHANNEL(ch) \
206 extern char __wine_dbch_##ch[]
207 #define WINE_DEFAULT_DEBUG_CHANNEL(ch) \
208 extern char __wine_dbch_##ch[]; \
209 static char * const __wine_dbch___default = __wine_dbch_##ch
211 #define WINE_DPRINTF wine_dbg_printf
212 #define WINE_MESSAGE wine_dbg_printf
215 /* Wine uses shorter names that are very likely to conflict with other software */
217 inline static const char *debugstr_an( const char * s, int n ) { return wine_dbgstr_an( s, n ); }
218 inline static const char *debugstr_wn( const WCHAR *s, int n ) { return wine_dbgstr_wn( s, n ); }
219 inline static const char *debugstr_guid( const struct _GUID *id ) { return wine_dbgstr_guid(id); }
220 inline static const char *debugstr_a( const char *s ) { return wine_dbgstr_an( s, -1 ); }
221 inline static const char *debugstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, -1 ); }
223 #define TRACE WINE_TRACE
224 #define TRACE_(ch) WINE_TRACE_(ch)
225 #define TRACE_ON(ch) WINE_TRACE_ON(ch)
227 #define WARN WINE_WARN
228 #define WARN_(ch) WINE_WARN_(ch)
229 #define WARN_ON(ch) WINE_WARN_ON(ch)
231 #define FIXME WINE_FIXME
232 #define FIXME_(ch) WINE_FIXME_(ch)
233 #define FIXME_ON(ch) WINE_FIXME_ON(ch)
235 #undef ERR /* Solaris got an 'ERR' define in <sys/reg.h> */
237 #define ERR_(ch) WINE_ERR_(ch)
238 #define ERR_ON(ch) WINE_ERR_ON(ch)
240 #define DPRINTF WINE_DPRINTF
241 #define MESSAGE WINE_MESSAGE
243 #endif /* __WINESRC__ */
249 #endif /* __WINE_WINE_DEBUG_H */