Extend diagnostics to handle tcpip diagnostics client option (#2833)
authorMitchell Hwang <16830051+mdh1418@users.noreply.github.com>
Wed, 16 Feb 2022 19:16:23 +0000 (14:16 -0500)
committerGitHub <noreply@github.com>
Wed, 16 Feb 2022 19:16:23 +0000 (11:16 -0800)
* Extend Microsoft.Diagnostics.NETCore.Client to support TCPIP usage on Dotnet/Runtime
* Remove 3rd line from header and provide AssemblyInfo context

33 files changed:
src/Microsoft.Diagnostics.NETCore.Client/AssemblyInfo.cs [new file with mode: 0644]
src/Microsoft.Diagnostics.NETCore.Client/BinaryWriterExtensions.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClientExceptions.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DumpType.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeProvider.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeSession.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeSessionConfiguration.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/WriteDumpFlags.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/ExposedSocketNetworkStream.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcAdvertise.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcClient.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcCommands.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcEndpointConfig.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcHeader.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcMessage.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcResponse.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcServerTransport.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcSocket.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcTcpSocketEndPoint.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcTransport.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcUnixDomainSocket.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcUnixDomainSocketEndPoint.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/ProcessEnvironment.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/ProcessInfo.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsServerRouter/DiagnosticsServerRouterFactory.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsServerRouter/DiagnosticsServerRouterRunner.cs
src/Microsoft.Diagnostics.NETCore.Client/HandleableCollection.cs
src/Microsoft.Diagnostics.NETCore.Client/Microsoft.Diagnostics.NETCore.Client.csproj
src/Microsoft.Diagnostics.NETCore.Client/NativeMethods.cs
src/Microsoft.Diagnostics.NETCore.Client/ReversedServer/IpcEndpointInfo.cs
src/Microsoft.Diagnostics.NETCore.Client/ReversedServer/ReversedDiagnosticsServer.cs
src/Microsoft.Diagnostics.NETCore.Client/StreamExtensions.cs

diff --git a/src/Microsoft.Diagnostics.NETCore.Client/AssemblyInfo.cs b/src/Microsoft.Diagnostics.NETCore.Client/AssemblyInfo.cs
new file mode 100644 (file)
index 0000000..a53e971
--- /dev/null
@@ -0,0 +1,8 @@
+#if DIAGNOSTICS_RUNTIME
+// As of https://github.com/dotnet/runtime/pull/64358, InternalsVisibleTo MSBuild Item does not seem to work in Dotnet/Runtime like it does on Dotnet/Diagnostics
+using System;
+using System.IO;
+using System.Runtime.CompilerServices;
+
+[assembly: InternalsVisibleTo("common")]
+#endif
\ No newline at end of file
index c95b24d5e354858df95bb0bce2f802a71ec28f00..47e3df1fd08908996ee150524840c126a95295d5 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.IO;
index e928aaea0c214554c3ffc37b4b6f268f1e43c5d8..181ccc4a94abc4c21ad7b173f6d02c80827731f5 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Collections.Generic;
index 79ae879d4f6e76848b6fe99c68538350c593af9d..fa9aec630cff74cf8e23d2f6bd1eeba4945477f3 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 
index 2200e84fb23475e6db67ee59e2c8daa82c7586b6..4dbad80a685c5da3d4c8ab1160e0c7a31abb530f 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 namespace Microsoft.Diagnostics.NETCore.Client
 {
index 67da997a2379f8f16022c69a510d8fbe2c7fdfb4..af871695406442b36e88517aa98bdf50b19c8123 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Collections.Generic;
index e277b9a65f6833ee4cb665632ad3b15886535092..79577037c0271373187c7c51a2691fbfcb5a7e38 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Collections.Generic;
index 29ff243af43fc83ade7229cbf34771448bf59c01..90a622302dafc6d55c915baebcb03cebb061de6a 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Collections.Generic;
index b1f93cd59b42004ce7fddde9bb078fa1db5ad698..601bc4b9d9fe29492b78c6010b404c4ab226ff30 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 namespace Microsoft.Diagnostics.NETCore.Client
 {
index dbf6e3e5809433cab919ec422d569dfe87bbda5b..ded8f7af8d11a69063b9d98f61222d4ae1713dbd 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System.Net.Sockets;
 
index 4aa3432d0d8719d1109a136262bbbb331589f1a2..861c6245d27659f8589f797f654ae9882b742b6a 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Linq;
index 87efac955a7fade45a50d6031046da974ff947ca..17e2b25fb12cc33b4e7049d0445539a94a997bc6 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.IO;
index b1f4e80ef17da29b2541c7021afa635cac6a7868..516cf3064562c6ceb34da7ace89308b0f3e98b42 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Collections.Generic;
index 867cba276ed224155fda75b046269a19ccaff28b..83f3085375da9623ad800aea4d006e8d4d775c9f 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Runtime.InteropServices;
@@ -18,13 +17,17 @@ namespace Microsoft.Diagnostics.NETCore.Client
         public enum TransportType
         {
             NamedPipe,
-            UnixDomainSocket
+            UnixDomainSocket,
+#if DIAGNOSTICS_RUNTIME
+            TcpSocket
+#endif
         }
 
         PortType _portType;
 
         TransportType _transportType;
 
+        // For TcpSocket TransportType, the address format will be <hostname_or_ip>:<port>
         public string Address { get; }
 
         public bool IsConnectConfig => _portType == PortType.Connect;
@@ -57,6 +60,12 @@ namespace Microsoft.Diagnostics.NETCore.Client
                         throw new PlatformNotSupportedException($"{UnixDomainSocketSchema} is not supported on Windows, use {NamedPipeSchema}.");
                     break;
                 }
+#if DIAGNOSTICS_RUNTIME
+                case TransportType.TcpSocket:
+                {
+                    break;
+                }
+#endif
                 default:
                 {
                     throw new NotSupportedException($"{transportType} not supported.");
index 6950e8527bd1cf0dd4ead13f8761b5dcabe9c622..95e025a2e3cdc61adf2155f065ccb7031479105c 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Diagnostics;
index c1acad97cf115a2f65a785b746fd58704cd60ed0..9aa4d253047e64164fa8ddbc280d1e001c5b1626 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Collections.Generic;
index 02bc098bde487ff61ffd3f59138b7937511d2e4b..fea123ea006ee6c4afed4691b1e568d5219e0585 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.IO;
index 7d0deac4607f2692244902863a289711f0f127ff..64e99ee6668be297411224c079788de83306e8c8 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.IO;
index 3fe202a62e6260ec831090d5b00cfbf6d40f8aa0..27b0b07d683243569ce6089c2a95aa860667ac90 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Diagnostics;
@@ -23,6 +22,8 @@ namespace Microsoft.Diagnostics.NETCore.Client
         {
         }
 
+// .NET 6 implements this method directly on Socket, but for earlier runtimes we need a polyfill
+#if !NET6_0
         public async Task<Socket> AcceptAsync(CancellationToken token)
         {
             using (token.Register(() => Close(0)))
@@ -44,6 +45,7 @@ namespace Microsoft.Diagnostics.NETCore.Client
                 }
             }
         }
+#endif
 
         public virtual void Connect(EndPoint remoteEP, TimeSpan timeout)
         {
@@ -60,6 +62,8 @@ namespace Microsoft.Diagnostics.NETCore.Client
             }
         }
 
