From 278b652b417e28c5156b46ff91cfc0b4638234a6 Mon Sep 17 00:00:00 2001 From: Mike McLaughlin Date: Thu, 21 Nov 2024 14:30:58 -0800 Subject: [PATCH] Misc SOS fixes (#5040) Fix null refs when no dump or live session (ITarget == null) Add .NET 10.0 runtime hosting for managed SOS code Fix release prep stage from PR #5036 --- eng/pipelines/prepare-release.yml | 4 ++-- .../Runtime.cs | 2 +- .../SpecialDiagInfo.cs | 2 +- .../Host/CommandFormatHelpers.cs | 8 +++++--- .../Host/SpecialDiagInfoHeader.cs | 2 +- src/SOS/extensions/hostcoreclr.cpp | 2 ++ .../RunTests.cs | 2 +- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/eng/pipelines/prepare-release.yml b/eng/pipelines/prepare-release.yml index a7bff089f3..81f644e15c 100644 --- a/eng/pipelines/prepare-release.yml +++ b/eng/pipelines/prepare-release.yml @@ -23,10 +23,10 @@ stages: displayName: 'Build Manifest generation and asset publishing tool' - ${{ elseif and(ne(variables['System.TeamProject'], 'public'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release/')) }}: - task: UseDotNet@2 - displayName: 'Use .NET Core runtime 6.x' + displayName: 'Use .NET Core runtime 8.x' inputs: packageType: runtime - version: 6.x + version: 8.x installationPath: '$(Build.Repository.LocalPath)\.dotnet' - template: /eng/common/templates/post-build/setup-maestro-vars.yml diff --git a/src/Microsoft.Diagnostics.DebugServices.Implementation/Runtime.cs b/src/Microsoft.Diagnostics.DebugServices.Implementation/Runtime.cs index d3fffa53e0..26513a095c 100644 --- a/src/Microsoft.Diagnostics.DebugServices.Implementation/Runtime.cs +++ b/src/Microsoft.Diagnostics.DebugServices.Implementation/Runtime.cs @@ -30,7 +30,7 @@ public class Runtime : IRuntime, IDisposable public Runtime(IServiceProvider services, int id, ClrInfo clrInfo) { - Target = services.GetService() ?? throw new NullReferenceException($"Uninitialized service: {nameof(Target)}"); + Target = services.GetService() ?? throw new DiagnosticsException("Dump or live session target required"); Id = id; _clrInfo = clrInfo ?? throw new ArgumentNullException(nameof(clrInfo)); _symbolService = services.GetService(); diff --git a/src/Microsoft.Diagnostics.DebugServices.Implementation/SpecialDiagInfo.cs b/src/Microsoft.Diagnostics.DebugServices.Implementation/SpecialDiagInfo.cs index 74a5093b9e..65b3621825 100644 --- a/src/Microsoft.Diagnostics.DebugServices.Implementation/SpecialDiagInfo.cs +++ b/src/Microsoft.Diagnostics.DebugServices.Implementation/SpecialDiagInfo.cs @@ -54,7 +54,7 @@ internal struct EXCEPTION_RECORD64 public SpecialDiagInfo(ITarget target, IMemoryService memoryService) { - _target = target; + _target = target ?? throw new DiagnosticsException("Dump or live session target required"); _memoryService = memoryService; } diff --git a/src/Microsoft.Diagnostics.ExtensionCommands/Host/CommandFormatHelpers.cs b/src/Microsoft.Diagnostics.ExtensionCommands/Host/CommandFormatHelpers.cs index 9afd33d872..6ef5026f5c 100644 --- a/src/Microsoft.Diagnostics.ExtensionCommands/Host/CommandFormatHelpers.cs +++ b/src/Microsoft.Diagnostics.ExtensionCommands/Host/CommandFormatHelpers.cs @@ -20,7 +20,8 @@ public static class CommandFormatHelpers /// public static void DisplaySpecialInfo(this CommandBase command, string indent = "") { - if (command.Services.GetService().OperatingSystem != OSPlatform.Windows) + ITarget target = command.Services.GetService() ?? throw new DiagnosticsException("Dump or live session target required"); + if (target.OperatingSystem != OSPlatform.Windows) { ulong address = SpecialDiagInfoHeader.GetAddress(command.Services); command.Console.Write($"{indent}SpecialDiagInfoHeader : {address:X16}"); @@ -57,7 +58,7 @@ public static void DisplayResources(this CommandBase command, IModule module, bo if (module.IsPEImage) { command.Console.WriteLine($"{indent}Resources:"); - IDataReader reader = command.Services.GetService() ?? throw new DiagnosticsException("IDataReader service needed"); + IDataReader reader = command.Services.GetService() ?? throw new DiagnosticsException("IDataReader service required"); IResourceNode resourceRoot = ModuleInfo.TryCreateResourceRoot(reader, module.ImageBase, module.ImageSize, module.IsFileLayout.GetValueOrDefault(false)); if (resourceRoot != null) { @@ -160,7 +161,8 @@ IConsoleService Console() } // Print the Windows runtime engine metrics (.NET Core and .NET Framework) - if (command.Services.GetService().OperatingSystem == OSPlatform.Windows) + ITarget target = command.Services.GetService() ?? throw new DiagnosticsException("Dump or live session target required"); + if (target.OperatingSystem == OSPlatform.Windows) { if (symbols != null && symbols.TryGetSymbolAddress(ClrEngineMetrics.Symbol, out ulong metricsAddress)) { diff --git a/src/Microsoft.Diagnostics.ExtensionCommands/Host/SpecialDiagInfoHeader.cs b/src/Microsoft.Diagnostics.ExtensionCommands/Host/SpecialDiagInfoHeader.cs index 3a7a154865..5f700a9c3b 100644 --- a/src/Microsoft.Diagnostics.ExtensionCommands/Host/SpecialDiagInfoHeader.cs +++ b/src/Microsoft.Diagnostics.ExtensionCommands/Host/SpecialDiagInfoHeader.cs @@ -52,7 +52,7 @@ public static bool TryRead(IServiceProvider services, ulong address, out Special public static ulong GetAddress(IServiceProvider services) { - ITarget target = services.GetService(); + ITarget target = services.GetService() ?? throw new DiagnosticsException("Dump or live session target required"); IMemoryService memoryService = services.GetService(); return target.OperatingSystem == OSPlatform.OSX ? SpecialDiagInfoAddress_OSX : (memoryService.PointerSize == 4 ? SpecialDiagInfoAddress_32BIT : SpecialDiagInfoAddress_64BIT); } diff --git a/src/SOS/extensions/hostcoreclr.cpp b/src/SOS/extensions/hostcoreclr.cpp index 4c49602343..fa5d8f592c 100644 --- a/src/SOS/extensions/hostcoreclr.cpp +++ b/src/SOS/extensions/hostcoreclr.cpp @@ -72,6 +72,7 @@ namespace RuntimeHostingConstants {9, 0}, {8, 0}, {6, 0}, + {10, 0}, }; constexpr char DotnetRootEnvVar[] = "DOTNET_ROOT"; @@ -128,6 +129,7 @@ namespace RuntimeHostingConstants "/rh-dotnet90/root/usr/bin/dotnet", "/rh-dotnet80/root/usr/bin/dotnet", "/rh-dotnet60/root/usr/bin/dotnet", + "/rh-dotnet100/root/usr/bin/dotnet", "/usr/share/dotnet", #endif }; diff --git a/src/tests/Microsoft.Diagnostics.DebugServices.UnitTests/RunTests.cs b/src/tests/Microsoft.Diagnostics.DebugServices.UnitTests/RunTests.cs index 7ae2286083..170b4a1bef 100644 --- a/src/tests/Microsoft.Diagnostics.DebugServices.UnitTests/RunTests.cs +++ b/src/tests/Microsoft.Diagnostics.DebugServices.UnitTests/RunTests.cs @@ -31,7 +31,7 @@ public class RunTestsCommand : CommandBase, ITestOutputHelper public override void Invoke() { - ITarget target = Services.GetService(); + ITarget target = Services.GetService() ?? throw new DiagnosticsException("Dump or live session target required"); string os; if (target.OperatingSystem == OSPlatform.Linux) {