From: Mike McLaughlin Date: Fri, 28 Jun 2024 18:38:06 +0000 (-0700) Subject: Add runtime enumeration control to runtime service and providers (#4765) X-Git-Tag: accepted/tizen/unified/20241231.014852~39^2^2~161 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=36353b20e53e0c4af482e4fbe1d0a572515f14a2;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Add runtime enumeration control to runtime service and providers (#4765) Add `runtimes --all` option. --- diff --git a/src/Microsoft.Diagnostics.DebugServices.Implementation/RuntimeProvider.cs b/src/Microsoft.Diagnostics.DebugServices.Implementation/RuntimeProvider.cs index 3ea0ab90b..4639a0ebc 100644 --- a/src/Microsoft.Diagnostics.DebugServices.Implementation/RuntimeProvider.cs +++ b/src/Microsoft.Diagnostics.DebugServices.Implementation/RuntimeProvider.cs @@ -26,15 +26,17 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation /// Returns the list of .NET runtimes in the target /// /// The starting runtime id for this provider - public IEnumerable EnumerateRuntimes(int startingRuntimeId) + /// Enumeration control flags + public IEnumerable EnumerateRuntimes(int startingRuntimeId, RuntimeEnumerationFlags flags) { // The ClrInfo and DataTarget instances are disposed when Runtime instance is disposed. Runtime instances are // not flushed when the Target/RuntimeService is flushed; they are all disposed and the list cleared. They are // all re-created the next time the IRuntime or ClrRuntime instance is queried. - DataTarget dataTarget = new(new CustomDataTarget(_services.GetService())) + DataTarget dataTarget = new(new CustomDataTarget(_services.GetService()) { + ForceCompleteRuntimeEnumeration = (flags & RuntimeEnumerationFlags.All) != 0, FileLocator = null - }; + }); for (int i = 0; i < dataTarget.ClrVersions.Length; i++) { yield return new Runtime(_services, startingRuntimeId + i, dataTarget.ClrVersions[i]); diff --git a/src/Microsoft.Diagnostics.DebugServices.Implementation/RuntimeService.cs b/src/Microsoft.Diagnostics.DebugServices.Implementation/RuntimeService.cs index ef969eb2d..b37c5d6f3 100644 --- a/src/Microsoft.Diagnostics.DebugServices.Implementation/RuntimeService.cs +++ b/src/Microsoft.Diagnostics.DebugServices.Implementation/RuntimeService.cs @@ -47,7 +47,8 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation /// /// Returns the list of runtimes in the target /// - public IEnumerable EnumerateRuntimes() + /// Enumeration control flags + public IEnumerable EnumerateRuntimes(RuntimeEnumerationFlags flags) { if (_runtimes is null) { @@ -55,7 +56,7 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation foreach (ServiceFactory factory in _serviceManager.EnumerateProviderFactories(typeof(IRuntimeProvider))) { IRuntimeProvider provider = (IRuntimeProvider)factory(_services); - _runtimes.AddRange(provider.EnumerateRuntimes(_runtimes.Count)); + _runtimes.AddRange(provider.EnumerateRuntimes(_runtimes.Count, flags)); } } return _runtimes; diff --git a/src/Microsoft.Diagnostics.DebugServices/IRuntimeProvider.cs b/src/Microsoft.Diagnostics.DebugServices/IRuntimeProvider.cs index a81155d02..357bb63cf 100644 --- a/src/Microsoft.Diagnostics.DebugServices/IRuntimeProvider.cs +++ b/src/Microsoft.Diagnostics.DebugServices/IRuntimeProvider.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Collections.Generic; namespace Microsoft.Diagnostics.DebugServices @@ -14,6 +15,7 @@ namespace Microsoft.Diagnostics.DebugServices /// Returns the list of runtimes in the target /// /// The starting runtime id for this provider - IEnumerable EnumerateRuntimes(int startingRuntimeId); + /// Enumeration control flags + IEnumerable EnumerateRuntimes(int startingRuntimeId, RuntimeEnumerationFlags flags); } } diff --git a/src/Microsoft.Diagnostics.DebugServices/IRuntimeService.cs b/src/Microsoft.Diagnostics.DebugServices/IRuntimeService.cs index 4f3863996..3ba22b1ed 100644 --- a/src/Microsoft.Diagnostics.DebugServices/IRuntimeService.cs +++ b/src/Microsoft.Diagnostics.DebugServices/IRuntimeService.cs @@ -13,6 +13,7 @@ namespace Microsoft.Diagnostics.DebugServices /// /// Returns the list of runtimes in the target /// - IEnumerable EnumerateRuntimes(); + /// Enumeration control flags + IEnumerable EnumerateRuntimes(RuntimeEnumerationFlags flags = RuntimeEnumerationFlags.Default); } } diff --git a/src/Microsoft.Diagnostics.DebugServices/RuntimeEnumerationFlags.cs b/src/Microsoft.Diagnostics.DebugServices/RuntimeEnumerationFlags.cs new file mode 100644 index 000000000..ccf0ee554 --- /dev/null +++ b/src/Microsoft.Diagnostics.DebugServices/RuntimeEnumerationFlags.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; + +namespace Microsoft.Diagnostics.DebugServices +{ + /// + /// Enumeration control flags + /// + [Flags] + public enum RuntimeEnumerationFlags + { + /// + /// Providers can return only the runtimes they feel are important like ones involved in a crash. + /// + Default = 0x00, + + /// + /// Force enumeration of all runtimes. If set, all the possible runtimes in the target process are enumerated. + /// + All = 0x01, + } +} diff --git a/src/Microsoft.Diagnostics.ExtensionCommands/Host/RuntimesCommand.cs b/src/Microsoft.Diagnostics.ExtensionCommands/Host/RuntimesCommand.cs index 1d678a23a..561214e0b 100644 --- a/src/Microsoft.Diagnostics.ExtensionCommands/Host/RuntimesCommand.cs +++ b/src/Microsoft.Diagnostics.ExtensionCommands/Host/RuntimesCommand.cs @@ -30,16 +30,28 @@ namespace Microsoft.Diagnostics.ExtensionCommands [Option(Name = "--netcore", Aliases = new string[] { "-netcore", "-c" }, Help = "Switches to the .NET Core or .NET 5+ runtime if exists.")] public bool NetCore { get; set; } + [Option(Name = "--all", Aliases = new string[] { "-a" }, Help = "Forces all runtimes to be enumerated.")] + public bool All { get; set; } + public override void Invoke() { if (NetFx && NetCore) { throw new DiagnosticsException("Cannot specify both -netfx and -netcore options"); } + RuntimeEnumerationFlags flags = RuntimeEnumerationFlags.Default; + + if (All) + { + // Force all runtimes to be enumerated. This requires a target flush. + flags = RuntimeEnumerationFlags.All; + Target.Flush(); + } + if (NetFx || NetCore) { string name = NetFx ? "desktop .NET Framework" : ".NET Core"; - foreach (IRuntime runtime in RuntimeService.EnumerateRuntimes()) + foreach (IRuntime runtime in RuntimeService.EnumerateRuntimes(flags)) { if (NetFx && runtime.RuntimeType == RuntimeType.Desktop || NetCore && runtime.RuntimeType == RuntimeType.NetCore) @@ -59,10 +71,10 @@ namespace Microsoft.Diagnostics.ExtensionCommands else { // Display the current runtime star ("*") only if there is more than one runtime and it is the current one - bool displayStar = RuntimeService.EnumerateRuntimes().Count() > 1; + bool displayStar = RuntimeService.EnumerateRuntimes(flags).Count() > 1; IRuntime currentRuntime = ContextService.GetCurrentRuntime(); - foreach (IRuntime runtime in RuntimeService.EnumerateRuntimes()) + foreach (IRuntime runtime in RuntimeService.EnumerateRuntimes(flags)) { string current = displayStar ? (runtime == currentRuntime ? "*" : " ") : ""; Write(current); diff --git a/src/SOS/SOS.Package/SOS.Symbol.Package.csproj b/src/SOS/SOS.Package/SOS.Symbol.Package.csproj index 59adf253d..d5c0851fc 100644 --- a/src/SOS/SOS.Package/SOS.Symbol.Package.csproj +++ b/src/SOS/SOS.Package/SOS.Symbol.Package.csproj @@ -21,6 +21,9 @@ $(SOSPackagePathPrefix)/win-x64 + + + $(SOSPackagePathPrefix)/win-x86 diff --git a/src/sos-packaging.props b/src/sos-packaging.props index 7ca956b59..77556c055 100644 --- a/src/sos-packaging.props +++ b/src/sos-packaging.props @@ -10,7 +10,9 @@ + +