1 |
|
---|
2 | #ifndef __WINE_DEBUGTOOLS_H
|
---|
3 | #define __WINE_DEBUGTOOLS_H
|
---|
4 |
|
---|
5 | #ifdef __WIN32OS2__
|
---|
6 | #include <odinwrap.h>
|
---|
7 | #include <odin.h>
|
---|
8 | #include <stdio.h>
|
---|
9 |
|
---|
10 | #ifndef __MISC_H__
|
---|
11 |
|
---|
12 | #ifdef __cplusplus
|
---|
13 | extern "C" {
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #ifdef DEBUG
|
---|
17 | #ifdef PRIVATE_LOGGING
|
---|
18 | //To use private dll logging, define PRIVATE_LOGGING and
|
---|
19 | //add Open/ClosePrivateLogFiles (see below) functions to the dll
|
---|
20 | //to open close the private logfile. The logfile handle should
|
---|
21 | //be stored in the _privateLogFile variable
|
---|
22 | //dprintf can be called like this:
|
---|
23 | //dprintf((LOG, "PE file : %s", szFileName));
|
---|
24 | #define LOG (void*)_privateLogFile
|
---|
25 | #define dprintf(a) WritePrivateLog a
|
---|
26 | #define dprintfGlobal(a) WriteLog a
|
---|
27 | #else
|
---|
28 | #define dprintf(a) WriteLog a
|
---|
29 | #endif
|
---|
30 | #define eprintf(a) WriteLog a
|
---|
31 | #define dassert(a, b) if(!(a)) dprintf b
|
---|
32 | #define dbgCheckObj(a) a->checkObject()
|
---|
33 | #define dprintfLock() WriteLogLock()
|
---|
34 | #define dprintfUnlock() WriteLogUnlock()
|
---|
35 |
|
---|
36 | #ifdef DEBUG_ENABLELOG_LEVEL2
|
---|
37 | #ifdef PRIVATE_LOGGING
|
---|
38 | #define dprintf2(a) WritePrivateLog a
|
---|
39 | #else
|
---|
40 | #define dprintf2(a) WriteLog a
|
---|
41 | #endif
|
---|
42 | #else
|
---|
43 | #define dprintf2(a)
|
---|
44 | #endif
|
---|
45 |
|
---|
46 | #else
|
---|
47 | #define dprintfGlobal(a)
|
---|
48 | #define dprintf(a)
|
---|
49 | #define dprintf2(a)
|
---|
50 | #define eprintf(a)
|
---|
51 | #define dassert(a, b)
|
---|
52 | #define dbgCheckObj(a)
|
---|
53 | #define dprintfLock()
|
---|
54 | #define dprintfUnlock()
|
---|
55 | #endif
|
---|
56 |
|
---|
57 | int SYSTEM WriteLog(const char *tekst, ...);
|
---|
58 | int SYSTEM WritePrivateLog(void *logfile, const char *tekst, ...);
|
---|
59 |
|
---|
60 | void SYSTEM WriteLogLock();
|
---|
61 | void SYSTEM WriteLogUnlock();
|
---|
62 |
|
---|
63 | void SYSTEM DecreaseLogCount();
|
---|
64 | void SYSTEM IncreaseLogCount();
|
---|
65 |
|
---|
66 | #ifdef __cplusplus
|
---|
67 | } // extern "C"
|
---|
68 | #endif
|
---|
69 |
|
---|
70 | #endif //__MISC_H__
|
---|
71 |
|
---|
72 | #endif
|
---|
73 |
|
---|
74 | #ifdef __WINE__ /* Debugging interface is internal to Wine */
|
---|
75 |
|
---|
76 | #include <stdio.h>
|
---|
77 | #include "config.h"
|
---|
78 | #include "debugstr.h"
|
---|
79 |
|
---|
80 | #define DEBUG_RUNTIME
|
---|
81 |
|
---|
82 | /* Internal definitions (do not use these directly) */
|
---|
83 |
|
---|
84 | enum __DEBUG_CLASS { __DBCL_FIXME, __DBCL_ERR, __DBCL_WARN, __DBCL_TRACE, __DBCL_COUNT };
|
---|
85 |
|
---|
86 | extern char __debug_msg_enabled[][__DBCL_COUNT];
|
---|
87 |
|
---|
88 | extern const char * const debug_cl_name[__DBCL_COUNT];
|
---|
89 | extern const char * const debug_ch_name[];
|
---|
90 |
|
---|
91 | #define __GET_DEBUGGING(dbcl,dbch) (__debug_msg_enabled[(dbch)][(dbcl)])
|
---|
92 | #define __SET_DEBUGGING(dbcl,dbch,on) (__debug_msg_enabled[(dbch)][(dbcl)] = (on))
|
---|
93 |
|
---|
94 | #define __DPRINTF(dbcl,dbch) \
|
---|
95 | (!__GET_DEBUGGING(dbcl,dbch) || \
|
---|
96 | (dprintf(("%s:%s:%s ", debug_cl_name[(dbcl)], debug_ch_name[(dbch)], __line__)),0)) \
|
---|
97 | ? 0 : WriteLog
|
---|
98 |
|
---|
99 | #define __DUMMY_DPRINTF 1 ? (void)0 : (void)((int (*)(char *, ...)) NULL)
|
---|
100 |
|
---|
101 |
|
---|
102 | /* Exported definitions and macros */
|
---|
103 |
|
---|
104 | /* use configure to allow user to compile out debugging messages */
|
---|
105 | #ifndef NO_TRACE_MSGS
|
---|
106 | #define TRACE __DPRINTF(__DBCL_TRACE,*DBCH_DEFAULT)
|
---|
107 | #define TRACE_(ch) __DPRINTF(__DBCL_TRACE,dbch_##ch)
|
---|
108 | #define TRACE_ON(ch) __GET_DEBUGGING(__DBCL_TRACE,dbch_##ch)
|
---|
109 | #else
|
---|
110 | #define TRACE __DUMMY_DPRINTF
|
---|
111 | #define TRACE_(ch) __DUMMY_DPRINTF
|
---|
112 | #define TRACE_ON(ch) 0
|
---|
113 | #endif /* NO_TRACE_MSGS */
|
---|
114 |
|
---|
115 | #ifndef NO_DEBUG_MSGS
|
---|
116 | #define WARN __DPRINTF(__DBCL_WARN,*DBCH_DEFAULT)
|
---|
117 | #define WARN_(ch) __DPRINTF(__DBCL_WARN,dbch_##ch)
|
---|
118 | #define WARN_ON(ch) __GET_DEBUGGING(__DBCL_WARN,dbch_##ch)
|
---|
119 | #define FIXME __DPRINTF(__DBCL_FIXME,*DBCH_DEFAULT)
|
---|
120 | #define FIXME_(ch) __DPRINTF(__DBCL_FIXME,dbch_##ch)
|
---|
121 | #define FIXME_ON(ch) __GET_DEBUGGING(__DBCL_FIXME,dbch_##ch)
|
---|
122 | #else
|
---|
123 | #define WARN __DUMMY_DPRINTF
|
---|
124 | #define WARN_(ch) __DUMMY_DPRINTF
|
---|
125 | #define WARN_ON(ch) 0
|
---|
126 | #define FIXME __DUMMY_DPRINTF
|
---|
127 | #define FIXME_(ch) __DUMMY_DPRINTF
|
---|
128 | #define FIXME_ON(ch) 0
|
---|
129 | #endif /* NO_DEBUG_MSGS */
|
---|
130 |
|
---|
131 | /* define error macro regardless of what is configured */
|
---|
132 | /* Solaris got an 'ERR' define in <sys/reg.h> */
|
---|
133 | #undef ERR
|
---|
134 | #define ERR __DPRINTF(__DBCL_ERR,*DBCH_DEFAULT)
|
---|
135 | #define ERR_(ch) __DPRINTF(__DBCL_ERR,dbch_##ch)
|
---|
136 | #define ERR_ON(ch) __GET_DEBUGGING(__DBCL_ERR,dbch_##ch)
|
---|
137 |
|
---|
138 | #define DECLARE_DEBUG_CHANNEL(ch) \
|
---|
139 | extern const int dbch_##ch;
|
---|
140 | #define DEFAULT_DEBUG_CHANNEL(ch) \
|
---|
141 | static const int *const DBCH_DEFAULT = &dbch_##ch;
|
---|
142 |
|
---|
143 | #define WINE_DECLARE_DEBUG_CHANNEL(ch) DECLARE_DEBUG_CHANNEL(ch)
|
---|
144 | #define WINE_DEFAULT_DEBUG_CHANNEL(ch) DEFAULT_DEBUG_CHANNEL(ch)
|
---|
145 |
|
---|
146 | #define DPRINTF dbg_printf
|
---|
147 | #define MESSAGE dbg_printf
|
---|
148 |
|
---|
149 | #endif /* __WINE__ */
|
---|
150 |
|
---|
151 | #ifdef __WIN32OS2__
|
---|
152 | # undef DECLARE_DEBUG_CHANNEL
|
---|
153 | # define DECLARE_DEBUG_CHANNEL ODINDEBUGCHANNEL
|
---|
154 | # undef DEFAULT_DEBUG_CHANNEL
|
---|
155 | # define DEFAULT_DEBUG_CHANNEL ODINDEBUGCHANNEL1
|
---|
156 | # undef TRACE
|
---|
157 | # undef TRACE_
|
---|
158 | # undef TRACE_ON
|
---|
159 | # define TRACE_ON(ch) 0
|
---|
160 | # undef FIXME
|
---|
161 | # undef FIXME_
|
---|
162 | # undef FIXME_ON
|
---|
163 | # define FIXME_ON(ch) 0
|
---|
164 | # undef WARN
|
---|
165 | # undef WARN_
|
---|
166 | # undef WARN_ON
|
---|
167 | # define WARN_ON(ch) 0
|
---|
168 | # undef ERR
|
---|
169 | # undef ERR_
|
---|
170 | # undef ERR_ON
|
---|
171 | # define ERR_ON(ch) 0
|
---|
172 | # undef DPRINTF
|
---|
173 | # undef MESSAGE
|
---|
174 | #ifdef DEBUG
|
---|
175 | # define TRACE WriteLog
|
---|
176 | # define TRACE_(ch) WriteLog
|
---|
177 | # define FIXME WriteLog
|
---|
178 | # define FIXME_(ch) WriteLog
|
---|
179 | # define WARN WriteLog
|
---|
180 | # define WARN_(ch) WriteLog
|
---|
181 | # define ERR_(ch) WriteLog
|
---|
182 | # define ERR WriteLog
|
---|
183 | # define DPRINTF WriteLog
|
---|
184 | # define MESSAGE WriteLog
|
---|
185 | #else
|
---|
186 | #ifdef __GNUC__
|
---|
187 | # define TRACE 1 ? (void) 0 : (void)
|
---|
188 | # define TRACE_(ch) 1 ? (void) 0 : (void)
|
---|
189 | # define FIXME 1 ? (void) 0 : (void)
|
---|
190 | # define FIXME_(ch) 1 ? (void) 0 : (void)
|
---|
191 | # define WARN 1 ? (void) 0 : (void)
|
---|
192 | # define WARN_(ch) 1 ? (void) 0 : (void)
|
---|
193 | # define ERR_(ch) 1 ? (void) 0 : (void)
|
---|
194 | # define ERR 1 ? (void) 0 : (void)
|
---|
195 | # define DPRINTF 1 ? (void) 0 : (void)
|
---|
196 | # define MESSAGE 1 ? (void) 0 : (void)
|
---|
197 | #else
|
---|
198 | # define TRACE 1 ? (void)0 : (void)((int (*)(const char *, ...)) NULL)
|
---|
199 | # define TRACE_(ch) 1 ? (void)0 : (void)((int (*)(const char *, ...)) NULL)
|
---|
200 | # define FIXME 1 ? (void)0 : (void)((int (*)(const char *, ...)) NULL)
|
---|
201 | # define FIXME_(ch) 1 ? (void)0 : (void)((int (*)(constchar *, ...)) NULL)
|
---|
202 | # define WARN 1 ? (void)0 : (void)((int (*)(const char *, ...)) NULL)
|
---|
203 | # define WARN_(ch) 1 ? (void)0 : (void)((int (*)(const char *, ...)) NULL)
|
---|
204 | # define ERR_(ch) 1 ? (void)0 : (void)((int (*)(const char *, ...)) NULL)
|
---|
205 | # define ERR 1 ? (void)0 : (void)((int (*)(const char *, ...)) NULL)
|
---|
206 | # define DPRINTF 1 ? (void)0 : (void)((int (*)(const char *, ...)) NULL)
|
---|
207 | # define MESSAGE 1 ? (void)0 : (void)((int (*)(const char *, ...)) NULL)
|
---|
208 | #endif
|
---|
209 | #endif
|
---|
210 | #undef __GET_DEBUGGING
|
---|
211 | #define __GET_DEBUGGING(dbcl,dbch)
|
---|
212 | #undef __SET_DEBUGGING
|
---|
213 | #define __SET_DEBUGGING(dbcl,dbch,on)
|
---|
214 |
|
---|
215 | #endif
|
---|
216 |
|
---|
217 | #ifdef DEBUG
|
---|
218 | #ifdef __cplusplus
|
---|
219 | extern "C" {
|
---|
220 | #endif
|
---|
221 |
|
---|
222 | //LPCSTR debugstr_guid1( void *id );
|
---|
223 | ////#define debugstr_guid(a) debugstr_guid1((void *)a)
|
---|
224 | //#define debugstr_guid(a) 0
|
---|
225 |
|
---|
226 | #ifndef GUID_DEFINED
|
---|
227 | #define GUID_DEFINED
|
---|
228 | typedef struct _GUID
|
---|
229 | {
|
---|
230 | unsigned long Data1;
|
---|
231 | unsigned short Data2;
|
---|
232 | unsigned short Data3;
|
---|
233 | unsigned char Data4[8];
|
---|
234 | } GUID;
|
---|
235 | #endif
|
---|
236 |
|
---|
237 | #ifdef __GNUC__
|
---|
238 | inline static const char *debugstr_guid( const GUID *id )
|
---|
239 | #else
|
---|
240 | static char *debugstr_guid( const GUID *id )
|
---|
241 | #endif
|
---|
242 | {
|
---|
243 | static char temp[64];
|
---|
244 |
|
---|
245 | if (!id) return "(null)";
|
---|
246 | if (!HIWORD(id))
|
---|
247 | {
|
---|
248 | sprintf( temp, "<guid-0x%04x>", LOWORD(id) );
|
---|
249 | }
|
---|
250 | else
|
---|
251 | {
|
---|
252 | sprintf( temp, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
|
---|
253 | id->Data1, id->Data2, id->Data3,
|
---|
254 | id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
|
---|
255 | id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
|
---|
256 | }
|
---|
257 | return temp;
|
---|
258 | }
|
---|
259 |
|
---|
260 | #ifdef __cplusplus
|
---|
261 | }
|
---|
262 | #endif
|
---|
263 |
|
---|
264 | #ifdef __GNUC__
|
---|
265 | inline static LPCSTR debugstr_an (LPCSTR src, int n)
|
---|
266 | #else
|
---|
267 | static LPCSTR debugstr_an (LPCSTR src, int n)
|
---|
268 | #endif
|
---|
269 | {
|
---|
270 | LPSTR dst;
|
---|
271 | static char res[128];
|
---|
272 |
|
---|
273 | if (!HIWORD(src))
|
---|
274 | {
|
---|
275 | if (!src) return "(null)";
|
---|
276 | sprintf(res, "#%04x", LOWORD(src) );
|
---|
277 | return res;
|
---|
278 | }
|
---|
279 | if (n > sizeof(res)) return "(null)";
|
---|
280 |
|
---|
281 | if (n < 0) n = 0;
|
---|
282 | dst = res;
|
---|
283 | *dst++ = '"';
|
---|
284 | while (n-- > 0 && *src)
|
---|
285 | {
|
---|
286 | BYTE c = *src++;
|
---|
287 | switch (c)
|
---|
288 | {
|
---|
289 | case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
|
---|
290 | case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
|
---|
291 | case '\t': *dst++ = '\\'; *dst++ = 't'; break;
|
---|
292 | case '"': *dst++ = '\\'; *dst++ = '"'; break;
|
---|
293 | case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
|
---|
294 | default:
|
---|
295 | if (c >= ' ' && c <= 126)
|
---|
296 | *dst++ = c;
|
---|
297 | else
|
---|
298 | {
|
---|
299 | *dst++ = '\\';
|
---|
300 | *dst++ = '0' + ((c >> 6) & 7);
|
---|
301 | *dst++ = '0' + ((c >> 3) & 7);
|
---|
302 | *dst++ = '0' + ((c >> 0) & 7);
|
---|
303 | }
|
---|
304 | }
|
---|
305 | }
|
---|
306 | *dst++ = '"';
|
---|
307 | if (*src)
|
---|
308 | {
|
---|
309 | *dst++ = '.';
|
---|
310 | *dst++ = '.';
|
---|
311 | *dst++ = '.';
|
---|
312 | }
|
---|
313 | *dst++ = '\0';
|
---|
314 | return res;
|
---|
315 | }
|
---|
316 |
|
---|
317 | /* ---------------------------------------------------------------------- */
|
---|
318 |
|
---|
319 | #ifdef __GNUC__
|
---|
320 | inline static LPCSTR debugstr_wn (LPCWSTR src, int n)
|
---|
321 | #else
|
---|
322 | static LPCSTR debugstr_wn (LPCWSTR src, int n)
|
---|
323 | #endif
|
---|
324 | {
|
---|
325 | LPSTR dst;
|
---|
326 | static char res[128];
|
---|
327 |
|
---|
328 | if (!HIWORD(src))
|
---|
329 | {
|
---|
330 | if (!src) return "(null)";
|
---|
331 | sprintf(res, "#%04x", LOWORD(src) );
|
---|
332 | return res;
|
---|
333 | }
|
---|
334 |
|
---|
335 | if (n > sizeof(res)) return "(null)";
|
---|
336 | if (n < 0) n = 0;
|
---|
337 |
|
---|
338 | dst = res;
|
---|
339 | *dst++ = 'L';
|
---|
340 | *dst++ = '"';
|
---|
341 | while (n-- > 0 && *src)
|
---|
342 | {
|
---|
343 | WORD c = *src++;
|
---|
344 | switch (c)
|
---|
345 | {
|
---|
346 | case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
|
---|
347 | case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
|
---|
348 | case '\t': *dst++ = '\\'; *dst++ = 't'; break;
|
---|
349 | case '"': *dst++ = '\\'; *dst++ = '"'; break;
|
---|
350 | case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
|
---|
351 | default:
|
---|
352 | if (c >= ' ' && c <= 126)
|
---|
353 | *dst++ = (char)c;
|
---|
354 | else
|
---|
355 | {
|
---|
356 | *dst++ = '\\';
|
---|
357 | sprintf(dst,"%04x",c);
|
---|
358 | dst+=4;
|
---|
359 | }
|
---|
360 | }
|
---|
361 | }
|
---|
362 | *dst++ = '"';
|
---|
363 | if (*src)
|
---|
364 | {
|
---|
365 | *dst++ = '.';
|
---|
366 | *dst++ = '.';
|
---|
367 | *dst++ = '.';
|
---|
368 | }
|
---|
369 | *dst++ = '\0';
|
---|
370 | return res;
|
---|
371 | }
|
---|
372 | #else
|
---|
373 | #define debugstr_guid(a) ""
|
---|
374 | #define debugstr_an(a,n) ""
|
---|
375 | #define debugstr_wn(w,n) ""
|
---|
376 | #endif
|
---|
377 |
|
---|
378 | #endif /* __WINE_DEBUGTOOLS_H */
|
---|