Commit c2d84da8 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Copy the implementation of __wine_dbg_strdup and __wine_dbg_header to the PE side.

parent 2084fbd9
......@@ -34,12 +34,33 @@
WINE_DECLARE_DEBUG_CHANNEL(relay);
WINE_DECLARE_DEBUG_CHANNEL(thread);
WINE_DECLARE_DEBUG_CHANNEL(pid);
WINE_DECLARE_DEBUG_CHANNEL(timestamp);
struct _KUSER_SHARED_DATA *user_shared_data = (void *)0x7ffe0000;
struct debug_info
{
unsigned int str_pos; /* current position in strings buffer */
unsigned int out_pos; /* current position in output buffer */
char strings[1020]; /* buffer for temporary strings */
char output[1020]; /* current output line */
};
C_ASSERT( sizeof(struct debug_info) == 0x800 );
static int nb_debug_options;
static struct __wine_debug_channel *debug_options;
static inline struct debug_info *get_info(void)
{
#ifdef _WIN64
return (struct debug_info *)((TEB32 *)((char *)NtCurrentTeb() + 0x2000) + 1);
#else
return (struct debug_info *)(NtCurrentTeb() + 1);
#endif
}
static void init_options(void)
{
unsigned int offset = page_size * (sizeof(void *) / 4);
......@@ -81,7 +102,14 @@ unsigned char __cdecl __wine_dbg_get_channel_flags( struct __wine_debug_channel
*/
const char * __cdecl __wine_dbg_strdup( const char *str )
{
return unix_funcs->dbg_strdup( str );
struct debug_info *info = get_info();
unsigned int pos = info->str_pos;
size_t n = strlen( str ) + 1;
assert( n <= sizeof(info->strings) );
if (pos + n > sizeof(info->strings)) pos = 0;
info->str_pos = pos + n;
return memcpy( info->strings + pos, str, n );
}
/***********************************************************************
......@@ -90,7 +118,27 @@ const char * __cdecl __wine_dbg_strdup( const char *str )
int __cdecl __wine_dbg_header( enum __wine_debug_class cls, struct __wine_debug_channel *channel,
const char *function )
{
return unix_funcs->dbg_header( cls, channel, function );
static const char * const classes[] = { "fixme", "err", "warn", "trace" };
struct debug_info *info = get_info();
char *pos = info->output;
if (!(__wine_dbg_get_channel_flags( channel ) & (1 << cls))) return -1;
/* only print header if we are at the beginning of the line */
if (info->out_pos) return 0;
if (TRACE_ON(timestamp))
{
ULONG ticks = NtGetTickCount();
pos += sprintf( pos, "%3u.%03u:", ticks / 1000, ticks % 1000 );
}
if (TRACE_ON(pid)) pos += sprintf( pos, "%04x:", GetCurrentProcessId() );
pos += sprintf( pos, "%04x:", GetCurrentThreadId() );
if (function && cls < ARRAY_SIZE( classes ))
pos += snprintf( pos, sizeof(info->output) - (pos - info->output), "%s:%s:%s ",
classes[cls], channel->name, function );
info->out_pos = pos - info->output;
return info->out_pos;
}
/***********************************************************************
......
......@@ -277,7 +277,7 @@ int __cdecl __wine_dbg_header( enum __wine_debug_class cls, struct __wine_debug_
{
static const char * const classes[] = { "fixme", "err", "warn", "trace" };
struct debug_info *info = get_info();
char buffer[200], *pos = buffer;
char *pos = info->output;
if (!(__wine_dbg_get_channel_flags( channel ) & (1 << cls))) return -1;
......@@ -295,10 +295,10 @@ int __cdecl __wine_dbg_header( enum __wine_debug_class cls, struct __wine_debug_
pos += sprintf( pos, "%04x:", GetCurrentThreadId() );
}
if (function && cls < ARRAY_SIZE( classes ))
snprintf( pos, sizeof(buffer) - (pos - buffer), "%s:%s:%s ",
classes[cls], channel->name, function );
return append_output( info, buffer, strlen( buffer ));
pos += snprintf( pos, sizeof(info->output) - (pos - info->output), "%s:%s:%s ",
classes[cls], channel->name, function );
info->out_pos = pos - info->output;
return info->out_pos;
}
/***********************************************************************
......
......@@ -1850,9 +1850,7 @@ static struct unix_funcs unix_funcs =
init_builtin_dll,
init_unix_lib,
unwind_builtin_dll,
__wine_dbg_strdup,
__wine_dbg_output,
__wine_dbg_header,
};
......
......@@ -26,7 +26,7 @@
struct _DISPATCHER_CONTEXT;
/* increment this when you change the function table */
#define NTDLL_UNIXLIB_VERSION 121
#define NTDLL_UNIXLIB_VERSION 122
struct unix_funcs
{
......@@ -80,10 +80,7 @@ struct unix_funcs
CONTEXT *context );
/* debugging functions */
const char * (CDECL *dbg_strdup)( const char *str );
int (CDECL *dbg_output)( const char *str );
int (CDECL *dbg_header)( enum __wine_debug_class cls, struct __wine_debug_channel *channel,
const char *function );
};
#endif /* __NTDLL_UNIXLIB_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment