From a3c6f83abc21e88b69bb6b50e02892ab78a04774 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Mon, 27 May 2019 09:19:56 +1000
Subject: [PATCH] libwine: Add process specific debug channels.

---
 dlls/ntdll/unix/debug.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/dlls/ntdll/unix/debug.c b/dlls/ntdll/unix/debug.c
index 7bc7787c9de..cf4ce6fb9a6 100644
--- a/dlls/ntdll/unix/debug.c
+++ b/dlls/ntdll/unix/debug.c
@@ -34,6 +34,7 @@
 #endif
 
 #include "wine/debug.h"
+#include "wine/library.h"
 #include "ntdll_misc.h"
 
 WINE_DECLARE_DEBUG_CHANNEL(pid);
@@ -107,10 +108,22 @@ static void add_option( const char *name, unsigned char set, unsigned char clear
     nb_debug_options++;
 }
 
+/* get name of the current process */
+static const char *get_process_name( void )
+{
+    const char *ret, *tmp;
+    if (__wine_main_argc < 2) return NULL;
+    ret = __wine_main_argv[1];
+    if ((tmp = strrchr(ret, '/'))) ret = ++tmp;
+    if ((tmp = strrchr(ret, '\\'))) ret = ++tmp;
+    return ret;
+}
+
 /* parse a set of debugging option specifications and add them to the option list */
 static void parse_options( const char *str )
 {
-    char *opt, *next, *options;
+    char *opt, *next, *popt, *options;
+    const char *process = get_process_name();
     unsigned int i;
 
     if (!(options = strdup(str))) return;
@@ -121,6 +134,17 @@ static void parse_options( const char *str )
 
         if ((next = strchr( opt, ',' ))) *next++ = 0;
 
+        if ((popt = strchr( opt, ':' )))
+        {
+            unsigned int inv = 0;
+            *popt = 0;
+            if (!process) continue;
+            if (*opt == '-' || *opt == '+')
+                inv = (*opt++ == '-');
+            if (inv == !strcmp( opt, process )) continue;
+            opt = ++popt;
+        }
+
         p = opt + strcspn( opt, "+-" );
         if (!p[0]) p = opt;  /* assume it's a debug channel name */
 
@@ -161,7 +185,7 @@ static void debug_usage(void)
 {
     static const char usage[] =
         "Syntax of the WINEDEBUG variable:\n"
-        "  WINEDEBUG=[class]+xxx,[class]-yyy,...\n\n"
+        "  WINEDEBUG=[+process:][class]+xxx,[-process:][class]-yyy,...\n\n"
         "Example: WINEDEBUG=+relay,warn-heap\n"
         "    turns on relay traces, disable heap warnings\n"
         "Available message classes: err, warn, fixme, trace\n";
-- 
2.26.2

