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