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 | /*
|
---|
22 | * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
23 | * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
|
---|
24 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
25 | * a choice of LGPL license versions is made available with the language indicating
|
---|
26 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
27 | * of the LGPL is applied is otherwise unspecified.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #ifndef __WINE_WINE_DEBUG_H
|
---|
31 | #define __WINE_WINE_DEBUG_H
|
---|
32 |
|
---|
33 | #if defined(VBOX_WITH_WDDM) || defined(VBOX_WINE_WITH_IPRT)
|
---|
34 | # error "Unexpected include! VBOX_WITH_WDDM or VBOX_WINE_WITH_IPRT are defined!"
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | #ifdef VBOX_WINE_WITH_IPRT
|
---|
38 | # include <iprt/assert.h>
|
---|
39 | #else
|
---|
40 | # define AssertBreakpoint() do { } while (0)
|
---|
41 | # define Assert(_expr) do { } while (0)
|
---|
42 | # ifdef DEBUG_misha
|
---|
43 | # include <iprt/cdefs.h>
|
---|
44 | # endif
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | #include <stdarg.h>
|
---|
48 | #include <windef.h>
|
---|
49 | #ifndef GUID_DEFINED
|
---|
50 | #include <guiddef.h>
|
---|
51 | #endif
|
---|
52 |
|
---|
53 | #include <iprt/assert.h>
|
---|
54 |
|
---|
55 | #ifdef __WINE_WINE_TEST_H
|
---|
56 | #error This file should not be used in Wine tests
|
---|
57 | #endif
|
---|
58 |
|
---|
59 | #ifdef __cplusplus
|
---|
60 | extern "C" {
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | struct _GUID;
|
---|
64 |
|
---|
65 | #ifdef DEBUG
|
---|
66 | # define VBOX_WINE_DEBUG
|
---|
67 | #endif
|
---|
68 |
|
---|
69 | #ifdef VBOX_WINE_DEBUG
|
---|
70 | # ifndef VBOX_WINE_DEBUG_DEFINES
|
---|
71 | extern DWORD g_VBoxVDbgBreakOnD3DErr;
|
---|
72 | # else
|
---|
73 | # ifdef DEBUG_misha
|
---|
74 | # define _ERR_BREAK_DEFAULT 1
|
---|
75 | # else
|
---|
76 | # define _ERR_BREAK_DEFAULT 0
|
---|
77 | # endif
|
---|
78 | DWORD g_VBoxVDbgBreakOnD3DErr = _ERR_BREAK_DEFAULT;
|
---|
79 | # endif
|
---|
80 |
|
---|
81 | # define _ERR_BREAK() Assert(0)
|
---|
82 | # define _ERR_ASSERT(_e) Assert((_e))
|
---|
83 | # define _ERR_CHECK_BREAK(_t) do { \
|
---|
84 | if (g_VBoxVDbgBreakOn##_t) { _ERR_BREAK(); } \
|
---|
85 | } while (0)
|
---|
86 | # define _ERR_CHECK_ASSERT(_t, _e) do { \
|
---|
87 | if (g_VBoxVDbgBreakOn##_t) { _ERR_ASSERT(_e); } \
|
---|
88 | } while (0)
|
---|
89 |
|
---|
90 | # define ERR_D3D() _ERR_CHECK_BREAK(D3DErr)
|
---|
91 | # define ASSERT_D3D(_e) _ERR_CHECK_ASSERT(D3DErr, _e)
|
---|
92 | #else
|
---|
93 | # define ERR_D3D() do {} while (0)
|
---|
94 | # define ASSERT_D3D(_e) do {} while (0)
|
---|
95 | #endif /* #ifdef VBOX_WINE_DEBUG */
|
---|
96 |
|
---|
97 | /*
|
---|
98 | * Internal definitions (do not use these directly)
|
---|
99 | */
|
---|
100 |
|
---|
101 | enum __wine_debug_class
|
---|
102 | {
|
---|
103 | __WINE_DBCL_FIXME,
|
---|
104 | __WINE_DBCL_ERR,
|
---|
105 | __WINE_DBCL_WARN,
|
---|
106 | __WINE_DBCL_TRACE,
|
---|
107 |
|
---|
108 | __WINE_DBCL_INIT = 7 /* lazy init flag */
|
---|
109 | };
|
---|
110 |
|
---|
111 | struct __wine_debug_channel
|
---|
112 | {
|
---|
113 | unsigned char flags;
|
---|
114 | char name[15];
|
---|
115 | };
|
---|
116 |
|
---|
117 | #ifndef WINE_NO_TRACE_MSGS
|
---|
118 | # define __WINE_GET_DEBUGGING_TRACE(dbch) ((dbch)->flags & (1 << __WINE_DBCL_TRACE))
|
---|
119 | #else
|
---|
120 | # define __WINE_GET_DEBUGGING_TRACE(dbch) 0
|
---|
121 | #endif
|
---|
122 |
|
---|
123 | #ifndef WINE_NO_DEBUG_MSGS
|
---|
124 | # define __WINE_GET_DEBUGGING_WARN(dbch) ((dbch)->flags & (1 << __WINE_DBCL_WARN))
|
---|
125 | # if 0 && defined(DEBUG_misha)
|
---|
126 | # define __WINE_GET_DEBUGGING_FIXME(dbch) (RT_BREAKPOINT(), ((dbch)->flags & (1 << __WINE_DBCL_FIXME)))
|
---|
127 | # else
|
---|
128 | # define __WINE_GET_DEBUGGING_FIXME(dbch) ((dbch)->flags & (1 << __WINE_DBCL_FIXME))
|
---|
129 | # endif
|
---|
130 | #else
|
---|
131 | # define __WINE_GET_DEBUGGING_WARN(dbch) 0
|
---|
132 | # if 0 && defined(DEBUG_misha)
|
---|
133 | # define __WINE_GET_DEBUGGING_FIXME(dbch) (RT_BREAKPOINT(), 0)
|
---|
134 | # else
|
---|
135 | # define __WINE_GET_DEBUGGING_FIXME(dbch) 0
|
---|
136 | # endif
|
---|
137 | #endif
|
---|
138 |
|
---|
139 | /* define error macro regardless of what is configured */
|
---|
140 | #if defined(DEBUG_misha)
|
---|
141 | #define __WINE_GET_DEBUGGING_ERR(dbch) (RT_BREAKPOINT(), ((dbch)->flags & (1 << __WINE_DBCL_ERR)))
|
---|
142 | #else
|
---|
143 | #define __WINE_GET_DEBUGGING_ERR(dbch) ((dbch)->flags & (1 << __WINE_DBCL_ERR))
|
---|
144 | #endif
|
---|
145 |
|
---|
146 | #define __WINE_GET_DEBUGGING(dbcl,dbch) __WINE_GET_DEBUGGING##dbcl(dbch)
|
---|
147 |
|
---|
148 | #define __WINE_IS_DEBUG_ON(dbcl,dbch) \
|
---|
149 | (__WINE_GET_DEBUGGING##dbcl(dbch) && (__wine_dbg_get_channel_flags(dbch) & (1 << __WINE_DBCL##dbcl)))
|
---|
150 |
|
---|
151 | #ifdef __GNUC__
|
---|
152 |
|
---|
153 | #define __WINE_DPRINTF(dbcl,dbch) \
|
---|
154 | do { if(__WINE_GET_DEBUGGING(dbcl,(dbch))) { \
|
---|
155 | struct __wine_debug_channel * const __dbch = (dbch); \
|
---|
156 | const enum __wine_debug_class __dbcl = __WINE_DBCL##dbcl; \
|
---|
157 | __WINE_DBG_LOG
|
---|
158 |
|
---|
159 | #define __WINE_DBG_LOG(args...) \
|
---|
160 | wine_dbg_log( __dbcl, __dbch, __FUNCTION__, args); } } while(0)
|
---|
161 |
|
---|
162 | #define __WINE_PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
|
---|
163 |
|
---|
164 |
|
---|
165 | #ifdef WINE_NO_TRACE_MSGS
|
---|
166 | #define WINE_TRACE(args...) do { } while(0)
|
---|
167 | #define WINE_TRACE_(ch) WINE_TRACE
|
---|
168 | #endif
|
---|
169 |
|
---|
170 | #ifdef WINE_NO_DEBUG_MSGS
|
---|
171 | #define WINE_WARN(args...) do { } while(0)
|
---|
172 | #define WINE_WARN_(ch) WINE_WARN
|
---|
173 | #define WINE_FIXME(args...) do { } while(0)
|
---|
174 | #define WINE_FIXME_(ch) WINE_FIXME
|
---|
175 | #endif
|
---|
176 |
|
---|
177 | #elif defined(__SUNPRO_C)
|
---|
178 |
|
---|
179 | #define __WINE_DPRINTF(dbcl,dbch) \
|
---|
180 | do { if(__WINE_GET_DEBUGGING(dbcl,(dbch))) { \
|
---|
181 | struct __wine_debug_channel * const __dbch = (dbch); \
|
---|
182 | const enum __WINE_DEBUG_CLASS __dbcl = __WINE_DBCL##dbcl; \
|
---|
183 | __WINE_DBG_LOG
|
---|
184 |
|
---|
185 | #define __WINE_DBG_LOG(...) \
|
---|
186 | wine_dbg_log( __dbcl, __dbch, __func__, __VA_ARGS__); } } while(0)
|
---|
187 |
|
---|
188 | #define __WINE_PRINTF_ATTR(fmt,args)
|
---|
189 |
|
---|
190 | #ifdef WINE_NO_TRACE_MSGS
|
---|
191 | #define WINE_TRACE(...) do { } while(0)
|
---|
192 | #define WINE_TRACE_(ch) WINE_TRACE
|
---|
193 | #endif
|
---|
194 |
|
---|
195 | #ifdef WINE_NO_DEBUG_MSGS
|
---|
196 | #define WINE_WARN(...) do { } while(0)
|
---|
197 | #define WINE_WARN_(ch) WINE_WARN
|
---|
198 | #define WINE_FIXME(...) do { } while(0)
|
---|
199 | #define WINE_FIXME_(ch) WINE_FIXME
|
---|
200 | #endif
|
---|
201 |
|
---|
202 | #else /* !__GNUC__ && !__SUNPRO_C */
|
---|
203 |
|
---|
204 | #define __WINE_DPRINTF(dbcl,dbch) \
|
---|
205 | (!__WINE_GET_DEBUGGING(dbcl,(dbch)) || \
|
---|
206 | (wine_dbg_log(__WINE_DBCL##dbcl,(dbch),__FILE__,"%d: ",__LINE__) == -1)) ? \
|
---|
207 | (void)0 : (void)wine_dbg_printf
|
---|
208 |
|
---|
209 | #define __WINE_PRINTF_ATTR(fmt, args)
|
---|
210 |
|
---|
211 | #endif /* !__GNUC__ && !__SUNPRO_C */
|
---|
212 |
|
---|
213 | struct __wine_debug_functions
|
---|
214 | {
|
---|
215 | char * (*get_temp_buffer)( size_t n );
|
---|
216 | void (*release_temp_buffer)( char *buffer, size_t n );
|
---|
217 | const char * (*dbgstr_an)( const char * s, int n );
|
---|
218 | const char * (*dbgstr_wn)( const WCHAR *s, int n );
|
---|
219 | int (*dbg_vprintf)( const char *format, va_list args );
|
---|
220 | int (*dbg_vlog)( enum __wine_debug_class cls, struct __wine_debug_channel *channel,
|
---|
221 | const char *function, const char *format, va_list args );
|
---|
222 | };
|
---|
223 |
|
---|
224 | extern unsigned char __wine_dbg_get_channel_flags( struct __wine_debug_channel *channel );
|
---|
225 | extern int __wine_dbg_set_channel_flags( struct __wine_debug_channel *channel,
|
---|
226 | unsigned char set, unsigned char clear );
|
---|
227 | extern void __wine_dbg_set_functions( const struct __wine_debug_functions *new_funcs,
|
---|
228 | struct __wine_debug_functions *old_funcs, size_t size );
|
---|
229 |
|
---|
230 | /*
|
---|
231 | * Exported definitions and macros
|
---|
232 | */
|
---|
233 |
|
---|
234 | /* These functions return a printable version of a string, including
|
---|
235 | quotes. The string will be valid for some time, but not indefinitely
|
---|
236 | as strings are re-used. */
|
---|
237 | extern const char *wine_dbgstr_an( const char * s, int n );
|
---|
238 | extern const char *wine_dbgstr_wn( const WCHAR *s, int n );
|
---|
239 | extern const char *wine_dbg_sprintf( const char *format, ... ) __WINE_PRINTF_ATTR(1,2);
|
---|
240 |
|
---|
241 | extern int wine_dbg_printf( const char *format, ... ) __WINE_PRINTF_ATTR(1,2);
|
---|
242 | extern int wine_dbg_log( enum __wine_debug_class cls, struct __wine_debug_channel *ch, const char *func,
|
---|
243 | const char *format, ... ) __WINE_PRINTF_ATTR(4,5);
|
---|
244 |
|
---|
245 | static inline const char *wine_dbgstr_a( const char *s )
|
---|
246 | {
|
---|
247 | return wine_dbgstr_an( s, -1 );
|
---|
248 | }
|
---|
249 |
|
---|
250 | static inline const char *wine_dbgstr_w( const WCHAR *s )
|
---|
251 | {
|
---|
252 | return wine_dbgstr_wn( s, -1 );
|
---|
253 | }
|
---|
254 |
|
---|
255 | static inline const char *wine_dbgstr_guid( const GUID *id )
|
---|
256 | {
|
---|
257 | if (!id) return "(null)";
|
---|
258 | if (!((ULONG_PTR)id >> 16)) return wine_dbg_sprintf( "<guid-0x%04hx>", (WORD)(ULONG_PTR)id );
|
---|
259 | return wine_dbg_sprintf( "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
|
---|
260 | id->Data1, id->Data2, id->Data3,
|
---|
261 | id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
|
---|
262 | id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
|
---|
263 | }
|
---|
264 |
|
---|
265 | static inline const char *wine_dbgstr_point( const POINT *pt )
|
---|
266 | {
|
---|
267 | if (!pt) return "(null)";
|
---|
268 | return wine_dbg_sprintf( "(%d,%d)", pt->x, pt->y );
|
---|
269 | }
|
---|
270 |
|
---|
271 | static inline const char *wine_dbgstr_size( const SIZE *size )
|
---|
272 | {
|
---|
273 | if (!size) return "(null)";
|
---|
274 | return wine_dbg_sprintf( "(%d,%d)", size->cx, size->cy );
|
---|
275 | }
|
---|
276 |
|
---|
277 | static inline const char *wine_dbgstr_rect( const RECT *rect )
|
---|
278 | {
|
---|
279 | if (!rect) return "(null)";
|
---|
280 | return wine_dbg_sprintf( "(%d,%d)-(%d,%d)", rect->left, rect->top,
|
---|
281 | rect->right, rect->bottom );
|
---|
282 | }
|
---|
283 |
|
---|
284 | static inline const char *wine_dbgstr_longlong( ULONGLONG ll )
|
---|
285 | {
|
---|
286 | if (sizeof(ll) > sizeof(unsigned long) && ll >> 32)
|
---|
287 | return wine_dbg_sprintf( "%lx%08lx", (unsigned long)(ll >> 32), (unsigned long)ll );
|
---|
288 | else return wine_dbg_sprintf( "%lx", (unsigned long)ll );
|
---|
289 | }
|
---|
290 |
|
---|
291 | #ifndef WINE_TRACE
|
---|
292 | #define WINE_TRACE __WINE_DPRINTF(_TRACE,__wine_dbch___default)
|
---|
293 | #define WINE_TRACE_(ch) __WINE_DPRINTF(_TRACE,&__wine_dbch_##ch)
|
---|
294 | #endif
|
---|
295 | #define WINE_TRACE_ON(ch) __WINE_IS_DEBUG_ON(_TRACE,&__wine_dbch_##ch)
|
---|
296 |
|
---|
297 | #ifndef WINE_WARN
|
---|
298 | #define WINE_WARN __WINE_DPRINTF(_WARN,__wine_dbch___default)
|
---|
299 | #define WINE_WARN_(ch) __WINE_DPRINTF(_WARN,&__wine_dbch_##ch)
|
---|
300 | #endif
|
---|
301 | #define WINE_WARN_ON(ch) __WINE_IS_DEBUG_ON(_WARN,&__wine_dbch_##ch)
|
---|
302 |
|
---|
303 | #ifndef WINE_FIXME
|
---|
304 | #define WINE_FIXME __WINE_DPRINTF(_FIXME,__wine_dbch___default)
|
---|
305 | #define WINE_FIXME_(ch) __WINE_DPRINTF(_FIXME,&__wine_dbch_##ch)
|
---|
306 | #endif
|
---|
307 | #define WINE_FIXME_ON(ch) __WINE_IS_DEBUG_ON(_FIXME,&__wine_dbch_##ch)
|
---|
308 |
|
---|
309 | #define WINE_ERR __WINE_DPRINTF(_ERR,__wine_dbch___default)
|
---|
310 | #define WINE_ERR_(ch) __WINE_DPRINTF(_ERR,&__wine_dbch_##ch)
|
---|
311 | #define WINE_ERR_ON(ch) __WINE_IS_DEBUG_ON(_ERR,&__wine_dbch_##ch)
|
---|
312 |
|
---|
313 | #define WINE_DECLARE_DEBUG_CHANNEL(ch) \
|
---|
314 | static struct __wine_debug_channel __wine_dbch_##ch = { ~0, #ch }
|
---|
315 | #define WINE_DEFAULT_DEBUG_CHANNEL(ch) \
|
---|
316 | static struct __wine_debug_channel __wine_dbch_##ch = { ~0, #ch }; \
|
---|
317 | static struct __wine_debug_channel * const __wine_dbch___default = &__wine_dbch_##ch
|
---|
318 |
|
---|
319 | #define WINE_DPRINTF wine_dbg_printf
|
---|
320 | #define WINE_MESSAGE wine_dbg_printf
|
---|
321 |
|
---|
322 | #ifdef __WINESRC__
|
---|
323 | /* Wine uses shorter names that are very likely to conflict with other software */
|
---|
324 |
|
---|
325 | static inline const char *debugstr_an( const char * s, int n ) { return wine_dbgstr_an( s, n ); }
|
---|
326 | static inline const char *debugstr_wn( const WCHAR *s, int n ) { return wine_dbgstr_wn( s, n ); }
|
---|
327 | static inline const char *debugstr_guid( const struct _GUID *id ) { return wine_dbgstr_guid(id); }
|
---|
328 | static inline const char *debugstr_a( const char *s ) { return wine_dbgstr_an( s, -1 ); }
|
---|
329 | static inline const char *debugstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, -1 ); }
|
---|
330 |
|
---|
331 | #define TRACE WINE_TRACE
|
---|
332 | #define TRACE_(ch) WINE_TRACE_(ch)
|
---|
333 | #define TRACE_ON(ch) WINE_TRACE_ON(ch)
|
---|
334 |
|
---|
335 | #define WARN WINE_WARN
|
---|
336 | #define WARN_(ch) WINE_WARN_(ch)
|
---|
337 | #define WARN_ON(ch) WINE_WARN_ON(ch)
|
---|
338 |
|
---|
339 | #define FIXME WINE_FIXME
|
---|
340 | #define FIXME_(ch) WINE_FIXME_(ch)
|
---|
341 | #define FIXME_ON(ch) WINE_FIXME_ON(ch)
|
---|
342 |
|
---|
343 | #undef ERR /* Solaris got an 'ERR' define in <sys/reg.h> */
|
---|
344 | #define ERR WINE_ERR
|
---|
345 | #define ERR_(ch) WINE_ERR_(ch)
|
---|
346 | #define ERR_ON(ch) WINE_ERR_ON(ch)
|
---|
347 |
|
---|
348 | #define DPRINTF WINE_DPRINTF
|
---|
349 | #define MESSAGE WINE_MESSAGE
|
---|
350 |
|
---|
351 | #endif /* __WINESRC__ */
|
---|
352 |
|
---|
353 | #ifdef __cplusplus
|
---|
354 | }
|
---|
355 | #endif
|
---|
356 |
|
---|
357 |
|
---|
358 | #ifdef DEBUG_misha
|
---|
359 | //# define VBOXWINEDBG_SHADERS
|
---|
360 | #endif
|
---|
361 |
|
---|
362 | #ifdef VBOXWINEDBG_SHADERS
|
---|
363 |
|
---|
364 | void vboxWDbgPrintF(char * szString, ...);
|
---|
365 |
|
---|
366 | # define WDLOG(_m) do {\
|
---|
367 | vboxWDbgPrintF _m ; \
|
---|
368 | } while (0)
|
---|
369 | #else
|
---|
370 |
|
---|
371 | # define WDLOG(_m) do { } while (0)
|
---|
372 | #endif
|
---|
373 |
|
---|
374 | #endif /* __WINE_WINE_DEBUG_H */
|
---|