2 * Debugging channels functions for WINE support on ROS.
12 #include <wine/debugtools.h>
14 DECLARE_DEBUG_CHANNEL(winedbgc);
17 /* ---------------------------------------------------------------------- */
21 char *str_pos; /* current position in strings buffer */
22 char *out_pos; /* current position in output buffer */
23 char strings[1024]; /* buffer for temporary strings */
24 char output[1024]; /* 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()->WineDebugInfo;
37 tmp.str_pos = tmp.strings;
38 tmp.out_pos = tmp.output;
40 if (!RtlGetProcessHeap()) return &tmp;
41 /* setup the temp structure in case HeapAlloc wants to print something */
42 NtCurrentTeb()->WineDebugInfo = &tmp;
43 info = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(*info));
44 info->str_pos = info->strings;
45 info->out_pos = info->output;
46 NtCurrentTeb()->WineDebugInfo = 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()->WineDebugInfo;
69 /***********************************************************************
70 * wine_dbgstr_an (NTDLL.@)
72 const char *wine_dbgstr_an(const char *src, int n)
76 if (!((WORD)(DWORD)(src) >> 16))
78 if (!src) return "(null)";
80 sprintf(res, "#%04x", (WORD)(DWORD)(src) );
84 else if (n > 200) n = 200;
85 dst = res = gimme1 (n * 4 + 6);
87 while (n-- > 0 && *src)
89 unsigned char c = *src++;
92 case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
93 case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
94 case '\t': *dst++ = '\\'; *dst++ = 't'; break;
95 case '"': *dst++ = '\\'; *dst++ = '"'; break;
96 case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
98 if (c >= ' ' && c <= 126)
103 *dst++ = '0' + ((c >> 6) & 7);
104 *dst++ = '0' + ((c >> 3) & 7);
105 *dst++ = '0' + ((c >> 0) & 7);
121 /***********************************************************************
122 * wine_dbgstr_wn (NTDLL.@)
124 const char *wine_dbgstr_wn(const WCHAR *src, int n)
128 if (!((WORD)(DWORD)(src) >> 16))
130 if (!src) return "(null)";
132 sprintf(res, "#%04x", (WORD)(DWORD)(src) );
136 else if (n > 200) n = 200;
137 dst = res = gimme1(n * 5 + 7);
140 while (n-- > 0 && *src)
145 case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
146 case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
147 case '\t': *dst++ = '\\'; *dst++ = 't'; break;
148 case '"': *dst++ = '\\'; *dst++ = '"'; break;
149 case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
151 if (c >= ' ' && c <= 126)
156 sprintf(dst,"%04x",c);
173 /***********************************************************************
174 * wine_dbgstr_guid (NTDLL.@)
176 const char *wine_dbgstr_guid(const GUID *id)
180 if (!id) return "(null)";
181 if (!((WORD)(DWORD)(id) >> 16)) {
183 sprintf(str, "<guid-0x%04x>", (WORD)(DWORD)(id));
186 sprintf(str, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
187 id->Data1, id->Data2, id->Data3,
188 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
189 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7]);
194 /***********************************************************************
195 * wine_dbg_vprintf (NTDLL.@)
197 int wine_dbg_vprintf(const char *format, va_list args)
199 struct debug_info *info = get_info();
202 int ret = _vsnprintf(info->out_pos, sizeof(info->output) - (info->out_pos - info->output),
205 p = strrchr(info->out_pos, '\n');
207 info->out_pos += ret;
209 char *pos = info->output;
216 /* move beginning of next line to start of buffer */
217 while ((*pos = *p++)) pos++;
223 /***********************************************************************
224 * wine_dbg_printf (NTDLL.@)
226 int wine_dbg_printf(const char *format, ...)
231 va_start(valist, format);
233 Trace(format, valist);
235 ret = wine_dbg_vprintf(format, valist);
240 /***********************************************************************
241 * wine_dbg_log (NTDLL.@)
243 int wine_dbg_log(enum __DEBUG_CLASS cls, const char *channel,
244 const char *function, const char *format, ...)
246 static const char *classes[__DBCL_COUNT] = { "fixme", "err", "warn", "trace" };
250 va_start(valist, format);
251 if (TRACE_ON(winedbgc))
252 ret = wine_dbg_printf("%08lx:", NtCurrentTeb()->Cid.UniqueThread);
253 if (cls < __DBCL_COUNT)
254 ret += wine_dbg_printf("%s:%s:%s ", classes[cls], channel + 1, function);
256 ret += wine_dbg_vprintf(format, valist);