[LIBWINE]
[reactos.git] / reactos / include / reactos / 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #ifndef __WINE_DEBUG_H
22 #define __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 __WINE_WINE_TEST_H
31 #error This file should not be used in Wine tests
32 #endif
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 struct _GUID;
39
40 /*
41 * Internal definitions (do not use these directly)
42 */
43
44 enum __wine_debug_class
45 {
46 __WINE_DBCL_FIXME = 0, /* 0x1 */
47 __WINE_DBCL_ERR = 1, /* 0x2 */
48 __WINE_DBCL_WARN = 2, /* 0x4 */
49 __WINE_DBCL_TRACE = 3, /* 0x8 */
50
51 /* lazy init flag */
52 __WINE_DBCL_INIT = 0x7
53 };
54
55 struct __wine_debug_channel
56 {
57 unsigned char flags;
58 char name[15];
59 };
60
61 #define UNIMPLEMENTED WINE_FIXME("%s is UNIMPLEMENTED!\n", __FUNCTION__)
62
63 #ifndef WINE_NO_TRACE_MSGS
64 # define __WINE_GET_DEBUGGING_TRACE(dbch) ((dbch)->flags & (1 << __WINE_DBCL_TRACE))
65 #else
66 # define __WINE_GET_DEBUGGING_TRACE(dbch) 0
67 #endif
68
69 #ifndef WINE_NO_DEBUG_MSGS
70 # define __WINE_GET_DEBUGGING_WARN(dbch) ((dbch)->flags & (1 << __WINE_DBCL_WARN))
71 # define __WINE_GET_DEBUGGING_FIXME(dbch) ((dbch)->flags & (1 << __WINE_DBCL_FIXME))
72 #else
73 # define __WINE_GET_DEBUGGING_WARN(dbch) 0
74 # define __WINE_GET_DEBUGGING_FIXME(dbch) 0
75 #endif
76
77 /* define error macro regardless of what is configured */
78 #define __WINE_GET_DEBUGGING_ERR(dbch) ((dbch)->flags & (1 << __WINE_DBCL_ERR))
79
80 #define __WINE_GET_DEBUGGING(dbcl,dbch) __WINE_GET_DEBUGGING##dbcl(dbch)
81
82 #define __WINE_IS_DEBUG_ON(dbcl,dbch) \
83 (__WINE_GET_DEBUGGING##dbcl(dbch) && (__wine_dbg_get_channel_flags(dbch) & (1 << __WINE_DBCL##dbcl)))
84
85 #ifdef __GNUC__
86
87 #define __WINE_DPRINTF(dbcl,dbch) \
88 do { if(__WINE_GET_DEBUGGING(dbcl,(dbch))) { \
89 struct __wine_debug_channel * const __dbch = (dbch); \
90 const enum __wine_debug_class __dbcl = __WINE_DBCL##dbcl; \
91 __WINE_DBG_LOG
92
93 #define __WINE_DBG_LOG(args...) \
94 ros_dbg_log( __dbcl, __dbch, __FILE__, __FUNCTION__, __LINE__, args); } } while(0)
95
96 #define __WINE_PRINTF_ATTR(fmt,args) /*__attribute__((format (printf,fmt,args)))*/
97
98
99 #ifdef WINE_NO_TRACE_MSGS
100 #define WINE_TRACE(args...) do { } while(0)
101 #define WINE_TRACE_(ch) WINE_TRACE
102 #endif
103
104 #ifdef WINE_NO_DEBUG_MSGS
105 #define WINE_WARN(args...) do { } while(0)
106 #define WINE_WARN_(ch) WINE_WARN
107 #define WINE_FIXME(args...) do { } while(0)
108 #define WINE_FIXME_(ch) WINE_FIXME
109 #endif
110
111 #elif defined(__SUNPRO_C)
112
113 #define __WINE_DPRINTF(dbcl,dbch) \
114 do { if(__WINE_GET_DEBUGGING(dbcl,(dbch))) { \
115 struct __wine_debug_channel * const __dbch = (dbch); \
116 const enum __WINE_DEBUG_CLASS __dbcl = __WINE_DBCL##dbcl; \
117 __WINE_DBG_LOG
118
119 #define __WINE_DBG_LOG(...) \
120 wine_dbg_log( __dbcl, __dbch, __func__, __VA_ARGS__); } } while(0)
121
122 #define __WINE_PRINTF_ATTR(fmt,args)
123
124 #ifdef WINE_NO_TRACE_MSGS
125 #define WINE_TRACE(...) do { } while(0)
126 #define WINE_TRACE_(ch) WINE_TRACE
127 #endif
128
129 #ifdef WINE_NO_DEBUG_MSGS
130 #define WINE_WARN(...) do { } while(0)
131 #define WINE_WARN_(ch) WINE_WARN
132 #define WINE_FIXME(...) do { } while(0)
133 #define WINE_FIXME_(ch) WINE_FIXME
134 #endif
135
136 #else /* !__GNUC__ && !__SUNPRO_C */
137
138 #define __WINE_DPRINTF(dbcl,dbch) \
139 (!__WINE_GET_DEBUGGING(dbcl,(dbch)) || \
140 (ros_dbg_log(__WINE_DBCL##dbcl,(dbch),__FILE__,"",__LINE__,"") == -1)) ? \
141 (void)0 : (void)wine_dbg_printf
142
143 #define __WINE_PRINTF_ATTR(fmt, args)
144
145 #endif /* !__GNUC__ && !__SUNPRO_C */
146
147 struct __wine_debug_functions
148 {
149 char * (*get_temp_buffer)( size_t n );
150 void (*release_temp_buffer)( char *buffer, size_t n );
151 const char * (*dbgstr_an)( const char * s, int n );
152 const char * (*dbgstr_wn)( const WCHAR *s, int n );
153 int (*dbg_vprintf)( const char *format, va_list args );
154 int (*dbg_vlog)( enum __wine_debug_class cls, struct __wine_debug_channel *channel,
155 const char *file, const char *function, const int line, const char *format, va_list args );
156 };
157
158 extern unsigned char __wine_dbg_get_channel_flags( struct __wine_debug_channel *channel );
159 extern int __wine_dbg_set_channel_flags( struct __wine_debug_channel *channel,
160 unsigned char set, unsigned char clear );
161 extern void __wine_dbg_set_functions( const struct __wine_debug_functions *new_funcs,
162 struct __wine_debug_functions *old_funcs, size_t size );
163
164 /*
165 * Exported definitions and macros
166 */
167
168 /* These functions return a printable version of a string, including
169 quotes. The string will be valid for some time, but not indefinitely
170 as strings are re-used. */
171 extern const char *wine_dbgstr_an( const char * s, int n );
172 extern const char *wine_dbgstr_wn( const WCHAR *s, int n );
173 extern const char *wine_dbg_sprintf( const char *format, ... ) __WINE_PRINTF_ATTR(1,2);
174
175 extern int wine_dbg_printf( const char *format, ... ) __WINE_PRINTF_ATTR(1,2);
176 extern int wine_dbg_log( enum __wine_debug_class cls, struct __wine_debug_channel *ch, const char *func,
177 const char *format, ... ) __WINE_PRINTF_ATTR(4,5);
178 /* ReactOS compliant debug format */
179 extern int ros_dbg_log( enum __wine_debug_class cls, struct __wine_debug_channel *ch, const char *file,
180 const char *func, const int line, const char *format, ... ) __WINE_PRINTF_ATTR(6,7);
181
182 static __inline const char *wine_dbgstr_a( const char *s )
183 {
184 return wine_dbgstr_an( s, -1 );
185 }
186
187 static __inline const char *wine_dbgstr_w( const WCHAR *s )
188 {
189 return wine_dbgstr_wn( s, -1 );
190 }
191
192 static __inline const char *wine_dbgstr_guid( const GUID *id )
193 {
194 if (!id) return "(null)";
195 if (!((ULONG_PTR)id >> 16)) return wine_dbg_sprintf( "<guid-0x%04lx>", (ULONG_PTR)id & 0xffff );
196 return wine_dbg_sprintf( "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
197 id->Data1, id->Data2, id->Data3,
198 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
199 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
200 }
201
202 static __inline const char *wine_dbgstr_point( const POINT *pt )
203 {
204 if (!pt) return "(null)";
205 return wine_dbg_sprintf( "(%ld,%ld)", pt->x, pt->y );
206 }
207
208 static __inline const char *wine_dbgstr_size( const SIZE *size )
209 {
210 if (!size) return "(null)";
211 return wine_dbg_sprintf( "(%ld,%ld)", size->cx, size->cy );
212 }
213
214 static __inline const char *wine_dbgstr_rect( const RECT *rect )
215 {
216 if (!rect) return "(null)";
217 return wine_dbg_sprintf( "(%ld,%ld)-(%ld,%ld)", rect->left, rect->top,
218 rect->right, rect->bottom );
219 }
220
221 static __inline const char *wine_dbgstr_longlong( ULONGLONG ll )
222 {
223 if (/*sizeof(ll) > sizeof(unsigned long) &&*/ ll >> 32) /* ULONGLONG is always > long in ReactOS */
224 return wine_dbg_sprintf( "%lx%08lx", (unsigned long)(ll >> 32), (unsigned long)ll );
225 else return wine_dbg_sprintf( "%lx", (unsigned long)ll );
226 }
227
228 #ifndef WINE_TRACE
229 #define WINE_TRACE __WINE_DPRINTF(_TRACE,__wine_dbch___default)
230 #define WINE_TRACE_(ch) __WINE_DPRINTF(_TRACE,&__wine_dbch_##ch)
231 #endif
232 #define WINE_TRACE_ON(ch) __WINE_IS_DEBUG_ON(_TRACE,&__wine_dbch_##ch)
233
234 #ifndef WINE_WARN
235 #define WINE_WARN __WINE_DPRINTF(_WARN,__wine_dbch___default)
236 #define WINE_WARN_(ch) __WINE_DPRINTF(_WARN,&__wine_dbch_##ch)
237 #endif
238 #define WINE_WARN_ON(ch) __WINE_IS_DEBUG_ON(_WARN,&__wine_dbch_##ch)
239
240 #ifndef WINE_FIXME
241 #define WINE_FIXME __WINE_DPRINTF(_FIXME,__wine_dbch___default)
242 #define WINE_FIXME_(ch) __WINE_DPRINTF(_FIXME,&__wine_dbch_##ch)
243 #endif
244 #define WINE_FIXME_ON(ch) __WINE_IS_DEBUG_ON(_FIXME,&__wine_dbch_##ch)
245
246 #define WINE_ERR __WINE_DPRINTF(_ERR,__wine_dbch___default)
247 #define WINE_ERR_(ch) __WINE_DPRINTF(_ERR,&__wine_dbch_##ch)
248 #define WINE_ERR_ON(ch) __WINE_IS_DEBUG_ON(_ERR,&__wine_dbch_##ch)
249
250 #define WINE_DECLARE_DEBUG_CHANNEL(ch) \
251 static struct __wine_debug_channel __wine_dbch_##ch = { (unsigned char)~0, #ch }
252 #define WINE_DEFAULT_DEBUG_CHANNEL(ch) \
253 static struct __wine_debug_channel __wine_dbch_##ch = { (unsigned char)~0, #ch }; \
254 static struct __wine_debug_channel * const __wine_dbch___default = &__wine_dbch_##ch
255
256 #define WINE_DPRINTF wine_dbg_printf
257 #define WINE_MESSAGE wine_dbg_printf
258
259 /* Wine uses shorter names that are very likely to conflict with other software */
260
261 static __inline const char *debugstr_an( const char * s, int n ) { return wine_dbgstr_an( s, n ); }
262 static __inline const char *debugstr_wn( const WCHAR *s, int n ) { return wine_dbgstr_wn( s, n ); }
263 static __inline const char *debugstr_guid( const struct _GUID *id ) { return wine_dbgstr_guid(id); }
264 static __inline const char *debugstr_a( const char *s ) { return wine_dbgstr_an( s, -1 ); }
265 static __inline const char *debugstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, -1 ); }
266
267 #define TRACE WINE_TRACE
268 #define TRACE_(ch) WINE_TRACE_(ch)
269 #define TRACE_ON(ch) WINE_TRACE_ON(ch)
270
271 #define WARN WINE_WARN
272 #define WARN_(ch) WINE_WARN_(ch)
273 #define WARN_ON(ch) WINE_WARN_ON(ch)
274
275 #define FIXME WINE_FIXME
276 #define FIXME_(ch) WINE_FIXME_(ch)
277 #define FIXME_ON(ch) WINE_FIXME_ON(ch)
278
279 #undef ERR /* Solaris got an 'ERR' define in <sys/reg.h> */
280 #define ERR WINE_ERR
281 #define ERR_(ch) WINE_ERR_(ch)
282 #define ERR_ON(ch) WINE_ERR_ON(ch)
283
284 #define DPRINTF WINE_DPRINTF
285 #define MESSAGE WINE_MESSAGE
286
287 #ifdef __cplusplus
288 }
289 #endif
290
291 #endif /* __WINE_DEBUG_H */