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