Module: wine Branch: master Commit: c2d84da8134cc9d07a114561c10c75bf91078370 URL: https://source.winehq.org/git/wine.git/?a=commit;h=c2d84da8134cc9d07a114561c...
Author: Alexandre Julliard julliard@winehq.org Date: Tue Jun 15 17:16:30 2021 +0200
ntdll: Copy the implementation of __wine_dbg_strdup and __wine_dbg_header to the PE side.
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/ntdll/thread.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++-- dlls/ntdll/unix/debug.c | 10 +++++----- dlls/ntdll/unix/loader.c | 2 -- dlls/ntdll/unixlib.h | 5 +---- 4 files changed, 56 insertions(+), 13 deletions(-)
diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c index bcf010724c4..d86d20448bf 100644 --- a/dlls/ntdll/thread.c +++ b/dlls/ntdll/thread.c @@ -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; }
/*********************************************************************** diff --git a/dlls/ntdll/unix/debug.c b/dlls/ntdll/unix/debug.c index 753bc36e469..0272e68bea6 100644 --- a/dlls/ntdll/unix/debug.c +++ b/dlls/ntdll/unix/debug.c @@ -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; }
/*********************************************************************** diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index 0b2a7f3721c..fca63141ba3 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -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, };
diff --git a/dlls/ntdll/unixlib.h b/dlls/ntdll/unixlib.h index d0f2f4ed508..cbe5c9d3ccd 100644 --- a/dlls/ntdll/unixlib.h +++ b/dlls/ntdll/unixlib.h @@ -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 */