source: trunk/include/win/debugtools.h

Last change on this file was 22041, checked in by dmik, 13 years ago

kernel32: Add public debug log lock/unlock methods for higher level serialization.

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