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

Last change on this file since 5120 was 4834, checked in by sandervl, 25 years ago

update

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#define debugstr_guid(a) 0
196
197#ifdef __cplusplus
198}
199#endif
200
201static LPCSTR debugstr_an (LPCSTR src, int n)
202{
203 LPSTR dst;
204 static char res[128];
205
206 if (!src) return "(null)";
207 if (n > sizeof(res)) return "(null)";
208
209 if (n < 0) n = 0;
210 dst = res;
211 *dst++ = '"';
212 while (n-- > 0 && *src)
213 {
214 BYTE c = *src++;
215 switch (c)
216 {
217 case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
218 case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
219 case '\t': *dst++ = '\\'; *dst++ = 't'; break;
220 case '"': *dst++ = '\\'; *dst++ = '"'; break;
221 case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
222 default:
223 if (c >= ' ' && c <= 126)
224 *dst++ = c;
225 else
226 {
227 *dst++ = '\\';
228 *dst++ = '0' + ((c >> 6) & 7);
229 *dst++ = '0' + ((c >> 3) & 7);
230 *dst++ = '0' + ((c >> 0) & 7);
231 }
232 }
233 }
234 *dst++ = '"';
235 if (*src)
236 {
237 *dst++ = '.';
238 *dst++ = '.';
239 *dst++ = '.';
240 }
241 *dst++ = '\0';
242 return res;
243}
244
245/* ---------------------------------------------------------------------- */
246
247static LPCSTR debugstr_wn (LPCWSTR src, int n)
248{
249 LPSTR dst;
250 static char res[128];
251
252 if (!src) return "(null)";
253 if (n > sizeof(res)) return "(null)";
254 if (n < 0) n = 0;
255
256 dst = res;
257 *dst++ = 'L';
258 *dst++ = '"';
259 while (n-- > 0 && *src)
260 {
261 WORD c = *src++;
262 switch (c)
263 {
264 case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
265 case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
266 case '\t': *dst++ = '\\'; *dst++ = 't'; break;
267 case '"': *dst++ = '\\'; *dst++ = '"'; break;
268 case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
269 default:
270 if (c >= ' ' && c <= 126)
271 *dst++ = (char)c;
272 else
273 {
274 *dst++ = '\\';
275 sprintf(dst,"%04x",c);
276 dst+=4;
277 }
278 }
279 }
280 *dst++ = '"';
281 if (*src)
282 {
283 *dst++ = '.';
284 *dst++ = '.';
285 *dst++ = '.';
286 }
287 *dst++ = '\0';
288 return res;
289}
290
291#endif
292
293#endif /* __WINE_DEBUGTOOLS_H */
Note: See TracBrowser for help on using the repository browser.