11 #include "debugtools.h"
17 /* ---------------------------------------------------------------------- */
21 char *str_pos; /* current position in strings buffer */
22 char *out_pos; /* current position in output buffer */
23 char strings[504]; /* buffer for temporary strings */
24 char output[504]; /* current output line */
27 static struct debug_info tmp;
29 /* get the debug info pointer for the current thread */
30 static inline struct debug_info *get_info(void)
32 struct debug_info *info = NtCurrentTeb()->debug_info;
35 /* setup the temp structure in case HeapAlloc wants to print something */
36 NtCurrentTeb()->debug_info = &tmp;
37 tmp.str_pos = tmp.strings;
38 tmp.out_pos = tmp.output;
39 info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) );
40 info->str_pos = info->strings;
41 info->out_pos = info->output;
42 NtCurrentTeb()->debug_info = info;
47 /* allocate some tmp space for a string */
48 static void *gimme1(int n)
50 struct debug_info *info = get_info();
51 char *res = info->str_pos;
53 if (res + n >= &info->strings[sizeof(info->strings)]) res = info->strings;
54 info->str_pos = res + n;
58 /* release extra space that we requested in gimme1() */
59 static inline void release( void *ptr )
61 struct debug_info *info = NtCurrentTeb()->debug_info;
65 /***********************************************************************
68 const char *wine_dbgstr_an( const char *src, int n )
74 if (!src) return "(null)";
76 sprintf(res, "#%04x", LOWORD(src) );
80 dst = res = gimme1 (n * 4 + 6);
82 while (n-- > 0 && *src)
84 unsigned char c = *src++;
87 case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
88 case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
89 case '\t': *dst++ = '\\'; *dst++ = 't'; break;
90 case '"': *dst++ = '\\'; *dst++ = '"'; break;
91 case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
93 if (c >= ' ' && c <= 126)
98 *dst++ = '0' + ((c >> 6) & 7);
99 *dst++ = '0' + ((c >> 3) & 7);
100 *dst++ = '0' + ((c >> 0) & 7);
116 /***********************************************************************
119 const char *wine_dbgstr_wn( const WCHAR *src, int n )
125 if (!src) return "(null)";
127 sprintf(res, "#%04x", LOWORD(src) );
131 dst = res = gimme1 (n * 5 + 7);
134 while (n-- > 0 && *src)
139 case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
140 case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
141 case '\t': *dst++ = '\\'; *dst++ = 't'; break;
142 case '"': *dst++ = '\\'; *dst++ = '"'; break;
143 case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
145 if (c >= ' ' && c <= 126)
150 sprintf(dst,"%04x",c);
167 /***********************************************************************
170 const char *wine_dbgstr_guid( const GUID *id )
174 if (!id) return "(null)";
178 sprintf( str, "<guid-0x%04x>", LOWORD(id) );
183 sprintf( str, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
184 id->Data1, id->Data2, id->Data3,
185 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
186 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
191 /***********************************************************************
194 int wine_dbg_vprintf( const char *format, va_list args )
196 struct debug_info *info = get_info();
198 int ret = vsprintf( info->out_pos, format, args );
199 char *p = strrchr( info->out_pos, '\n' );
200 if (!p) info->out_pos += ret;
203 char *pos = info->output;
205 write( 2, pos, p - pos );
206 /* move beginning of next line to start of buffer */
207 while ((*pos = *p++)) pos++;
213 /***********************************************************************
216 int wine_dbg_printf(const char *format, ...)
221 va_start(valist, format);
222 ret = wine_dbg_vprintf( format, valist );
227 /***********************************************************************
230 int wine_dbg_log(enum __DEBUG_CLASS cls, const char *channel,
231 const char *function, const char *format, ... )
233 static const char *classes[__DBCL_COUNT] = { "fixme", "err", "warn", "trace" };
237 va_start(valist, format);
238 if (cls < __DBCL_COUNT)
239 ret = wine_dbg_printf( "%s:%s:%s ", classes[cls], channel + 1, function );
241 ret += wine_dbg_vprintf( format, valist );