https://git.reactos.org/?p=reactos.git;a=commitdiff;h=cb979bb29316ebe476022e...
commit cb979bb29316ebe476022efe9cc7b2f40535982b Author: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org AuthorDate: Sun Nov 5 21:15:08 2017 +0100 Commit: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org CommitDate: Thu Aug 30 22:42:50 2018 +0200
[REACTOS] Introduce a "DEBUGFORMAT" environment variable that allows to select different debug trace formats. CORE-12671
- The default format is used when no format name is specified: this is the one we use so far in ReactOS:
<debug_class>:(<file>:<line>) <message>
with "debug_class" being "trace", "warn", "err".
- The "wine" format is the one used by Wine. It can be used when trying to diff-compare traces for a module with the corresponding one obtained from a Wine run. It can also be useful because the logging of Wine-synced code assumes that the function names are automatically added by the helper macros "FIXME()", "TRACE()", "WARN()" or "ERR()", and not manually inside the logging string given to these macros: for example:
FIXME("(%params) message\n", params);
displays:
fixme:<module>:SomeFunc(params) message
- The "extended" (or "ext") format is very noisy and tries to output a lot of information; it is a hybrid of the previous two formats:
<debug_class>:(<file>:<line>):<channel>:SomeFunc <message>
Support for displaying the current process ID is added in addition to the already existing support for thread ID. --- sdk/include/reactos/wine/debug.h | 2 +- sdk/lib/3rdparty/libwine/debug.c | 112 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 108 insertions(+), 6 deletions(-)
diff --git a/sdk/include/reactos/wine/debug.h b/sdk/include/reactos/wine/debug.h index cd366ab375..35aefc9852 100644 --- a/sdk/include/reactos/wine/debug.h +++ b/sdk/include/reactos/wine/debug.h @@ -141,7 +141,7 @@ struct __wine_debug_channel
#define __WINE_DPRINTF(dbcl,dbch) \ (!__WINE_GET_DEBUGGING(dbcl,(dbch)) || \ - (ros_dbg_log(__WINE_DBCL##dbcl,(dbch),__FILE__,"",__LINE__,"") == -1)) ? \ + (ros_dbg_log(__WINE_DBCL##dbcl,(dbch),__RELFILE__,__FUNCTION__,__LINE__,"") == -1)) ? \ (void)0 : (void)wine_dbg_printf
#define __WINE_PRINTF_ATTR(fmt, args) diff --git a/sdk/lib/3rdparty/libwine/debug.c b/sdk/lib/3rdparty/libwine/debug.c index dbcce115d2..9c6eba2c77 100644 --- a/sdk/lib/3rdparty/libwine/debug.c +++ b/sdk/lib/3rdparty/libwine/debug.c @@ -35,6 +35,7 @@ #include <rtlfuncs.h> #include <cmfuncs.h>
+WINE_DECLARE_DEBUG_CHANNEL(pid); WINE_DECLARE_DEBUG_CHANNEL(tid);
ULONG @@ -59,6 +60,18 @@ static struct __wine_debug_functions funcs;
static void debug_init(void);
+ +/* Wine format */ +static int winefmt_default_dbg_vlog( enum __wine_debug_class cls, struct __wine_debug_channel *channel, + const char *file, const char *func, const int line, const char *format, va_list args ); +/* ReactOS format (default) */ +static int rosfmt_default_dbg_vlog( enum __wine_debug_class cls, struct __wine_debug_channel *channel, + const char *file, const char *func, const int line, const char *format, va_list args ); +/* Extended format */ +static int extfmt_default_dbg_vlog( enum __wine_debug_class cls, struct __wine_debug_channel *channel, + const char *file, const char *func, const int line, const char *format, va_list args ); + + static int __cdecl cmp_name( const void *p1, const void *p2 ) { const char *name = p1; @@ -184,6 +197,25 @@ static void parse_options( const char *str ) free( options ); }
+/* + * The syntax of the DEBUGCHANNEL environment variable is: + * DEBUGCHANNEL=[class]+xxx,[class]-yyy,... + * + * For example: DEBUGCHANNEL=+all,warn-heap + * turns on all messages except warning heap messages. + * + * The available message classes are: err, warn, fixme, trace. + * + * In order to select a different debug trace format, the + * DEBUGFORMAT environment variable should be used: + * + * DEBUGFORMAT=fmt + * + * where fmt is the format name: 'wine', or 'extended' (abbreviation: 'ext'). + * If no format or an invalid one is specified, the fall-back default format + * is used instead. + */ + /* initialize all options at startup */ static void debug_init(void) { @@ -206,6 +238,34 @@ static void debug_init(void) free(wine_debug); } } + + dwLength = GetEnvironmentVariableA("DEBUGFORMAT", NULL, 0); + if (dwLength) + { + wine_debug = malloc(dwLength); + if (wine_debug) + { + if (GetEnvironmentVariableA("DEBUGFORMAT", wine_debug, dwLength) < dwLength) + { + if (strcmp(wine_debug, "wine") == 0) + { + funcs.dbg_vlog = winefmt_default_dbg_vlog; + } + else + if (strcmp(wine_debug, "extended") == 0 || + strcmp(wine_debug, "ext") == 0) + { + funcs.dbg_vlog = extfmt_default_dbg_vlog; + } + else + { + funcs.dbg_vlog = rosfmt_default_dbg_vlog; + } + } + free(wine_debug); + } + } + SetLastError(LastError); }
@@ -413,19 +473,36 @@ static int default_dbg_vprintf( const char *format, va_list args )
/* default implementation of wine_dbg_vlog */ -static int default_dbg_vlog( enum __wine_debug_class cls, struct __wine_debug_channel *channel, - const char *file, const char *func, const int line, const char *format, va_list args ) +/* Wine format */ +static int winefmt_default_dbg_vlog( enum __wine_debug_class cls, struct __wine_debug_channel *channel, + const char *file, const char *func, const int line, const char *format, va_list args ) +{ + int ret = 0; + + if (TRACE_ON(pid)) + ret += wine_dbg_printf( "%04x:", HandleToULong(NtCurrentTeb()->ClientId.UniqueProcess) ); + ret += wine_dbg_printf( "%04x:", HandleToULong(NtCurrentTeb()->ClientId.UniqueThread) ); + + if (cls < sizeof(debug_classes)/sizeof(debug_classes[0])) + ret += wine_dbg_printf( "%s:%s:%s ", debug_classes[cls], channel->name, func ); + if (format) + ret += funcs.dbg_vprintf( format, args ); + return ret; +} +/* ReactOS format (default) */ +static int rosfmt_default_dbg_vlog( enum __wine_debug_class cls, struct __wine_debug_channel *channel, + const char *file, const char *func, const int line, const char *format, va_list args ) { int ret = 0;
if (TRACE_ON(tid)) - ret += wine_dbg_printf("%04x:", HandleToULong(NtCurrentTeb()->ClientId.UniqueThread)); + ret += wine_dbg_printf( "%04x:", HandleToULong(NtCurrentTeb()->ClientId.UniqueThread) );
if (cls < sizeof(debug_classes)/sizeof(debug_classes[0])) ret += wine_dbg_printf( "%s:", debug_classes[cls] );
if (file && line) - ret += wine_dbg_printf ( "(%s:%d) ", file, line ); + ret += wine_dbg_printf( "(%s:%d) ", file, line ); else ret += wine_dbg_printf( "%s:%s: ", channel->name, func );
@@ -433,6 +510,31 @@ static int default_dbg_vlog( enum __wine_debug_class cls, struct __wine_debug_ch ret += funcs.dbg_vprintf( format, args ); return ret; } +/* Extended format */ +static int extfmt_default_dbg_vlog( enum __wine_debug_class cls, struct __wine_debug_channel *channel, + const char *file, const char *func, const int line, const char *format, va_list args ) +{ + int ret = 0; + + if (TRACE_ON(pid) || TRACE_ON(tid)) + { + ret += wine_dbg_printf( "[%04x:%04x]:", + (TRACE_ON(pid) ? HandleToULong(NtCurrentTeb()->ClientId.UniqueProcess) : 0), + (TRACE_ON(tid) ? HandleToULong(NtCurrentTeb()->ClientId.UniqueThread) : 0) ); + } + + if (cls < sizeof(debug_classes)/sizeof(debug_classes[0])) + ret += wine_dbg_printf( "%s:", debug_classes[cls] ); + + if (file && line) + ret += wine_dbg_printf( "(%s:%d):", file, line ); + + ret += wine_dbg_printf( "%s:%s ", channel->name, func ); + + if (format) + ret += funcs.dbg_vprintf( format, args ); + return ret; +}
/* wrappers to use the function pointers */
@@ -460,5 +562,5 @@ static struct __wine_debug_functions funcs = default_dbgstr_an, default_dbgstr_wn, default_dbg_vprintf, - default_dbg_vlog + rosfmt_default_dbg_vlog };