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

Last change on this file since 4822 was 4822, checked in by bird, 25 years ago

Watcom corrections.

File size: 7.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 ; WriteLogError a
26 #define dassert(a, b) if(!(a)) WriteLogError b
27 #define dbgCheckObj(a) a->checkObject()
28 #define DisableLogging DecreaseLogCount
29 #define EnableLogging IncreaseLogCount
30
31#ifdef DEBUG_ENABLELOG_LEVEL2
32#ifdef PRIVATE_LOGGING
33 #define dprintf2(a) WritePrivateLog a
34#else
35 #define dprintf2(a) WriteLog a
36#endif
37#else
38 #define dprintf2(a)
39#endif
40
41#else
42 #define dprintfGlobal(a)
43 #define dprintf(a)
44 #define dprintf2(a)
45 #define eprintf(a)
46 #define dassert(a, b)
47 #define dbgCheckObj(a)
48 #define DisableLogging
49 #define EnableLogging
50#endif
51
52int SYSTEM WriteLog(char *tekst, ...);
53int SYSTEM WritePrivateLog(void *logfile, char *tekst, ...);
54int SYSTEM WriteLogError(char *tekst, ...);
55
56void SYSTEM DecreaseLogCount();
57void SYSTEM IncreaseLogCount();
58
59#endif //__MISC_H__
60
61#endif
62
63#ifdef __WINE__ /* Debugging interface is internal to Wine */
64
65#include <stdio.h>
66#include "config.h"
67#include "debugstr.h"
68
69#define DEBUG_RUNTIME
70
71/* Internal definitions (do not use these directly) */
72
73enum __DEBUG_CLASS { __DBCL_FIXME, __DBCL_ERR, __DBCL_WARN, __DBCL_TRACE, __DBCL_COUNT };
74
75extern char __debug_msg_enabled[][__DBCL_COUNT];
76
77extern const char * const debug_cl_name[__DBCL_COUNT];
78extern const char * const debug_ch_name[];
79
80#define __GET_DEBUGGING(dbcl,dbch) (__debug_msg_enabled[(dbch)][(dbcl)])
81#define __SET_DEBUGGING(dbcl,dbch,on) (__debug_msg_enabled[(dbch)][(dbcl)] = (on))
82
83#define __DPRINTF(dbcl,dbch) \
84 (!__GET_DEBUGGING(dbcl,dbch) || \
85 (dprintf(("%s:%s:%s ", debug_cl_name[(dbcl)], debug_ch_name[(dbch)], __line__)),0)) \
86 ? 0 : WriteLog
87
88#define __DUMMY_DPRINTF 1 ? (void)0 : (void)((int (*)(char *, ...)) NULL)
89
90
91/* Exported definitions and macros */
92
93/* use configure to allow user to compile out debugging messages */
94#ifndef NO_TRACE_MSGS
95#define TRACE __DPRINTF(__DBCL_TRACE,*DBCH_DEFAULT)
96#define TRACE_(ch) __DPRINTF(__DBCL_TRACE,dbch_##ch)
97#define TRACE_ON(ch) __GET_DEBUGGING(__DBCL_TRACE,dbch_##ch)
98#else
99#define TRACE __DUMMY_DPRINTF
100#define TRACE_(ch) __DUMMY_DPRINTF
101#define TRACE_ON(ch) 0
102#endif /* NO_TRACE_MSGS */
103
104#ifndef NO_DEBUG_MSGS
105#define WARN __DPRINTF(__DBCL_WARN,*DBCH_DEFAULT)
106#define WARN_(ch) __DPRINTF(__DBCL_WARN,dbch_##ch)
107#define WARN_ON(ch) __GET_DEBUGGING(__DBCL_WARN,dbch_##ch)
108#define FIXME __DPRINTF(__DBCL_FIXME,*DBCH_DEFAULT)
109#define FIXME_(ch) __DPRINTF(__DBCL_FIXME,dbch_##ch)
110#define FIXME_ON(ch) __GET_DEBUGGING(__DBCL_FIXME,dbch_##ch)
111#else
112#define WARN __DUMMY_DPRINTF
113#define WARN_(ch) __DUMMY_DPRINTF
114#define WARN_ON(ch) 0
115#define FIXME __DUMMY_DPRINTF
116#define FIXME_(ch) __DUMMY_DPRINTF
117#define FIXME_ON(ch) 0
118#endif /* NO_DEBUG_MSGS */
119
120/* define error macro regardless of what is configured */
121/* Solaris got an 'ERR' define in <sys/reg.h> */
122#undef ERR
123#define ERR __DPRINTF(__DBCL_ERR,*DBCH_DEFAULT)
124#define ERR_(ch) __DPRINTF(__DBCL_ERR,dbch_##ch)
125#define ERR_ON(ch) __GET_DEBUGGING(__DBCL_ERR,dbch_##ch)
126
127#define DECLARE_DEBUG_CHANNEL(ch) \
128 extern const int dbch_##ch;
129#define DEFAULT_DEBUG_CHANNEL(ch) \
130 static const int *const DBCH_DEFAULT = &dbch_##ch;
131
132#define DPRINTF dbg_printf
133#define MESSAGE dbg_printf
134
135#endif /* __WINE__ */
136
137#ifdef __WIN32OS2__
138# undef DECLARE_DEBUG_CHANNEL
139# define DECLARE_DEBUG_CHANNEL ODINDEBUGCHANNEL
140# undef DEFAULT_DEBUG_CHANNEL
141# define DEFAULT_DEBUG_CHANNEL ODINDEBUGCHANNEL1
142# undef TRACE
143# undef TRACE_
144# undef TRACE_ON
145# define TRACE_ON(ch) 0
146# undef FIXME
147# undef FIXME_
148# undef FIXME_ON
149# define FIXME_ON(ch) 0
150# undef WARN
151# undef WARN_
152# undef WARN_ON
153# define WARN_ON(ch) 0
154# undef ERR
155# undef ERR_
156# undef ERR_ON
157# define ERR_ON(ch) 0
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#else
168# define TRACE 1 ? (void)0 : (void)((int (*)(char *, ...)) NULL)
169# define TRACE_(ch) 1 ? (void)0 : (void)((int (*)(char *, ...)) NULL)
170# define FIXME 1 ? (void)0 : (void)((int (*)(char *, ...)) NULL)
171# define FIXME_(ch) 1 ? (void)0 : (void)((int (*)(char *, ...)) NULL)
172# define WARN 1 ? (void)0 : (void)((int (*)(char *, ...)) NULL)
173# define WARN_(ch) 1 ? (void)0 : (void)((int (*)(char *, ...)) NULL)
174# define ERR_(ch) 1 ? (void)0 : (void)((int (*)(char *, ...)) NULL)
175# define ERR 1 ? (void)0 : (void)((int (*)(char *, ...)) NULL)
176#endif
177#undef __GET_DEBUGGING
178#define __GET_DEBUGGING(dbcl,dbch)
179#undef __SET_DEBUGGING
180#define __SET_DEBUGGING(dbcl,dbch,on)
181
182#undef DPRINTF
183#define DPRINTF WriteLog
184#undef MESSAGE
185#define MESSAGE WriteLog
186
187#endif
188
189#ifdef DEBUG
190#ifdef __cplusplus
191extern "C" {
192#endif
193LPCSTR debugstr_guid1( void *id );
194#define debugstr_guid(a) debugstr_guid1((void *)a)
195
196#ifdef __cplusplus
197}
198#endif
199
200static LPCSTR debugstr_an (LPCSTR src, int n)
201{
202 LPSTR dst;
203 static char res[128];
204
205 if (!src) return "(null)";
206 if (n > sizeof(res)) return "(null)";
207
208 if (n < 0) n = 0;
209 dst = res;
210 *dst++ = '"';
211 while (n-- > 0 && *src)
212 {
213 BYTE c = *src++;
214 switch (c)
215 {
216 case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
217 case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
218 case '\t': *dst++ = '\\'; *dst++ = 't'; break;
219 case '"': *dst++ = '\\'; *dst++ = '"'; break;
220 case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
221 default:
222 if (c >= ' ' && c <= 126)
223 *dst++ = c;
224 else
225 {
226 *dst++ = '\\';
227 *dst++ = '0' + ((c >> 6) & 7);
228 *dst++ = '0' + ((c >> 3) & 7);
229 *dst++ = '0' + ((c >> 0) & 7);
230 }
231 }
232 }
233 *dst++ = '"';
234 if (*src)
235 {
236 *dst++ = '.';
237 *dst++ = '.';
238 *dst++ = '.';
239 }
240 *dst++ = '\0';
241 return res;
242}
243
244/* ---------------------------------------------------------------------- */
245
246static LPCSTR debugstr_wn (LPCWSTR src, int n)
247{
248 LPSTR dst;
249 static char res[128];
250
251 if (!src) return "(null)";
252 if (n > sizeof(res)) return "(null)";
253 if (n < 0) n = 0;
254
255 dst = res;
256 *dst++ = 'L';
257 *dst++ = '"';
258 while (n-- > 0 && *src)
259 {
260 WORD c = *src++;
261 switch (c)
262 {
263 case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
264 case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
265 case '\t': *dst++ = '\\'; *dst++ = 't'; break;
266 case '"': *dst++ = '\\'; *dst++ = '"'; break;
267 case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
268 default:
269 if (c >= ' ' && c <= 126)
270 *dst++ = (char)c;
271 else
272 {
273 *dst++ = '\\';
274 sprintf(dst,"%04x",c);
275 dst+=4;
276 }
277 }
278 }
279 *dst++ = '"';
280 if (*src)
281 {
282 *dst++ = '.';
283 *dst++ = '.';
284 *dst++ = '.';
285 }
286 *dst++ = '\0';
287 return res;
288}
289
290#endif
291
292#endif /* __WINE_DEBUGTOOLS_H */
Note: See TracBrowser for help on using the repository browser.