source: branches/gcc-kmk/include/win/debugtools.h@ 21741

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

Common compiler warnings and errors.

File size: 8.8 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# define TRACE 1 ? (void)0 : (void)((int (*)(const char *, ...)) NULL)
180# define TRACE_(ch) 1 ? (void)0 : (void)((int (*)(const char *, ...)) NULL)
181# define FIXME 1 ? (void)0 : (void)((int (*)(const char *, ...)) NULL)
182# define FIXME_(ch) 1 ? (void)0 : (void)((int (*)(constchar *, ...)) NULL)
183# define WARN 1 ? (void)0 : (void)((int (*)(const char *, ...)) NULL)
184# define WARN_(ch) 1 ? (void)0 : (void)((int (*)(const char *, ...)) NULL)
185# define ERR_(ch) 1 ? (void)0 : (void)((int (*)(const char *, ...)) NULL)
186# define ERR 1 ? (void)0 : (void)((int (*)(const char *, ...)) NULL)
187# define DPRINTF 1 ? (void)0 : (void)((int (*)(const char *, ...)) NULL)
188# define MESSAGE 1 ? (void)0 : (void)((int (*)(const char *, ...)) NULL)
189#endif
190#undef __GET_DEBUGGING
191#define __GET_DEBUGGING(dbcl,dbch)
192#undef __SET_DEBUGGING
193#define __SET_DEBUGGING(dbcl,dbch,on)
194
195#endif
196
197#ifdef DEBUG
198#ifdef __cplusplus
199extern "C" {
200#endif
201
202//LPCSTR debugstr_guid1( void *id );
203////#define debugstr_guid(a) debugstr_guid1((void *)a)
204//#define debugstr_guid(a) 0
205
206#ifndef GUID_DEFINED
207#define GUID_DEFINED
208typedef struct _GUID
209{
210 unsigned long Data1;
211 unsigned short Data2;
212 unsigned short Data3;
213 unsigned char Data4[8];
214} GUID;
215#endif
216
217#ifdef __GNUC__
218inline static const char *debugstr_guid( const GUID *id )
219#else
220static char *debugstr_guid( const GUID *id )
221#endif
222{
223 static char temp[64];
224
225 if (!id) return "(null)";
226 if (!HIWORD(id))
227 {
228 sprintf( temp, "<guid-0x%04x>", LOWORD(id) );
229 }
230 else
231 {
232 sprintf( temp, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
233 id->Data1, id->Data2, id->Data3,
234 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
235 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
236 }
237 return temp;
238}
239
240#ifdef __cplusplus
241}
242#endif
243
244#ifdef __GNUC__
245inline static LPCSTR debugstr_an (LPCSTR src, int n)
246#else
247static LPCSTR debugstr_an (LPCSTR src, int n)
248#endif
249{
250 LPSTR dst;
251 static char res[128];
252
253 if (!HIWORD(src))
254 {
255 if (!src) return "(null)";
256 sprintf(res, "#%04x", LOWORD(src) );
257 return res;
258 }
259 if (n > sizeof(res)) return "(null)";
260
261 if (n < 0) n = 0;
262 dst = res;
263 *dst++ = '"';
264 while (n-- > 0 && *src)
265 {
266 BYTE c = *src++;
267 switch (c)
268 {
269 case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
270 case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
271 case '\t': *dst++ = '\\'; *dst++ = 't'; break;
272 case '"': *dst++ = '\\'; *dst++ = '"'; break;
273 case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
274 default:
275 if (c >= ' ' && c <= 126)
276 *dst++ = c;
277 else
278 {
279 *dst++ = '\\';
280 *dst++ = '0' + ((c >> 6) & 7);
281 *dst++ = '0' + ((c >> 3) & 7);
282 *dst++ = '0' + ((c >> 0) & 7);
283 }
284 }
285 }
286 *dst++ = '"';
287 if (*src)
288 {
289 *dst++ = '.';
290 *dst++ = '.';
291 *dst++ = '.';
292 }
293 *dst++ = '\0';
294 return res;
295}
296
297/* ---------------------------------------------------------------------- */
298
299#ifdef __GNUC__
300inline static LPCSTR debugstr_wn (LPCWSTR src, int n)
301#else
302static LPCSTR debugstr_wn (LPCWSTR src, int n)
303#endif
304{
305 LPSTR dst;
306 static char res[128];
307
308 if (!HIWORD(src))
309 {
310 if (!src) return "(null)";
311 sprintf(res, "#%04x", LOWORD(src) );
312 return res;
313 }
314
315 if (n > sizeof(res)) return "(null)";
316 if (n < 0) n = 0;
317
318 dst = res;
319 *dst++ = 'L';
320 *dst++ = '"';
321 while (n-- > 0 && *src)
322 {
323 WORD c = *src++;
324 switch (c)
325 {
326 case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
327 case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
328 case '\t': *dst++ = '\\'; *dst++ = 't'; break;
329 case '"': *dst++ = '\\'; *dst++ = '"'; break;
330 case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
331 default:
332 if (c >= ' ' && c <= 126)
333 *dst++ = (char)c;
334 else
335 {
336 *dst++ = '\\';
337 sprintf(dst,"%04x",c);
338 dst+=4;
339 }
340 }
341 }
342 *dst++ = '"';
343 if (*src)
344 {
345 *dst++ = '.';
346 *dst++ = '.';
347 *dst++ = '.';
348 }
349 *dst++ = '\0';
350 return res;
351}
352#else
353#define debugstr_guid(a) ""
354#define debugstr_an(a,n) ""
355#define debugstr_wn(w,n) ""
356#endif
357
358#endif /* __WINE_DEBUGTOOLS_H */
Note: See TracBrowser for help on using the repository browser.