:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / include / wine / debugtools.h
1 #ifndef __WINE_DEBUGTOOLS_H
2 #define __WINE_DEBUGTOOLS_H
3
4 #ifndef __NTDLL__
5
6 #include <stdarg.h>
7 #include "config.h"
8 #include "windef.h"
9
10 #else
11
12 #include <windows.h>
13
14 #endif /* __NTDLL__ */
15
16 struct _GUID;
17
18 /* Internal definitions (do not use these directly) */
19
20 enum __DEBUG_CLASS { __DBCL_FIXME, __DBCL_ERR, __DBCL_WARN, __DBCL_TRACE, __DBCL_COUNT };
21
22 #ifndef NO_TRACE_MSGS
23 # define __GET_DEBUGGING_TRACE(dbch) ((dbch)[0] & (1 << __DBCL_TRACE))
24 #else
25 # define __GET_DEBUGGING_TRACE(dbch) 0
26 #endif
27
28 #ifndef NO_DEBUG_MSGS
29 # define __GET_DEBUGGING_WARN(dbch)  ((dbch)[0] & (1 << __DBCL_WARN))
30 # define __GET_DEBUGGING_FIXME(dbch) ((dbch)[0] & (1 << __DBCL_FIXME))
31 #else
32 # define __GET_DEBUGGING_WARN(dbch)  0
33 # define __GET_DEBUGGING_FIXME(dbch) 0
34 #endif
35
36 /* define error macro regardless of what is configured */
37 #define __GET_DEBUGGING_ERR(dbch)  ((dbch)[0] & (1 << __DBCL_ERR))
38
39 #define __GET_DEBUGGING(dbcl,dbch)  __GET_DEBUGGING##dbcl(dbch)
40 #define __SET_DEBUGGING(dbcl,dbch,on) \
41     ((on) ? ((dbch)[0] |= 1 << (dbcl)) : ((dbch)[0] &= ~(1 << (dbcl))))
42
43 #ifdef __GNUC__
44
45 #define __DPRINTF(dbcl,dbch) \
46   do { if(__GET_DEBUGGING(dbcl,(dbch))) { \
47        const char * const __dbch = (dbch); \
48        const enum __DEBUG_CLASS __dbcl = __DBCL##dbcl; \
49        __WINE_DBG_LOG
50
51 #define __WINE_DBG_LOG(args...) \
52     wine_dbg_log( __dbcl, __dbch, __FUNCTION__, args); } } while(0)
53
54 #define __PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
55
56 #else  /* __GNUC__ */
57
58 #define __DPRINTF(dbcl,dbch) \
59     (!__GET_DEBUGGING(dbcl,(dbch)) || \
60      (wine_dbg_log(__DBCL##dbcl,(dbch),__FILE__,"%d: ",__LINE__),0)) ? \
61      (void)0 : (void)wine_dbg_printf
62
63 #define __PRINTF_ATTR(fmt, args)
64
65 #endif  /* __GNUC__ */
66
67 /* Exported definitions and macros */
68
69 /* These function return a printable version of a string, including
70    quotes.  The string will be valid for some time, but not indefinitely
71    as strings are re-used.  */
72 extern const char *wine_dbgstr_an( const char * s, int n );
73 extern const char *wine_dbgstr_wn( const WCHAR *s, int n );
74 extern const char *wine_dbgstr_guid( const struct _GUID *id );
75
76 extern int wine_dbg_vprintf( const char *format, va_list args ) __PRINTF_ATTR(1,0);
77 extern int wine_dbg_printf( const char *format, ... ) __PRINTF_ATTR(1,2);
78 extern int wine_dbg_log( enum __DEBUG_CLASS cls, const char *ch,
79                          const char *func, const char *format, ... ) __PRINTF_ATTR(4,5);
80
81 inline static const char *debugstr_an( const char * s, int n ) { return wine_dbgstr_an( s, n ); }
82 inline static const char *debugstr_wn( const WCHAR *s, int n ) { return wine_dbgstr_wn( s, n ); }
83 inline static const char *debugstr_guid( const struct _GUID *id ) { return wine_dbgstr_guid(id); }
84 inline static const char *debugstr_a( const char *s )  { return wine_dbgstr_an( s, 80 ); }
85 inline static const char *debugstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, 80 ); }
86 inline static const char *debugres_a( const char *s )  { return wine_dbgstr_an( s, 80 ); }
87 inline static const char *debugres_w( const WCHAR *s ) { return wine_dbgstr_wn( s, 80 ); }
88
89 #define TRACE        __DPRINTF(_TRACE,__wine_dbch___default)
90 #define TRACE_(ch)   __DPRINTF(_TRACE,__wine_dbch_##ch)
91 #define TRACE_ON(ch) __GET_DEBUGGING(_TRACE,__wine_dbch_##ch)
92
93 #define WARN         __DPRINTF(_WARN,__wine_dbch___default)
94 #define WARN_(ch)    __DPRINTF(_WARN,__wine_dbch_##ch)
95 #define WARN_ON(ch)  __GET_DEBUGGING(_WARN,__wine_dbch_##ch)
96
97 #define FIXME        __DPRINTF(_FIXME,__wine_dbch___default)
98 #define FIXME_(ch)   __DPRINTF(_FIXME,__wine_dbch_##ch)
99 #define FIXME_ON(ch) __GET_DEBUGGING(_FIXME,__wine_dbch_##ch)
100
101 #undef ERR  /* Solaris got an 'ERR' define in <sys/reg.h> */
102 #define ERR          __DPRINTF(_ERR,__wine_dbch___default)
103 #define ERR_(ch)     __DPRINTF(_ERR,__wine_dbch_##ch)
104 #define ERR_ON(ch)   __GET_DEBUGGING(_ERR,__wine_dbch_##ch)
105
106 #define DECLARE_DEBUG_CHANNEL(ch) \
107     char __wine_dbch_##ch[1];
108 #define DEFAULT_DEBUG_CHANNEL(ch) \
109     char __wine_dbch_##ch[1]; static char * const __wine_dbch___default = __wine_dbch_##ch
110
111 #define DPRINTF wine_dbg_printf
112 #define MESSAGE wine_dbg_printf
113
114 #endif  /* __WINE_DEBUGTOOLS_H */
115