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

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

header updates

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