File size: 12,707 Bytes
ff994b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
diff --git a/src/coreclr/src/inc/clrconfigvalues.h b/src/coreclr/src/inc/clrconfigvalues.h
index 32d07226003dc7..f92167f0dfdb5b 100644
--- a/src/coreclr/src/inc/clrconfigvalues.h
+++ b/src/coreclr/src/inc/clrconfigvalues.h
@@ -712,7 +712,7 @@ RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeProcNumbers, W("EventPipeProcNumbers"
 //
 // Diagnostics Ports
 //
-RRETAIL_CONFIG_DWORD_INFO_EX(EXTERNAL_DOTNET_DiagnosticPortSuspend, W("DOTNET_DiagnosticPortSuspend"), 1, "This will cause the runtime to pause during startup before major subsystems are started.  Resume using the Diagnostics IPC ResumeStartup command.", CLRConfig::DontPrependCOMPlus_);
+RETAIL_CONFIG_DWORD_INFO_EX(EXTERNAL_DOTNET_DiagnosticPortSuspend, W("DOTNET_DiagnosticPortSuspend"), 0, "This will cause the runtime to pause during startup before major subsystems are started.  Resume using the Diagnostics IPC ResumeStartup command.", CLRConfig::DontPrependCOMPlus_);
 RETAIL_CONFIG_STRING_INFO_EX(EXTERNAL_DOTNET_DiagnosticPorts, W("DOTNET_DiagnosticPorts"), "A semicolon delimited list of additional Diagnostic Ports, where a Diagnostic Port is a NamedPipe path without '\\\\.\\pipe\\' on Windows or the full path of Unix Domain Socket on Linux/Unix followed by optional tags, e.g., '<path>,listen,nosuspend;<path>,connect'", CLRConfig::DontPrependCOMPlus_);
 
 //
diff --git a/src/coreclr/src/vm/ipcstreamfactory.cpp b/src/coreclr/src/vm/ipcstreamfactory.cpp
index df18c7602585a0..75b7fb3a0c4117 100644
--- a/src/coreclr/src/vm/ipcstreamfactory.cpp
+++ b/src/coreclr/src/vm/ipcstreamfactory.cpp
@@ -15,11 +15,11 @@ CQuickArrayList<LPSTR> split(LPSTR string, LPCSTR delimiters)
 {
     CQuickArrayList<LPSTR> parts;
     char *context;
-    char *portConfig = nullptr;
+    char *part = nullptr;
     for (char *cursor = string; ; cursor = nullptr)
     {
-        if ((portConfig = strtok_s(cursor, delimiters, &context)) != nullptr)
-            parts.Push(portConfig);
+        if ((part = strtok_s(cursor, delimiters, &context)) != nullptr)
+            parts.Push(part);
         else
             break;
     }
@@ -110,11 +110,14 @@ bool IpcStreamFactory::Configure(ErrorCallback callback)
 
             ASSERT(portConfigParts.Size() >= 1);
             if (portConfigParts.Size() == 0)
+            {
+                fSuccess &= false;
                 continue;
+            }
 
-            builder.WithPath(portConfigParts.Pop());
-            while (portConfigParts.Size() > 0)
+            while (portConfigParts.Size() > 1)
                 builder.WithTag(portConfigParts.Pop());
+            builder.WithPath(portConfigParts.Pop());
 
             const bool fBuildSuccess = BuildAndAddPort(builder, callback);
             STRESS_LOG1(LF_DIAGNOSTICS_PORT, LL_INFO10, "IpcStreamFactory::Configure - Diagnostic Port creation succeeded? %d \n", fBuildSuccess);
diff --git a/src/coreclr/src/vm/ipcstreamfactory.h b/src/coreclr/src/vm/ipcstreamfactory.h
index 80554b7d523884..cfd286beee0bba 100644
--- a/src/coreclr/src/vm/ipcstreamfactory.h
+++ b/src/coreclr/src/vm/ipcstreamfactory.h
@@ -32,7 +32,7 @@ class IpcStreamFactory
         DiagnosticPortType Type = DiagnosticPortType::LISTEN;
         DiagnosticPortSuspendMode SuspendMode = DiagnosticPortSuspendMode::NOSUSPEND;
 
-        DiagnosticPortBuilder WithPath(LPSTR path) { Path = _strdup(path); return *this; }
+        DiagnosticPortBuilder WithPath(LPSTR path) { Path = path != nullptr ? _strdup(path) : nullptr; return *this; }
         DiagnosticPortBuilder WithType(DiagnosticPortType type) { Type = type; return *this; }
         DiagnosticPortBuilder WithSuspendMode(DiagnosticPortSuspendMode mode) { SuspendMode = mode; return *this; }
         DiagnosticPortBuilder WithTag(LPSTR tag)
diff --git a/src/tests/tracing/eventpipe/common/IpcUtils.cs b/src/tests/tracing/eventpipe/common/IpcUtils.cs
index bf17e1e27e837b..73e817859ad828 100644
--- a/src/tests/tracing/eventpipe/common/IpcUtils.cs
+++ b/src/tests/tracing/eventpipe/common/IpcUtils.cs
@@ -21,8 +21,8 @@ namespace Tracing.Tests.Common
 {
     public static class Utils
     {
-        public static readonly string DiagnosticsMonitorAddressEnvKey = "DOTNET_DiagnosticsMonitorAddress";
-        public static readonly string DiagnosticsMonitorPauseOnStartEnvKey = "DOTNET_DiagnosticsMonitorPauseOnStart";
+        public static readonly string DiagnosticPortsEnvKey = "DOTNET_DiagnosticPorts";
+        public static readonly string DiagnosticPortSuspend = "DOTNET_DiagnosticPortSuspend";
 
         public static async Task<T> WaitTillTimeout<T>(Task<T> task, TimeSpan timeout)
         {
diff --git a/src/tests/tracing/eventpipe/pauseonstart/pauseonstart.cs b/src/tests/tracing/eventpipe/pauseonstart/pauseonstart.cs
index 4065cd586feef1..e87d367651b06b 100644
--- a/src/tests/tracing/eventpipe/pauseonstart/pauseonstart.cs
+++ b/src/tests/tracing/eventpipe/pauseonstart/pauseonstart.cs
@@ -28,7 +28,7 @@ public static async Task<bool> TEST_RuntimeResumesExecutionWithCommand()
             var server = new ReverseServer(serverName);
             Task<bool> subprocessTask = Utils.RunSubprocess(
                 currentAssembly: Assembly.GetExecutingAssembly(),
-                environment: new Dictionary<string,string> { { Utils.DiagnosticsMonitorAddressEnvKey, serverName } },
+                environment: new Dictionary<string,string> { { Utils.DiagnosticPortsEnvKey, $"{serverName},connect,suspend" } },
                 duringExecution: async (_) =>
                 {
                     Stream stream = await server.AcceptAsync();
@@ -56,7 +56,7 @@ public static async Task<bool> TEST_TracesHaveRelevantEvents()
             using var memoryStream = new MemoryStream();
             Task<bool> subprocessTask = Utils.RunSubprocess(
                 currentAssembly: Assembly.GetExecutingAssembly(),
-                environment: new Dictionary<string,string> { { Utils.DiagnosticsMonitorAddressEnvKey, serverName } },
+                environment: new Dictionary<string,string> { { Utils.DiagnosticPortsEnvKey, $"{serverName},connect,suspend" } },
                 duringExecution: async (pid) =>
                 {
                     Stream stream = await server.AcceptAsync();
@@ -114,7 +114,7 @@ public static async Task<bool> TEST_MultipleSessionsCanBeStartedWhilepaused()
             using var memoryStream3 = new MemoryStream();
             Task<bool> subprocessTask = Utils.RunSubprocess(
                 currentAssembly: Assembly.GetExecutingAssembly(),
-                environment: new Dictionary<string,string> { { Utils.DiagnosticsMonitorAddressEnvKey, serverName } },
+                environment: new Dictionary<string,string> { { Utils.DiagnosticPortsEnvKey, $"{serverName},connect,suspend" } },
                 duringExecution: async (pid) =>
                 {
                     Stream stream = await server.AcceptAsync();
@@ -207,7 +207,7 @@ public static async Task<bool> TEST_CanStartAndStopSessionWhilepaused()
             using var memoryStream3 = new MemoryStream();
             Task<bool> subprocessTask = Utils.RunSubprocess(
                 currentAssembly: Assembly.GetExecutingAssembly(),
-                environment: new Dictionary<string,string> { { Utils.DiagnosticsMonitorAddressEnvKey, serverName } },
+                environment: new Dictionary<string,string> { { Utils.DiagnosticPortsEnvKey, $"{serverName},connect,suspend" } },
                 duringExecution: async (pid) =>
                 {
                     Stream stream = await server.AcceptAsync();
@@ -271,7 +271,7 @@ public static async Task<bool> TEST_DisabledCommandsError()
             using var memoryStream3 = new MemoryStream();
             Task<bool> subprocessTask = Utils.RunSubprocess(
                 currentAssembly: Assembly.GetExecutingAssembly(),
-                environment: new Dictionary<string,string> { { Utils.DiagnosticsMonitorAddressEnvKey, serverName } },
+                environment: new Dictionary<string,string> { { Utils.DiagnosticPortsEnvKey, $"{serverName},connect,suspend" } },
                 duringExecution: async (pid) =>
                 {
                     Stream stream = await server.AcceptAsync();
diff --git a/src/tests/tracing/eventpipe/reverse/reverse.cs b/src/tests/tracing/eventpipe/reverse/reverse.cs
index 05436e574d6436..6ce09ea82b81b7 100644
--- a/src/tests/tracing/eventpipe/reverse/reverse.cs
+++ b/src/tests/tracing/eventpipe/reverse/reverse.cs
@@ -28,8 +28,7 @@ public static async Task<bool> TEST_RuntimeIsResilientToServerClosing()
                 currentAssembly: Assembly.GetExecutingAssembly(),
                 environment: new Dictionary<string,string> 
                 {
-                    { Utils.DiagnosticsMonitorAddressEnvKey, serverName },
-                    { Utils.DiagnosticsMonitorPauseOnStartEnvKey, "0" }
+                    { Utils.DiagnosticPortsEnvKey, $"{serverName},connect,nosuspend" }
                 },
                 duringExecution: async (_) =>
                 {
@@ -59,8 +58,7 @@ public static async Task<bool> TEST_RuntimeConnectsToExistingServer()
                 currentAssembly: Assembly.GetExecutingAssembly(),
                 environment: new Dictionary<string,string> 
                 {
-                    { Utils.DiagnosticsMonitorAddressEnvKey, serverName },
-                    { Utils.DiagnosticsMonitorPauseOnStartEnvKey, "0" }
+                    { Utils.DiagnosticPortsEnvKey, $"{serverName},connect,nosuspend" }
                 },
                 duringExecution: async (_) => 
                 {
@@ -85,8 +83,7 @@ public static async Task<bool> TEST_CanConnectServerAndClientAtSameTime()
                 currentAssembly: Assembly.GetExecutingAssembly(),
                 environment: new Dictionary<string,string> 
                 {
-                    { Utils.DiagnosticsMonitorAddressEnvKey, serverName },
-                    { Utils.DiagnosticsMonitorPauseOnStartEnvKey, "0" }
+                    { Utils.DiagnosticPortsEnvKey, $"{serverName},connect,nosuspend" }
                 },
                 duringExecution: async (int pid) =>
                 {
@@ -139,8 +136,7 @@ public static async Task<bool> TEST_ServerWorksIfClientDoesntAccept()
                 currentAssembly: Assembly.GetExecutingAssembly(),
                 environment: new Dictionary<string,string> 
                 {
-                    { Utils.DiagnosticsMonitorAddressEnvKey, serverName },
-                    { Utils.DiagnosticsMonitorPauseOnStartEnvKey, "0" }
+                    { Utils.DiagnosticPortsEnvKey, $"{serverName},connect,nosuspend" }
                 },
                 duringExecution: async (int pid) =>
                 {
@@ -181,8 +177,7 @@ public static async Task<bool> TEST_ServerIsResilientToNoBufferAgent()
                 currentAssembly: Assembly.GetExecutingAssembly(),
                 environment: new Dictionary<string,string> 
                 {
-                    { Utils.DiagnosticsMonitorAddressEnvKey, serverName },
-                    { Utils.DiagnosticsMonitorPauseOnStartEnvKey, "0" }
+                    { Utils.DiagnosticPortsEnvKey, $"{serverName},connect,nosuspend" }
                 },
                 duringExecution: async (int pid) =>
                 {
@@ -220,8 +215,7 @@ public static async Task<bool> TEST_StandardConnectionStillWorksIfReverseConnect
                 currentAssembly: Assembly.GetExecutingAssembly(),
                 environment: new Dictionary<string,string> 
                 {
-                    { Utils.DiagnosticsMonitorAddressEnvKey, serverName },
-                    { Utils.DiagnosticsMonitorPauseOnStartEnvKey, "0" }
+                    { Utils.DiagnosticPortsEnvKey, $"{serverName},connect,nosuspend" }
                 },
                 duringExecution: async (int pid) =>
                 {
diff --git a/src/tests/tracing/eventpipe/reverseouter/reverseouter.cs b/src/tests/tracing/eventpipe/reverseouter/reverseouter.cs
index ff01fbc0f449f1..6d3c0e4657cd84 100644
--- a/src/tests/tracing/eventpipe/reverseouter/reverseouter.cs
+++ b/src/tests/tracing/eventpipe/reverseouter/reverseouter.cs
@@ -28,8 +28,7 @@ public static async Task<bool> TEST_ReverseConnectionCanRecycleWhileTracing()
                 currentAssembly: Assembly.GetExecutingAssembly(),
                 environment: new Dictionary<string,string> 
                 {
-                    { Utils.DiagnosticsMonitorAddressEnvKey, serverName },
-                    { Utils.DiagnosticsMonitorPauseOnStartEnvKey, "0" }
+                    { Utils.DiagnosticPortsEnvKey, $"{serverName},connect,nosuspend" }
                 },
                 duringExecution: async (int pid) =>
                 {