From: Rémi Bernon rbernon@codeweavers.com
--- dlls/ntdll/thread.c | 12 ++++++++++-- dlls/ntdll/unix/debug.c | 12 ++++++++++-- dlls/winecrt0/debug.c | 24 +++++++++++++++--------- include/wine/debug.h | 20 +++++++++++++++++--- 4 files changed, 52 insertions(+), 16 deletions(-)
diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c index b0b61419e37..ed26c69908b 100644 --- a/dlls/ntdll/thread.c +++ b/dlls/ntdll/thread.c @@ -132,7 +132,7 @@ const char * __cdecl __wine_dbg_strdup( const char *str ) * __wine_dbg_header (NTDLL.@) */ int __cdecl __wine_dbg_header( enum __wine_debug_class cls, struct __wine_debug_channel *channel, - const char *function ) + const struct __wine_debug_context *context ) { static const char * const classes[] = { "fixme", "err", "warn", "trace" }; struct debug_info *info = get_info(); @@ -150,9 +150,17 @@ int __cdecl __wine_dbg_header( enum __wine_debug_class cls, struct __wine_debug_ } if (TRACE_ON(pid)) pos += sprintf( pos, "%04lx:", GetCurrentProcessId() ); pos += sprintf( pos, "%04lx:", GetCurrentThreadId() ); - if (function && cls < ARRAY_SIZE( classes )) + if (context && cls < ARRAY_SIZE( classes )) + { + const char *function; + + if (context->compat) function = (const char *)context; + else if (context->version != WINE_DEBUG_CONTEXT_VERSION) function = ""; + else function = context->function; + 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 bc0e3c1c694..7ee57544af2 100644 --- a/dlls/ntdll/unix/debug.c +++ b/dlls/ntdll/unix/debug.c @@ -302,7 +302,7 @@ int __cdecl __wine_dbg_output( const char *str ) * __wine_dbg_header (NTDLL.@) */ int __cdecl __wine_dbg_header( enum __wine_debug_class cls, struct __wine_debug_channel *channel, - const char *function ) + const struct __wine_debug_context *context ) { static const char * const classes[] = { "fixme", "err", "warn", "trace" }; struct debug_info *info = get_info(); @@ -323,9 +323,17 @@ int __cdecl __wine_dbg_header( enum __wine_debug_class cls, struct __wine_debug_ if (TRACE_ON(pid)) pos += sprintf( pos, "%04x:", (UINT)GetCurrentProcessId() ); pos += sprintf( pos, "%04x:", (UINT)GetCurrentThreadId() ); } - if (function && cls < ARRAY_SIZE( classes )) + if (context && cls < ARRAY_SIZE( classes )) + { + const char *function; + + if (context->compat) function = (const char *)context; + else if (context->version != WINE_DEBUG_CONTEXT_VERSION) function = ""; + else function = context->function; + 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/winecrt0/debug.c b/dlls/winecrt0/debug.c index 2ac4505fb85..82b7db657a7 100644 --- a/dlls/winecrt0/debug.c +++ b/dlls/winecrt0/debug.c @@ -34,9 +34,8 @@ WINE_DECLARE_DEBUG_CHANNEL(timestamp); static const char * (__cdecl *p__wine_dbg_strdup)( const char *str ); static int (__cdecl *p__wine_dbg_output)( const char *str ); static unsigned char (__cdecl *p__wine_dbg_get_channel_flags)( struct __wine_debug_channel *channel ); -static int (__cdecl *p__wine_dbg_header)( enum __wine_debug_class cls, - struct __wine_debug_channel *channel, - const char *function ); +static int (__cdecl *p__wine_dbg_header)( enum __wine_debug_class cls, struct __wine_debug_channel *channel, + const struct __wine_debug_context *context );
static const char * const debug_classes[] = { "fixme", "err", "warn", "trace" };
@@ -178,9 +177,8 @@ static int __cdecl fallback__wine_dbg_output( const char *str ) return fwrite( str, 1, len, stderr ); }
-static int __cdecl fallback__wine_dbg_header( enum __wine_debug_class cls, - struct __wine_debug_channel *channel, - const char *function ) +static int __cdecl fallback__wine_dbg_header( enum __wine_debug_class cls, struct __wine_debug_channel *channel, + const struct __wine_debug_context *context ) { char buffer[200], *pos = buffer;
@@ -196,9 +194,17 @@ static int __cdecl fallback__wine_dbg_header( enum __wine_debug_class cls, } if (TRACE_ON(pid)) pos += sprintf( pos, "%04x:", (UINT)GetCurrentProcessId() ); pos += sprintf( pos, "%04x:", (UINT)GetCurrentThreadId() ); - if (function && cls < ARRAY_SIZE( debug_classes )) + if (context && cls < ARRAY_SIZE( debug_classes )) + { + const char *function; + + if (context->compat) function = (const char *)context; + else if (context->version != WINE_DEBUG_CONTEXT_VERSION) function = ""; + else function = context->function; + snprintf( pos, sizeof(buffer) - (pos - buffer), "%s:%s:%s ", debug_classes[cls], channel->name, function ); + }
return fwrite( buffer, 1, strlen(buffer), stderr ); } @@ -243,10 +249,10 @@ unsigned char __cdecl __wine_dbg_get_channel_flags( struct __wine_debug_channel }
int __cdecl __wine_dbg_header( enum __wine_debug_class cls, struct __wine_debug_channel *channel, - const char *function ) + const struct __wine_debug_context *context ) { LOAD_FUNC( __wine_dbg_header ); - return p__wine_dbg_header( cls, channel, function ); + return p__wine_dbg_header( cls, channel, context ); }
#endif /* __WINE_PE_BUILD */ diff --git a/include/wine/debug.h b/include/wine/debug.h index c20924818dd..985c72866ff 100644 --- a/include/wine/debug.h +++ b/include/wine/debug.h @@ -87,6 +87,14 @@ struct __wine_debug_channel const enum __wine_debug_class __dbcl = __WINE_DBCL##dbcl; \ __WINE_DBG_LOG
+struct __wine_debug_context +{ + char compat; /* for backward compatibility */ + int version; /* for forward compatibility */ + const char *function; +}; +#define WINE_DEBUG_CONTEXT_VERSION 1 + #define __WINE_DBG_LOG(...) \ wine_dbg_log( __dbcl, __dbch, __func__, __VA_ARGS__); } } while(0)
@@ -113,7 +121,7 @@ extern unsigned char __cdecl __wine_dbg_get_channel_flags( struct __wine_debug_c extern const char * __cdecl __wine_dbg_strdup( const char *str ); extern int __cdecl __wine_dbg_output( const char *str ); extern int __cdecl __wine_dbg_header( enum __wine_debug_class cls, struct __wine_debug_channel *channel, - const char *function ); + const struct __wine_debug_context *context );
/* * Exported definitions and macros @@ -178,14 +186,20 @@ static inline int __wine_dbg_cdecl wine_dbg_vlog( enum __wine_debug_class cls, struct __wine_debug_channel *channel, const char *function, const char *format, va_list args ) { + struct __wine_debug_context info = + { + .version = WINE_DEBUG_CONTEXT_VERSION, + .function = function, + }; + struct __wine_debug_context *context = &info; int ret;
if (*format == '\1') /* special magic to avoid standard prefix */ { format++; - function = NULL; + context = NULL; } - if ((ret = __wine_dbg_header( cls, channel, function )) != -1) ret += wine_dbg_vprintf( format, args ); + if ((ret = __wine_dbg_header( cls, channel, context )) != -1) ret += wine_dbg_vprintf( format, args ); return ret; }