source: trunk/include/win/debugtools.h@ 10606

Last change on this file since 10606 was 10606, checked in by sandervl, 21 years ago

KOM: Updates

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