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
34 * Internal definitions (do not use these directly)
37 enum __WINE_DEBUG_CLASS {
46 # define __WINE_GET_DEBUGGING_TRACE(dbch) ((dbch)[0] & (1 << __WINE_DBCL_TRACE))
48 # define __WINE_GET_DEBUGGING_TRACE(dbch) 0
52 # define __WINE_GET_DEBUGGING_WARN(dbch) ((dbch)[0] & (1 << __WINE_DBCL_WARN))
53 # define __WINE_GET_DEBUGGING_FIXME(dbch) ((dbch)[0] & (1 << __WINE_DBCL_FIXME))
55 # define __WINE_GET_DEBUGGING_WARN(dbch) 0
56 # define __WINE_GET_DEBUGGING_FIXME(dbch) 0
59 /* define error macro regardless of what is configured */
60 #define __WINE_GET_DEBUGGING_ERR(dbch) ((dbch)[0] & (1 << __WINE_DBCL_ERR))
62 #define __WINE_GET_DEBUGGING(dbcl,dbch) __WINE_GET_DEBUGGING##dbcl(dbch)
63 #define __WINE_SET_DEBUGGING(dbcl,dbch,on) \
64 ((on) ? ((dbch)[0] |= 1 << (dbcl)) : ((dbch)[0] &= ~(1 << (dbcl))))
68 #define __WINE_DPRINTF(dbcl,dbch) \
69 do { if(__WINE_GET_DEBUGGING(dbcl,(dbch))) { \
70 const char * const __dbch = (dbch); \
71 const enum __WINE_DEBUG_CLASS __dbcl = __WINE_DBCL##dbcl; \
74 #define __WINE_DBG_LOG(args...) \
75 wine_dbg_log( __dbcl, __dbch, __FUNCTION__, args); } } while(0)
77 #define __WINE_PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
79 #elif defined(__SUNPRO_C)
81 #define __WINE_DPRINTF(dbcl,dbch) \
82 do { if(__WINE_GET_DEBUGGING(dbcl,(dbch))) { \
83 const char * const __dbch = (dbch); \
84 const enum __WINE_DEBUG_CLASS __dbcl = __WINE_DBCL##dbcl; \
87 #define __WINE_DBG_LOG(...) \
88 wine_dbg_log( __dbcl, __dbch, __func__, __VA_ARGS__); } } while(0)
90 #define __WINE_PRINTF_ATTR(fmt,args)
92 #else /* !__GNUC__ && !__SUNPRO_C */
94 #define __WINE_DPRINTF(dbcl,dbch) \
95 (!__WINE_GET_DEBUGGING(dbcl,(dbch)) || \
96 (wine_dbg_log(__WINE_DBCL##dbcl,(dbch),__FILE__,"%d: ",__LINE__),0)) ? \
97 (void)0 : (void)wine_dbg_printf
99 #define __WINE_PRINTF_ATTR(fmt, args)
101 #endif /* !__GNUC__ && !__SUNPRO_C */
105 * Exported definitions and macros
108 /* These function return a printable version of a string, including
109 quotes. The string will be valid for some time, but not indefinitely
110 as strings are re-used. */
111 extern const char *wine_dbgstr_guid( const struct _GUID *id );
112 extern const char *wine_dbgstr_an( const char * s, int n );
113 extern const char *wine_dbgstr_wn( const WCHAR *s, int n );
114 extern const char *wine_dbgstr_a( const char *s );
115 extern const char *wine_dbgstr_w( const WCHAR *s );
117 extern int wine_dbg_printf( const char *format, ... ) __WINE_PRINTF_ATTR(1,2);
118 extern int wine_dbg_log( int cls, const char *ch, const char *func,
119 const char *format, ... ) __WINE_PRINTF_ATTR(4,5);
121 #define WINE_TRACE __WINE_DPRINTF(_TRACE,__wine_dbch___default)
122 #define WINE_TRACE_(ch) __WINE_DPRINTF(_TRACE,__wine_dbch_##ch)
123 #define WINE_TRACE_ON(ch) __WINE_GET_DEBUGGING(_TRACE,__wine_dbch_##ch)
125 #define WINE_WARN __WINE_DPRINTF(_WARN,__wine_dbch___default)
126 #define WINE_WARN_(ch) __WINE_DPRINTF(_WARN,__wine_dbch_##ch)
127 #define WINE_WARN_ON(ch) __WINE_GET_DEBUGGING(_WARN,__wine_dbch_##ch)
129 #define WINE_FIXME __WINE_DPRINTF(_FIXME,__wine_dbch___default)
130 #define WINE_FIXME_(ch) __WINE_DPRINTF(_FIXME,__wine_dbch_##ch)
131 #define WINE_FIXME_ON(ch) __WINE_GET_DEBUGGING(_FIXME,__wine_dbch_##ch)
133 #define WINE_ERR __WINE_DPRINTF(_ERR,__wine_dbch___default)
134 #define WINE_ERR_(ch) __WINE_DPRINTF(_ERR,__wine_dbch_##ch)
135 #define WINE_ERR_ON(ch) __WINE_GET_DEBUGGING(_ERR,__wine_dbch_##ch)
137 #define WINE_DECLARE_DEBUG_CHANNEL(ch) \
138 extern char __wine_dbch_##ch[]
139 #define WINE_DEFAULT_DEBUG_CHANNEL(ch) \
140 extern char __wine_dbch_##ch[]; \
141 static char * const __wine_dbch___default = __wine_dbch_##ch
143 #define WINE_DPRINTF wine_dbg_printf
144 #define WINE_MESSAGE wine_dbg_printf
147 /* Wine uses shorter names that are very likely to conflict with other software */
149 inline static const char *debugstr_an( const char * s, int n ) { return wine_dbgstr_an( s, n ); }
150 inline static const char *debugstr_wn( const WCHAR *s, int n ) { return wine_dbgstr_wn( s, n ); }
151 inline static const char *debugstr_guid( const struct _GUID *id ) { return wine_dbgstr_guid(id); }
152 inline static const char *debugstr_a( const char *s ) { return wine_dbgstr_an( s, -1 ); }
153 inline static const char *debugstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, -1 ); }
155 #define TRACE WINE_TRACE
156 #define TRACE_(ch) WINE_TRACE_(ch)
157 #define TRACE_ON(ch) WINE_TRACE_ON(ch)
159 #define WARN WINE_WARN
160 #define WARN_(ch) WINE_WARN_(ch)
161 #define WARN_ON(ch) WINE_WARN_ON(ch)
163 #define FIXME WINE_FIXME
164 #define FIXME_(ch) WINE_FIXME_(ch)
165 #define FIXME_ON(ch) WINE_FIXME_ON(ch)
167 #undef ERR /* Solaris got an 'ERR' define in <sys/reg.h> */
169 #define ERR_(ch) WINE_ERR_(ch)
170 #define ERR_ON(ch) WINE_ERR_ON(ch)
172 #define DPRINTF WINE_DPRINTF
173 #define MESSAGE WINE_MESSAGE
175 #endif /* __WINE__ */
181 #endif /* __WINE_WINE_DEBUG_H */