2000-11-05 05:51:34 +01:00
|
|
|
/*
|
|
|
|
* Management of the debugging channels
|
|
|
|
*
|
|
|
|
* Copyright 2000 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-11-05 05:51:34 +01:00
|
|
|
*/
|
|
|
|
|
2002-05-17 04:55:48 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2000-11-05 05:51:34 +01:00
|
|
|
#include <stdlib.h>
|
2002-05-17 04:55:48 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2000-11-05 05:51:34 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
2011-09-04 23:08:10 +02:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
# include <sys/stat.h>
|
|
|
|
#endif
|
2000-11-05 05:51:34 +01:00
|
|
|
|
2019-04-03 19:25:28 +02:00
|
|
|
#define __wine_dbg_get_channel_flags __wine_dbg_get_channel_flags_inline
|
2019-04-03 10:02:14 +02:00
|
|
|
#define wine_dbg_sprintf wine_dbg_sprintf_inline
|
2019-04-03 19:24:39 +02:00
|
|
|
#define wine_dbg_printf wine_dbg_printf_inline
|
2019-04-03 19:27:13 +02:00
|
|
|
#define wine_dbg_log wine_dbg_log_inline
|
2019-04-03 19:23:43 +02:00
|
|
|
#define wine_dbgstr_an wine_dbgstr_an_inline
|
|
|
|
#define wine_dbgstr_wn wine_dbgstr_wn_inline
|
2002-05-17 04:55:48 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wine/library.h"
|
|
|
|
|
2019-04-03 14:11:42 +02:00
|
|
|
struct __wine_debug_functions
|
|
|
|
{
|
|
|
|
char * (*get_temp_buffer)( size_t n );
|
|
|
|
void (*release_temp_buffer)( char *buffer, size_t n );
|
|
|
|
const char * (*dbgstr_an)( const char * s, int n );
|
|
|
|
const char * (*dbgstr_wn)( const WCHAR *s, int n );
|
|
|
|
int (*dbg_vprintf)( const char *format, va_list args );
|
|
|
|
int (*dbg_vlog)( enum __wine_debug_class cls, struct __wine_debug_channel *channel,
|
|
|
|
const char *function, const char *format, va_list args );
|
|
|
|
};
|
2013-03-27 17:08:16 +01:00
|
|
|
|
2005-09-28 17:21:48 +02:00
|
|
|
static const char * const debug_classes[] = { "fixme", "err", "warn", "trace" };
|
2000-11-05 05:51:34 +01:00
|
|
|
|
2005-09-28 17:21:48 +02:00
|
|
|
#define MAX_DEBUG_OPTIONS 256
|
2000-11-05 05:51:34 +01:00
|
|
|
|
2005-09-28 17:21:48 +02:00
|
|
|
static unsigned char default_flags = (1 << __WINE_DBCL_ERR) | (1 << __WINE_DBCL_FIXME);
|
2007-09-11 11:57:11 +02:00
|
|
|
static int nb_debug_options = -1;
|
2005-09-28 17:21:48 +02:00
|
|
|
static struct __wine_debug_channel debug_options[MAX_DEBUG_OPTIONS];
|
2000-11-05 05:51:34 +01:00
|
|
|
|
2005-09-28 17:21:48 +02:00
|
|
|
static struct __wine_debug_functions funcs;
|
2000-11-05 05:51:34 +01:00
|
|
|
|
2007-09-11 11:57:11 +02:00
|
|
|
static void debug_init(void);
|
|
|
|
|
2000-11-05 05:51:34 +01:00
|
|
|
static int cmp_name( const void *p1, const void *p2 )
|
|
|
|
{
|
|
|
|
const char *name = p1;
|
2005-09-28 17:21:48 +02:00
|
|
|
const struct __wine_debug_channel *chan = p2;
|
|
|
|
return strcmp( name, chan->name );
|
2000-11-05 05:51:34 +01:00
|
|
|
}
|
|
|
|
|
2005-09-28 17:21:48 +02:00
|
|
|
/* get the flags to use for a given channel, possibly setting them too in case of lazy init */
|
2019-04-03 19:25:28 +02:00
|
|
|
#undef __wine_dbg_get_channel_flags
|
2005-09-29 13:16:52 +02:00
|
|
|
unsigned char __wine_dbg_get_channel_flags( struct __wine_debug_channel *channel )
|
2000-11-05 05:51:34 +01:00
|
|
|
{
|
2007-09-11 11:57:11 +02:00
|
|
|
if (nb_debug_options == -1) debug_init();
|
|
|
|
|
2005-09-28 17:21:48 +02:00
|
|
|
if (nb_debug_options)
|
2000-11-05 05:51:34 +01:00
|
|
|
{
|
2005-09-28 17:21:48 +02:00
|
|
|
struct __wine_debug_channel *opt = bsearch( channel->name, debug_options, nb_debug_options,
|
|
|
|
sizeof(debug_options[0]), cmp_name );
|
|
|
|
if (opt) return opt->flags;
|
2000-11-05 05:51:34 +01:00
|
|
|
}
|
2005-09-28 17:21:48 +02:00
|
|
|
/* no option for this channel */
|
|
|
|
if (channel->flags & (1 << __WINE_DBCL_INIT)) channel->flags = default_flags;
|
|
|
|
return default_flags;
|
2000-11-05 05:51:34 +01:00
|
|
|
}
|
|
|
|
|
2005-10-18 12:49:20 +02:00
|
|
|
/* set the flags to use for a given channel; return 0 if the channel is not available to set */
|
|
|
|
int __wine_dbg_set_channel_flags( struct __wine_debug_channel *channel,
|
|
|
|
unsigned char set, unsigned char clear )
|
|
|
|
{
|
2007-09-11 11:57:11 +02:00
|
|
|
if (nb_debug_options == -1) debug_init();
|
|
|
|
|
2005-10-18 12:49:20 +02:00
|
|
|
if (nb_debug_options)
|
|
|
|
{
|
|
|
|
struct __wine_debug_channel *opt = bsearch( channel->name, debug_options, nb_debug_options,
|
|
|
|
sizeof(debug_options[0]), cmp_name );
|
|
|
|
if (opt)
|
|
|
|
{
|
|
|
|
opt->flags = (opt->flags & ~clear) | set;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-11-05 05:51:34 +01:00
|
|
|
/* add a new debug option at the end of the option list */
|
2005-09-28 17:21:48 +02:00
|
|
|
static void add_option( const char *name, unsigned char set, unsigned char clear )
|
2000-11-05 05:51:34 +01:00
|
|
|
{
|
2005-09-28 17:21:48 +02:00
|
|
|
int min = 0, max = nb_debug_options - 1, pos, res;
|
|
|
|
|
|
|
|
if (!name[0]) /* "all" option */
|
2000-11-05 05:51:34 +01:00
|
|
|
{
|
2005-09-28 17:21:48 +02:00
|
|
|
default_flags = (default_flags & ~clear) | set;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (strlen(name) >= sizeof(debug_options[0].name)) return;
|
|
|
|
|
|
|
|
while (min <= max)
|
|
|
|
{
|
|
|
|
pos = (min + max) / 2;
|
|
|
|
res = strcmp( name, debug_options[pos].name );
|
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
debug_options[pos].flags = (debug_options[pos].flags & ~clear) | set;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (res < 0) max = pos - 1;
|
|
|
|
else min = pos + 1;
|
2000-11-05 05:51:34 +01:00
|
|
|
}
|
2005-09-28 17:21:48 +02:00
|
|
|
if (nb_debug_options >= MAX_DEBUG_OPTIONS) return;
|
|
|
|
|
|
|
|
pos = min;
|
|
|
|
if (pos < nb_debug_options) memmove( &debug_options[pos + 1], &debug_options[pos],
|
|
|
|
(nb_debug_options - pos) * sizeof(debug_options[0]) );
|
|
|
|
strcpy( debug_options[pos].name, name );
|
|
|
|
debug_options[pos].flags = (default_flags & ~clear) | set;
|
|
|
|
nb_debug_options++;
|
2000-11-05 05:51:34 +01:00
|
|
|
}
|
2002-05-17 04:55:48 +02:00
|
|
|
|
2002-06-04 19:48:41 +02:00
|
|
|
/* parse a set of debugging option specifications and add them to the option list */
|
2005-09-28 17:21:48 +02:00
|
|
|
static void parse_options( const char *str )
|
2002-06-04 19:48:41 +02:00
|
|
|
{
|
2003-10-03 05:35:20 +02:00
|
|
|
char *opt, *next, *options;
|
2004-09-22 04:46:38 +02:00
|
|
|
unsigned int i;
|
2002-06-04 19:48:41 +02:00
|
|
|
|
2005-09-28 17:21:48 +02:00
|
|
|
if (!(options = strdup(str))) return;
|
2002-06-04 19:48:41 +02:00
|
|
|
for (opt = options; opt; opt = next)
|
|
|
|
{
|
2003-10-03 05:35:20 +02:00
|
|
|
const char *p;
|
2002-06-04 19:48:41 +02:00
|
|
|
unsigned char set = 0, clear = 0;
|
|
|
|
|
|
|
|
if ((next = strchr( opt, ',' ))) *next++ = 0;
|
|
|
|
|
|
|
|
p = opt + strcspn( opt, "+-" );
|
2003-12-05 01:17:41 +01:00
|
|
|
if (!p[0]) p = opt; /* assume it's a debug channel name */
|
2002-06-04 19:48:41 +02:00
|
|
|
|
|
|
|
if (p > opt)
|
|
|
|
{
|
2018-10-25 15:47:29 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(debug_classes); i++)
|
2002-06-04 19:48:41 +02:00
|
|
|
{
|
|
|
|
int len = strlen(debug_classes[i]);
|
|
|
|
if (len != (p - opt)) continue;
|
|
|
|
if (!memcmp( opt, debug_classes[i], len )) /* found it */
|
|
|
|
{
|
|
|
|
if (*p == '+') set |= 1 << i;
|
|
|
|
else clear |= 1 << i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-10-25 15:47:29 +02:00
|
|
|
if (i == ARRAY_SIZE(debug_classes)) /* bad class name, skip it */
|
2002-06-04 19:48:41 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-12-05 01:17:41 +01:00
|
|
|
if (*p == '-') clear = ~0;
|
|
|
|
else set = ~0;
|
|
|
|
}
|
|
|
|
if (*p == '+' || *p == '-') p++;
|
2005-09-28 17:21:48 +02:00
|
|
|
if (!p[0]) continue;
|
|
|
|
|
|
|
|
if (!strcmp( p, "all" ))
|
|
|
|
default_flags = (default_flags & ~clear) | set;
|
|
|
|
else
|
|
|
|
add_option( p, set, clear );
|
2002-06-04 19:48:41 +02:00
|
|
|
}
|
|
|
|
free( options );
|
2005-09-28 17:21:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* print the usage message */
|
|
|
|
static void debug_usage(void)
|
|
|
|
{
|
|
|
|
static const char usage[] =
|
|
|
|
"Syntax of the WINEDEBUG variable:\n"
|
|
|
|
" WINEDEBUG=[class]+xxx,[class]-yyy,...\n\n"
|
|
|
|
"Example: WINEDEBUG=+all,warn-heap\n"
|
|
|
|
" turns on all messages except warning heap messages\n"
|
|
|
|
"Available message classes: err, warn, fixme, trace\n";
|
|
|
|
write( 2, usage, sizeof(usage) - 1 );
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* initialize all options at startup */
|
2007-09-11 11:57:11 +02:00
|
|
|
static void debug_init(void)
|
2005-09-28 17:21:48 +02:00
|
|
|
{
|
|
|
|
char *wine_debug;
|
2011-09-04 23:08:10 +02:00
|
|
|
struct stat st1, st2;
|
2005-09-28 17:21:48 +02:00
|
|
|
|
2007-09-11 11:57:11 +02:00
|
|
|
if (nb_debug_options != -1) return; /* already initialized */
|
|
|
|
nb_debug_options = 0;
|
2011-09-04 23:08:10 +02:00
|
|
|
|
|
|
|
/* check for stderr pointing to /dev/null */
|
|
|
|
if (!fstat( 2, &st1 ) && S_ISCHR(st1.st_mode) &&
|
|
|
|
!stat( "/dev/null", &st2 ) && S_ISCHR(st2.st_mode) &&
|
|
|
|
st1.st_rdev == st2.st_rdev)
|
|
|
|
{
|
|
|
|
default_flags = 0;
|
|
|
|
return;
|
|
|
|
}
|
2005-09-28 17:21:48 +02:00
|
|
|
if ((wine_debug = getenv("WINEDEBUG")))
|
|
|
|
{
|
|
|
|
if (!strcmp( wine_debug, "help" )) debug_usage();
|
|
|
|
parse_options( wine_debug );
|
|
|
|
}
|
2002-06-04 19:48:41 +02:00
|
|
|
}
|
2002-05-17 04:55:48 +02:00
|
|
|
|
2005-09-26 18:45:25 +02:00
|
|
|
/* varargs wrapper for funcs.dbg_vprintf */
|
2019-04-03 19:24:39 +02:00
|
|
|
#undef wine_dbg_printf
|
2002-05-17 04:55:48 +02:00
|
|
|
int wine_dbg_printf( const char *format, ... )
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
va_list valist;
|
|
|
|
|
|
|
|
va_start(valist, format);
|
2005-09-23 12:52:07 +02:00
|
|
|
ret = funcs.dbg_vprintf( format, valist );
|
2002-05-17 04:55:48 +02:00
|
|
|
va_end(valist);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-09-26 18:45:25 +02:00
|
|
|
/* printf with temp buffer allocation */
|
2019-04-03 10:02:14 +02:00
|
|
|
#undef wine_dbg_sprintf
|
2003-01-03 04:12:58 +01:00
|
|
|
const char *wine_dbg_sprintf( const char *format, ... )
|
|
|
|
{
|
2005-09-26 18:45:25 +02:00
|
|
|
static const int max_size = 200;
|
|
|
|
char *ret;
|
|
|
|
int len;
|
2003-01-03 04:12:58 +01:00
|
|
|
va_list valist;
|
|
|
|
|
|
|
|
va_start(valist, format);
|
2005-09-26 18:45:25 +02:00
|
|
|
ret = funcs.get_temp_buffer( max_size );
|
|
|
|
len = vsnprintf( ret, max_size, format, valist );
|
|
|
|
if (len == -1 || len >= max_size) ret[max_size-1] = 0;
|
|
|
|
else funcs.release_temp_buffer( ret, len + 1 );
|
2003-01-03 04:12:58 +01:00
|
|
|
va_end(valist);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-26 18:45:25 +02:00
|
|
|
/* varargs wrapper for funcs.dbg_vlog */
|
2019-04-03 19:27:13 +02:00
|
|
|
#undef wine_dbg_log
|
2005-09-23 12:52:07 +02:00
|
|
|
int wine_dbg_log( enum __wine_debug_class cls, struct __wine_debug_channel *channel,
|
|
|
|
const char *func, const char *format, ... )
|
2002-05-17 04:55:48 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
va_list valist;
|
|
|
|
|
2005-09-29 13:16:52 +02:00
|
|
|
if (!(__wine_dbg_get_channel_flags( channel ) & (1 << cls))) return -1;
|
2005-09-28 17:21:48 +02:00
|
|
|
|
2002-05-17 04:55:48 +02:00
|
|
|
va_start(valist, format);
|
2005-09-23 12:52:07 +02:00
|
|
|
ret = funcs.dbg_vlog( cls, channel, func, format, valist );
|
2002-05-17 04:55:48 +02:00
|
|
|
va_end(valist);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* allocate some tmp string space */
|
|
|
|
/* FIXME: this is not 100% thread-safe */
|
2005-09-26 18:45:25 +02:00
|
|
|
static char *get_temp_buffer( size_t size )
|
2002-05-17 04:55:48 +02:00
|
|
|
{
|
|
|
|
static char *list[32];
|
2005-09-26 15:51:58 +02:00
|
|
|
static int pos;
|
2002-05-17 04:55:48 +02:00
|
|
|
char *ret;
|
|
|
|
int idx;
|
|
|
|
|
2018-10-25 15:47:29 +02:00
|
|
|
idx = interlocked_xchg_add( &pos, 1 ) % ARRAY_SIZE(list);
|
2002-05-17 04:55:48 +02:00
|
|
|
if ((ret = realloc( list[idx], size ))) list[idx] = ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-26 18:45:25 +02:00
|
|
|
/* release unused part of the buffer */
|
|
|
|
static void release_temp_buffer( char *buffer, size_t size )
|
|
|
|
{
|
|
|
|
/* don't bother doing anything */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-17 04:55:48 +02:00
|
|
|
/* default implementation of wine_dbgstr_an */
|
|
|
|
static const char *default_dbgstr_an( const char *str, int n )
|
|
|
|
{
|
2005-09-26 18:45:25 +02:00
|
|
|
static const char hex[16] = "0123456789abcdef";
|
2002-05-17 04:55:48 +02:00
|
|
|
char *dst, *res;
|
2005-09-26 18:45:25 +02:00
|
|
|
size_t size;
|
2002-05-17 04:55:48 +02:00
|
|
|
|
2005-09-26 18:45:25 +02:00
|
|
|
if (!((ULONG_PTR)str >> 16))
|
2002-05-17 06:17:48 +02:00
|
|
|
{
|
|
|
|
if (!str) return "(null)";
|
2005-09-26 18:45:25 +02:00
|
|
|
res = funcs.get_temp_buffer( 6 );
|
2002-05-17 06:17:48 +02:00
|
|
|
sprintf( res, "#%04x", LOWORD(str) );
|
|
|
|
return res;
|
|
|
|
}
|
2002-05-17 04:55:48 +02:00
|
|
|
if (n == -1) n = strlen(str);
|
|
|
|
if (n < 0) n = 0;
|
2005-09-26 18:45:25 +02:00
|
|
|
size = 10 + min( 300, n * 4 );
|
|
|
|
dst = res = funcs.get_temp_buffer( size );
|
2002-05-17 04:55:48 +02:00
|
|
|
*dst++ = '"';
|
2005-09-26 18:45:25 +02:00
|
|
|
while (n-- > 0 && dst <= res + size - 9)
|
2002-05-17 04:55:48 +02:00
|
|
|
{
|
|
|
|
unsigned char c = *str++;
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
|
|
|
|
case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
|
|
|
|
case '\t': *dst++ = '\\'; *dst++ = 't'; break;
|
|
|
|
case '"': *dst++ = '\\'; *dst++ = '"'; break;
|
|
|
|
case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
|
|
|
|
default:
|
|
|
|
if (c >= ' ' && c <= 126)
|
|
|
|
*dst++ = c;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*dst++ = '\\';
|
2005-09-26 18:45:25 +02:00
|
|
|
*dst++ = 'x';
|
|
|
|
*dst++ = hex[(c >> 4) & 0x0f];
|
|
|
|
*dst++ = hex[c & 0x0f];
|
2002-05-17 04:55:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*dst++ = '"';
|
2006-01-27 16:18:05 +01:00
|
|
|
if (n > 0)
|
2002-05-17 04:55:48 +02:00
|
|
|
{
|
|
|
|
*dst++ = '.';
|
|
|
|
*dst++ = '.';
|
|
|
|
*dst++ = '.';
|
|
|
|
}
|
2005-09-26 18:45:25 +02:00
|
|
|
*dst++ = 0;
|
|
|
|
funcs.release_temp_buffer( res, dst - res );
|
2002-05-17 04:55:48 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* default implementation of wine_dbgstr_wn */
|
|
|
|
static const char *default_dbgstr_wn( const WCHAR *str, int n )
|
|
|
|
{
|
|
|
|
char *dst, *res;
|
2005-09-26 18:45:25 +02:00
|
|
|
size_t size;
|
2002-05-17 04:55:48 +02:00
|
|
|
|
2005-09-26 18:45:25 +02:00
|
|
|
if (!((ULONG_PTR)str >> 16))
|
2002-05-17 06:17:48 +02:00
|
|
|
{
|
|
|
|
if (!str) return "(null)";
|
2005-09-26 18:45:25 +02:00
|
|
|
res = funcs.get_temp_buffer( 6 );
|
2002-05-17 06:17:48 +02:00
|
|
|
sprintf( res, "#%04x", LOWORD(str) );
|
|
|
|
return res;
|
|
|
|
}
|
2006-05-24 17:16:42 +02:00
|
|
|
if (n == -1)
|
|
|
|
{
|
|
|
|
const WCHAR *end = str;
|
|
|
|
while (*end) end++;
|
|
|
|
n = end - str;
|
|
|
|
}
|
2002-05-17 04:55:48 +02:00
|
|
|
if (n < 0) n = 0;
|
2005-09-26 18:45:25 +02:00
|
|
|
size = 12 + min( 300, n * 5 );
|
2008-07-16 00:55:36 +02:00
|
|
|
dst = res = funcs.get_temp_buffer( size );
|
2002-05-17 04:55:48 +02:00
|
|
|
*dst++ = 'L';
|
|
|
|
*dst++ = '"';
|
2005-09-26 18:45:25 +02:00
|
|
|
while (n-- > 0 && dst <= res + size - 10)
|
2002-05-17 04:55:48 +02:00
|
|
|
{
|
|
|
|
WCHAR c = *str++;
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
|
|
|
|
case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
|
|
|
|
case '\t': *dst++ = '\\'; *dst++ = 't'; break;
|
|
|
|
case '"': *dst++ = '\\'; *dst++ = '"'; break;
|
|
|
|
case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
|
|
|
|
default:
|
|
|
|
if (c >= ' ' && c <= 126)
|
|
|
|
*dst++ = c;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*dst++ = '\\';
|
|
|
|
sprintf(dst,"%04x",c);
|
|
|
|
dst+=4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*dst++ = '"';
|
2006-01-27 16:18:05 +01:00
|
|
|
if (n > 0)
|
2002-05-17 04:55:48 +02:00
|
|
|
{
|
|
|
|
*dst++ = '.';
|
|
|
|
*dst++ = '.';
|
|
|
|
*dst++ = '.';
|
|
|
|
}
|
2005-09-26 18:45:25 +02:00
|
|
|
*dst++ = 0;
|
|
|
|
funcs.release_temp_buffer( res, dst - res );
|
2002-05-17 04:55:48 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* default implementation of wine_dbg_vprintf */
|
|
|
|
static int default_dbg_vprintf( const char *format, va_list args )
|
|
|
|
{
|
|
|
|
return vfprintf( stderr, format, args );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* default implementation of wine_dbg_vlog */
|
2005-09-23 12:52:07 +02:00
|
|
|
static int default_dbg_vlog( enum __wine_debug_class cls, struct __wine_debug_channel *channel,
|
|
|
|
const char *func, const char *format, va_list args )
|
2002-05-17 04:55:48 +02:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2018-10-25 15:47:29 +02:00
|
|
|
if (cls < ARRAY_SIZE(debug_classes))
|
2005-09-23 12:52:07 +02:00
|
|
|
ret += wine_dbg_printf( "%s:%s:%s ", debug_classes[cls], channel->name, func );
|
2002-05-17 04:55:48 +02:00
|
|
|
if (format)
|
2005-09-23 12:52:07 +02:00
|
|
|
ret += funcs.dbg_vprintf( format, args );
|
2002-05-17 04:55:48 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2002-05-20 00:29:01 +02:00
|
|
|
/* wrappers to use the function pointers */
|
|
|
|
|
2019-04-03 19:23:43 +02:00
|
|
|
#undef wine_dbgstr_an
|
2002-05-20 00:29:01 +02:00
|
|
|
const char *wine_dbgstr_an( const char * s, int n )
|
|
|
|
{
|
2005-09-23 12:52:07 +02:00
|
|
|
return funcs.dbgstr_an(s, n);
|
2002-05-20 00:29:01 +02:00
|
|
|
}
|
|
|
|
|
2019-04-03 19:23:43 +02:00
|
|
|
#undef wine_dbgstr_wn
|
2002-05-20 00:29:01 +02:00
|
|
|
const char *wine_dbgstr_wn( const WCHAR *s, int n )
|
|
|
|
{
|
2005-09-23 12:52:07 +02:00
|
|
|
return funcs.dbgstr_wn(s, n);
|
2002-05-20 00:29:01 +02:00
|
|
|
}
|
|
|
|
|
2005-09-26 18:45:25 +02:00
|
|
|
void __wine_dbg_set_functions( const struct __wine_debug_functions *new_funcs,
|
|
|
|
struct __wine_debug_functions *old_funcs, size_t size )
|
2005-09-23 12:52:07 +02:00
|
|
|
{
|
2005-09-26 18:45:25 +02:00
|
|
|
if (old_funcs) memcpy( old_funcs, &funcs, min(sizeof(funcs),size) );
|
|
|
|
if (new_funcs) memcpy( &funcs, new_funcs, min(sizeof(funcs),size) );
|
2005-09-23 12:52:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct __wine_debug_functions funcs =
|
|
|
|
{
|
2005-09-26 18:45:25 +02:00
|
|
|
get_temp_buffer,
|
|
|
|
release_temp_buffer,
|
2005-09-23 12:52:07 +02:00
|
|
|
default_dbgstr_an,
|
|
|
|
default_dbgstr_wn,
|
|
|
|
default_dbg_vprintf,
|
|
|
|
default_dbg_vlog
|
|
|
|
};
|