Authors: Juraj Hercek <juraj@syncad.com>, Eric Frias <efrias@syncad.com>
[wine] / include / 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #ifndef __WINE_WINE_DEBUG_H
22 #define __WINE_WINE_DEBUG_H
23
24 #include <stdarg.h>
25 #include <windef.h>
26 #ifndef GUID_DEFINED
27 #include <guiddef.h>
28 #endif
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 struct _GUID;
35
36 /*
37  * Internal definitions (do not use these directly)
38  */
39
40 enum __WINE_DEBUG_CLASS {
41     __WINE_DBCL_FIXME,
42     __WINE_DBCL_ERR,
43     __WINE_DBCL_WARN,
44     __WINE_DBCL_TRACE,
45     __WINE_DBCL_COUNT
46 };
47
48 #ifndef NO_TRACE_MSGS
49 # define __WINE_GET_DEBUGGING_TRACE(dbch) ((dbch)[0] & (1 << __WINE_DBCL_TRACE))
50 #else
51 # define __WINE_GET_DEBUGGING_TRACE(dbch) 0
52 #endif
53
54 #ifndef 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))
57 #else
58 # define __WINE_GET_DEBUGGING_WARN(dbch)  0
59 # define __WINE_GET_DEBUGGING_FIXME(dbch) 0
60 #endif
61
62 /* define error macro regardless of what is configured */
63 #define __WINE_GET_DEBUGGING_ERR(dbch)  ((dbch)[0] & (1 << __WINE_DBCL_ERR))
64
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))))
68
69 #ifdef __GNUC__
70
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; \
75        __WINE_DBG_LOG
76
77 #define __WINE_DBG_LOG(args...) \
78     wine_dbg_log( __dbcl, __dbch, __FUNCTION__, args); } } while(0)
79
80 #define __WINE_PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
81
82
83 #ifdef NO_TRACE_MSGS
84 #define WINE_TRACE(args...) do { } while(0)
85 #define WINE_TRACE_(ch) WINE_TRACE
86 #endif
87
88 #ifdef 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
93 #endif
94
95 #elif defined(__SUNPRO_C)
96
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; \
101        __WINE_DBG_LOG
102
103 #define __WINE_DBG_LOG(...) \
104    wine_dbg_log( __dbcl, __dbch, __func__, __VA_ARGS__); } } while(0)
105
106 #define __WINE_PRINTF_ATTR(fmt,args)
107
108 #ifdef NO_TRACE_MSGS
109 #define WINE_TRACE(...) do { } while(0)
110 #define WINE_TRACE_(ch) WINE_TRACE
111 #endif
112
113 #ifdef 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
118 #endif
119
120 #else  /* !__GNUC__ && !__SUNPRO_C */
121
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
126
127 #define __WINE_PRINTF_ATTR(fmt, args)
128
129 #endif  /* !__GNUC__ && !__SUNPRO_C */
130
131
132 /*
133  * Exported definitions and macros
134  */
135
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);
144
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);
148
149 static inline const char *wine_dbgstr_guid( const GUID *id )
150 {
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] );
157 }
158
159 static inline const char *wine_dbgstr_point( const POINT *pt )
160 {
161     if (!pt) return "(null)";
162     return wine_dbg_sprintf( "(%ld,%ld)", pt->x, pt->y );
163 }
164
165 static inline const char *wine_dbgstr_size( const SIZE *size )
166 {
167     if (!size) return "(null)";
168     return wine_dbg_sprintf( "(%ld,%ld)", size->cx, size->cy );
169 }
170
171 static inline const char *wine_dbgstr_rect( const RECT *rect )
172 {
173     if (!rect) return "(null)";
174     return wine_dbg_sprintf( "(%ld,%ld)-(%ld,%ld)", rect->left, rect->top, rect->right, rect->bottom );
175 }
176
177 #ifndef WINE_TRACE
178 #define WINE_TRACE                 __WINE_DPRINTF(_TRACE,__wine_dbch___default)
179 #define WINE_TRACE_(ch)            __WINE_DPRINTF(_TRACE,__wine_dbch_##ch)
180 #endif
181 #define WINE_TRACE_ON(ch)          __WINE_GET_DEBUGGING(_TRACE,__wine_dbch_##ch)
182
183 #ifndef WINE_WARN
184 #define WINE_WARN                  __WINE_DPRINTF(_WARN,__wine_dbch___default)
185 #define WINE_WARN_(ch)             __WINE_DPRINTF(_WARN,__wine_dbch_##ch)
186 #endif
187 #define WINE_WARN_ON(ch)           __WINE_GET_DEBUGGING(_WARN,__wine_dbch_##ch)
188
189 #ifndef WINE_FIXME
190 #define WINE_FIXME                 __WINE_DPRINTF(_FIXME,__wine_dbch___default)
191 #define WINE_FIXME_(ch)            __WINE_DPRINTF(_FIXME,__wine_dbch_##ch)
192 #endif
193 #define WINE_FIXME_ON(ch)          __WINE_GET_DEBUGGING(_FIXME,__wine_dbch_##ch)
194
195 #define WINE_ERR                   __WINE_DPRINTF(_ERR,__wine_dbch___default)
196 #define WINE_ERR_(ch)              __WINE_DPRINTF(_ERR,__wine_dbch_##ch)
197 #define WINE_ERR_ON(ch)            __WINE_GET_DEBUGGING(_ERR,__wine_dbch_##ch)
198
199 #define WINE_DECLARE_DEBUG_CHANNEL(ch) \
200     extern char __wine_dbch_##ch[]
201 #define WINE_DEFAULT_DEBUG_CHANNEL(ch) \
202     extern char __wine_dbch_##ch[]; \
203     static char * const __wine_dbch___default = __wine_dbch_##ch
204
205 #define WINE_DPRINTF               wine_dbg_printf
206 #define WINE_MESSAGE               wine_dbg_printf
207
208 #ifdef __WINESRC__
209 /* Wine uses shorter names that are very likely to conflict with other software */
210
211 inline static const char *debugstr_an( const char * s, int n ) { return wine_dbgstr_an( s, n ); }
212 inline static const char *debugstr_wn( const WCHAR *s, int n ) { return wine_dbgstr_wn( s, n ); }
213 inline static const char *debugstr_guid( const struct _GUID *id ) { return wine_dbgstr_guid(id); }
214 inline static const char *debugstr_a( const char *s )  { return wine_dbgstr_an( s, -1 ); }
215 inline static const char *debugstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, -1 ); }
216
217 #define TRACE                      WINE_TRACE
218 #define TRACE_(ch)                 WINE_TRACE_(ch)
219 #define TRACE_ON(ch)               WINE_TRACE_ON(ch)
220
221 #define WARN                       WINE_WARN
222 #define WARN_(ch)                  WINE_WARN_(ch)
223 #define WARN_ON(ch)                WINE_WARN_ON(ch)
224
225 #define FIXME                      WINE_FIXME
226 #define FIXME_(ch)                 WINE_FIXME_(ch)
227 #define FIXME_ON(ch)               WINE_FIXME_ON(ch)
228
229 #undef ERR  /* Solaris got an 'ERR' define in <sys/reg.h> */
230 #define ERR                        WINE_ERR
231 #define ERR_(ch)                   WINE_ERR_(ch)
232 #define ERR_ON(ch)                 WINE_ERR_ON(ch)
233
234 #define DPRINTF                    WINE_DPRINTF
235 #define MESSAGE                    WINE_MESSAGE
236
237 #endif /* __WINESRC__ */
238
239 #ifdef __cplusplus
240 }
241 #endif
242
243 #endif  /* __WINE_WINE_DEBUG_H */