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

Last change on this file since 9707 was 9707, checked in by sandervl, 23 years ago

Added changed VAC headers to rename memory and file functions; add include\incl_vac to include path (/I)

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