Alexandre Julliard : include: Make wine_dbg_log() into an inline function.

Alexandre Julliard julliard at winehq.org
Wed Apr 3 15:26:18 CDT 2019


Module: wine
Branch: master
Commit: cf8193df5b4c5a09208e40d8f3183c00187c8bd0
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=cf8193df5b4c5a09208e40d8f3183c00187c8bd0

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Wed Apr  3 19:27:13 2019 +0200

include: Make wine_dbg_log() into an inline function.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/debugtools.c | 32 ++++++++++++++++++++++++++++++++
 dlls/ntdll/ntdll.spec   |  1 +
 include/wine/debug.h    | 30 +++++++++++++++++++++++++++---
 libs/wine/debug.c       |  2 ++
 4 files changed, 62 insertions(+), 3 deletions(-)

diff --git a/dlls/ntdll/debugtools.c b/dlls/ntdll/debugtools.c
index 1e4a3a1..94d2de7 100644
--- a/dlls/ntdll/debugtools.c
+++ b/dlls/ntdll/debugtools.c
@@ -276,6 +276,38 @@ 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 )
+{
+    static const char * const classes[] = { "fixme", "err", "warn", "trace" };
+    struct debug_info *info = get_info();
+    char buffer[200], *pos = buffer;
+
+    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 > info->output) return 0;
+
+    if (init_done)
+    {
+        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 ))
+        snprintf( pos, sizeof(buffer) - (pos - buffer), "%s:%s:%s ",
+                  classes[cls], channel->name, function );
+
+    return append_output( info, buffer, strlen( buffer ));
+}
+
+/***********************************************************************
  *		NTDLL_dbg_vprintf
  */
 static int NTDLL_dbg_vprintf( const char *format, va_list args )
diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index b608ab9..292b0f6 100644
--- a/dlls/ntdll/ntdll.spec
+++ b/dlls/ntdll/ntdll.spec
@@ -1507,6 +1507,7 @@
 
 # Debugging
 @ cdecl -norelay __wine_dbg_get_channel_flags(ptr)
+@ cdecl -norelay __wine_dbg_header(long long str)
 @ cdecl -norelay __wine_dbg_output(str)
 @ cdecl -norelay __wine_dbg_strdup(str)
 
diff --git a/include/wine/debug.h b/include/wine/debug.h
index 416b6c8..e95fcfb 100644
--- a/include/wine/debug.h
+++ b/include/wine/debug.h
@@ -161,6 +161,8 @@ extern void __wine_dbg_set_functions( const struct __wine_debug_functions *new_f
                                       struct __wine_debug_functions *old_funcs, size_t size );
 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 );
 
 /*
  * Exported definitions and macros
@@ -170,9 +172,6 @@ extern int __cdecl __wine_dbg_output( const char *str );
    quotes.  The string will be valid for some time, but not indefinitely
    as strings are re-used.  */
 
-extern int wine_dbg_log( enum __wine_debug_class cls, struct __wine_debug_channel *ch, const char *func,
-                         const char *format, ... ) __WINE_PRINTF_ATTR(4,5);
-
 #if (defined(__x86_64__) || defined(__aarch64__)) && defined(__GNUC__) && defined(__WINE_USE_MSVCRT)
 # define __wine_dbg_cdecl __cdecl
 # define __wine_dbg_va_list __builtin_ms_va_list
@@ -209,6 +208,31 @@ static inline int __wine_dbg_cdecl wine_dbg_printf( const char *format, ... )
     return __wine_dbg_output( buffer );
 }
 
+static int __wine_dbg_cdecl wine_dbg_log( enum __wine_debug_class cls,
+                                          struct __wine_debug_channel *channel, const char *func,
+                                          const char *format, ... ) __WINE_PRINTF_ATTR(4,5);
+static inline int __wine_dbg_cdecl wine_dbg_log( enum __wine_debug_class cls,
+                                                 struct __wine_debug_channel *channel,
+                                                 const char *function, const char *format, ... )
+{
+    char buffer[1024];
+    __wine_dbg_va_list args;
+    int ret;
+
+    if (*format == '\1')  /* special magic to avoid standard prefix */
+    {
+        format++;
+        function = NULL;
+    }
+    if ((ret = __wine_dbg_header( cls, channel, function )) == -1) return ret;
+
+    __wine_dbg_va_start( args, format );
+    vsnprintf( buffer, sizeof(buffer), format, args );
+    __wine_dbg_va_end( args );
+    ret += __wine_dbg_output( buffer );
+    return ret;
+}
+
 static inline const char *wine_dbgstr_an( const char *str, int n )
 {
     static const char hex[16] = "0123456789abcdef";
diff --git a/libs/wine/debug.c b/libs/wine/debug.c
index b9c7e0b..b19fefe 100644
--- a/libs/wine/debug.c
+++ b/libs/wine/debug.c
@@ -33,6 +33,7 @@
 #define __wine_dbg_get_channel_flags __wine_dbg_get_channel_flags_inline
 #define wine_dbg_sprintf wine_dbg_sprintf_inline
 #define wine_dbg_printf wine_dbg_printf_inline
+#define wine_dbg_log wine_dbg_log_inline
 #define wine_dbgstr_an wine_dbgstr_an_inline
 #define wine_dbgstr_wn wine_dbgstr_wn_inline
 #include "wine/debug.h"
@@ -252,6 +253,7 @@ const char *wine_dbg_sprintf( const char *format, ... )
 
 
 /* varargs wrapper for funcs.dbg_vlog */
+#undef wine_dbg_log
 int wine_dbg_log( enum __wine_debug_class cls, struct __wine_debug_channel *channel,
                   const char *func, const char *format, ... )
 {




More information about the wine-cvs mailing list