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
;
37 tmp
.str_pos
= tmp
.strings
;
38 tmp
.out_pos
= tmp
.output
;
40 if (!GetProcessHeap()) return &tmp
;
41 /* setup the temp structure in case HeapAlloc wants to print something */
42 NtCurrentTeb()->debug_info
= &tmp
;
43 info
= HeapAlloc( GetProcessHeap(), 0, sizeof(*info
) );
44 info
->str_pos
= info
->strings
;
45 info
->out_pos
= info
->output
;
46 NtCurrentTeb()->debug_info
= info
;
51 /* allocate some tmp space for a string */
52 static void *gimme1(int n
)
54 struct debug_info
*info
= get_info();
55 char *res
= info
->str_pos
;
57 if (res
+ n
>= &info
->strings
[sizeof(info
->strings
)]) res
= info
->strings
;
58 info
->str_pos
= res
+ n
;
62 /* release extra space that we requested in gimme1() */
63 static inline void release( void *ptr
)
65 struct debug_info
*info
= NtCurrentTeb()->debug_info
;
69 /***********************************************************************
72 const char *wine_dbgstr_an( const char *src
, int n
)
78 if (!src
) return "(null)";
80 sprintf(res
, "#%04x", LOWORD(src
) );
84 dst
= res
= gimme1 (n
* 4 + 6);
86 while (n
-- > 0 && *src
)
88 unsigned char c
= *src
++;
91 case '\n': *dst
++ = '\\'; *dst
++ = 'n'; break;
92 case '\r': *dst
++ = '\\'; *dst
++ = 'r'; break;
93 case '\t': *dst
++ = '\\'; *dst
++ = 't'; break;
94 case '"': *dst
++ = '\\'; *dst
++ = '"'; break;
95 case '\\': *dst
++ = '\\'; *dst
++ = '\\'; break;
97 if (c
>= ' ' && c
<= 126)
102 *dst
++ = '0' + ((c
>> 6) & 7);
103 *dst
++ = '0' + ((c
>> 3) & 7);
104 *dst
++ = '0' + ((c
>> 0) & 7);
120 /***********************************************************************
123 const char *wine_dbgstr_wn( const WCHAR
*src
, int n
)
129 if (!src
) return "(null)";
131 sprintf(res
, "#%04x", LOWORD(src
) );
135 dst
= res
= gimme1 (n
* 5 + 7);
138 while (n
-- > 0 && *src
)
143 case '\n': *dst
++ = '\\'; *dst
++ = 'n'; break;
144 case '\r': *dst
++ = '\\'; *dst
++ = 'r'; break;
145 case '\t': *dst
++ = '\\'; *dst
++ = 't'; break;
146 case '"': *dst
++ = '\\'; *dst
++ = '"'; break;
147 case '\\': *dst
++ = '\\'; *dst
++ = '\\'; break;
149 if (c
>= ' ' && c
<= 126)
154 sprintf(dst
,"%04x",c
);
171 /***********************************************************************
174 const char *wine_dbgstr_guid( const GUID
*id
)
178 if (!id
) return "(null)";
182 sprintf( str
, "<guid-0x%04x>", LOWORD(id
) );
187 sprintf( str
, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
188 id
->Data1
, id
->Data2
, id
->Data3
,
189 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
190 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7] );
195 /***********************************************************************
198 int wine_dbg_vprintf( const char *format
, va_list args
)
200 struct debug_info
*info
= get_info();
202 int ret
= vsprintf( info
->out_pos
, format
, args
);
203 char *p
= strrchr( info
->out_pos
, '\n' );
204 if (!p
) info
->out_pos
+= ret
;
207 char *pos
= info
->output
;
209 write( 2, pos
, p
- pos
);
210 /* move beginning of next line to start of buffer */
211 while ((*pos
= *p
++)) pos
++;
217 /***********************************************************************
220 int wine_dbg_printf(const char *format
, ...)
225 va_start(valist
, format
);
226 ret
= wine_dbg_vprintf( format
, valist
);
231 /***********************************************************************
234 int wine_dbg_log(enum __DEBUG_CLASS cls
, const char *channel
,
235 const char *function
, const char *format
, ... )
237 static const char *classes
[__DBCL_COUNT
] = { "fixme", "err", "warn", "trace" };
241 va_start(valist
, format
);
242 if (cls
< __DBCL_COUNT
)
243 ret
= wine_dbg_printf( "%s:%s:%s ", classes
[cls
], channel
+ 1, function
);
245 ret
+= wine_dbg_vprintf( format
, valist
);