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

Last change on this file since 21916 was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

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