+// .NET 6 implements this method directly on Socket, but for earlier runtimes we need a polyfill
+#if !NET6_0
         public async Task ConnectAsync(EndPoint remoteEP, CancellationToken token)
         {
             using (token.Register(() => Close(0)))
@@ -82,6 +86,6 @@ namespace Microsoft.Diagnostics.NETCore.Client
                 }
             }
         }
-
+#endif
     }
 }
index 00537bf72b04bd0aed610bda7b2d0247240ccb6a..ed6267c68c4023f6b4b3eb3c3c31d1e6c98552c0 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Net;
index 44eeb6ca7e67cee1cf23274229f4ef4b83fc4403..dcac67a71dcfd28c4136e80fe55df4947ab692ac 100644 (file)
@@ -1,12 +1,12 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Diagnostics;
 using System.IO;
 using System.IO.Pipes;
 using System.Linq;
+using System.Net.Sockets;
 using System.Runtime.InteropServices;
 using System.Security.Principal;
 using System.Threading;
@@ -69,6 +69,15 @@ namespace Microsoft.Diagnostics.NETCore.Client
                 socket.Connect(new IpcUnixDomainSocketEndPoint(config.Address), timeout);
                 return new ExposedSocketNetworkStream(socket, ownsSocket: true);
             }
+#if DIAGNOSTICS_RUNTIME
+            else if (config.Transport == IpcEndpointConfig.TransportType.TcpSocket)
+            {
+                var tcpClient = new TcpClient ();
+                var endPoint = new IpcTcpSocketEndPoint(config.Address);
+                tcpClient.Connect(endPoint.EndPoint);
+                return tcpClient.GetStream();
+            }
+#endif
             else
             {
                 throw new ArgumentException($"Unsupported IpcEndpointConfig transport type {config.Transport}");
index cd16fed02e52649bc83de142e259023a502019a1..c935b422308ba3ff1cd0d11955433c4557dbb609 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.IO;
index 8a8aa072cb95dd0e8fb3a5e169180642b157a6b6..f9413852a510f29c6ec3d6d882e6928d5fdf2d93 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.IO;
index 2b65bbe5fd6ed4039e68a66fcd261445a7541a33..c221a93a0f4f76171f349a73ee79245a2a777c0b 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Collections.Generic;
index 887612d866fa45cd0f973be92ddb27d5706d80bc..28d2340c3993c62105a7f33dbb02e43b6fc137e6 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Text;
index 88d0c1558ba090361c2c52f7c8a7265d387df65a..c9326245071efb55664eb1fb9e29608b3a5acc5f 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.IO;
index 24546fe2c10d112df510abd2467a6a14ae0c898f..d7376c480abd852612e074ccffd59ddbedd518f7 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Net;
index 84071fb824f1022571ce30e965faf4f2306c0358..43006000829a0ddfd42d714d6e520055dd561709 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Collections;
index 37668038de5d3396424345da4af27970170721af..929f82d0fac9770aa7792595b68a5a31d82d03ae 100644 (file)
     <IsShipping>true</IsShipping>
   </PropertyGroup>
 
+  <PropertyGroup Condition="'$(GitHubRepositoryName)' == 'runtime'">
+    <DefineConstants>$(DefineConstants);DIAGNOSTICS_RUNTIME</DefineConstants>
+    <NoWarn>CS1591,CS8073,CS0162</NoWarn>
+  </PropertyGroup>
+
   <ItemGroup>
     <PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="$(MicrosoftBclAsyncInterfacesVersion)" />
     <PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsLoggingVersion)" />
@@ -29,4 +34,8 @@
     <InternalsVisibleTo Include="Microsoft.Diagnostics.Monitoring.WebApi" />
     <InternalsVisibleTo Include="Microsoft.Diagnostics.NETCore.Client.UnitTests" />
   </ItemGroup>
+
+  <ItemGroup>
+    <Compile Condition="'$(GitHubRepositoryName)' == 'runtime'" Include="**/*.cs" />
+  </ItemGroup>
 </Project>
index 3962bb4002929438125b8796e6e4eb7364042095..a8ada8394d5c27360d614146758e28c24b33735c 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Runtime.InteropServices;
index aeb26ecf8951226e37a6629dd46ff69bd545d307..609b1760b078b78689cbf59fab85bb0e3f23377b 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Diagnostics;
index 0c15a603945443d512729e2589f327bad9969bfb..b4e26bd207a5a14aa7d28b2c498d8a9f4ac5cb15 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System;
 using System.Collections.Concurrent;
index 3cf6f97a81c2b3d3524d0aabb36abdb505d39aa9..cc3656757d10ca5aee27a92778de0971a29a67cd 100644 (file)
@@ -1,6 +1,5 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
 
 using System.IO;
 using System.Threading;